All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Jonathan Niedier" <jrnieder@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Jiang Xin" <worldhello.net@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 6/6] unpack-trees: remove i18n legos in unpack's porcelain error messages
Date: Thu, 31 May 2012 20:04:42 +0700	[thread overview]
Message-ID: <1338469482-30936-7-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1338469482-30936-1-git-send-email-pclouds@gmail.com>


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 unpack-trees.c | 55 +++++++++++++++++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/unpack-trees.c b/unpack-trees.c
index ad40109..41c5714 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -53,35 +53,46 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
 void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
 				  const char *cmd)
 {
-	int i;
+	int i, idx;
 	const char **msgs = opts->msgs;
-	const char *msg;
-	char *tmp;
-	const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
-	if (advice_commit_before_merge)
-		msg = "Your local changes to the following files would be overwritten by %s:\n%%s"
-			"Please, commit your changes or stash them before you can %s.";
+	struct strbuf msg = STRBUF_INIT;
+	const char *overwrite_advice[] = {
+		"Please, commit your changes or stash them before you can merge.",
+		"Please, commit your changes or stash them before you can switch branches."
+	};
+	const char *remove_untracked_advice[] = {
+		"Please move or remove them before you can merge.",
+		"Please move or remove them before you can switch branches."
+	};
+
+	if (!strcmp(cmd, "merge"))
+		idx = 0;
+	else if (!strcmp(cmd, "checkout"))
+		idx = 1;
 	else
-		msg = "Your local changes to the following files would be overwritten by %s:\n%%s";
-	tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 2);
-	sprintf(tmp, msg, cmd, cmd2);
-	msgs[ERROR_WOULD_OVERWRITE] = tmp;
-	msgs[ERROR_NOT_UPTODATE_FILE] = tmp;
+		die("BUG: unsupported command %s", cmd);
+
+	strbuf_addf(&msg, "Your local changes to the following files "
+		    "would be overwritten by %s:\n%%s", cmd);
+	if (advice_commit_before_merge)
+		strbuf_addstr(&msg, overwrite_advice[idx]);
+	msgs[ERROR_WOULD_OVERWRITE] = strbuf_detach(&msg, NULL);
+	msgs[ERROR_NOT_UPTODATE_FILE] = msgs[ERROR_WOULD_OVERWRITE];
 
 	msgs[ERROR_NOT_UPTODATE_DIR] =
 		"Updating the following directories would lose untracked files in it:\n%s";
 
+	strbuf_addf(&msg, "The following untracked working tree "
+		    "files would be removed by %s:\n%%s", cmd);
 	if (advice_commit_before_merge)
-		msg = "The following untracked working tree files would be %s by %s:\n%%s"
-			"Please move or remove them before you can %s.";
-	else
-		msg = "The following untracked working tree files would be %s by %s:\n%%s";
-	tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("removed") + strlen(cmd2) - 4);
-	sprintf(tmp, msg, "removed", cmd, cmd2);
-	msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = tmp;
-	tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("overwritten") + strlen(cmd2) - 4);
-	sprintf(tmp, msg, "overwritten", cmd, cmd2);
-	msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = tmp;
+		strbuf_addstr(&msg, remove_untracked_advice[idx]);
+	msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = strbuf_detach(&msg, NULL);
+
+	strbuf_addf(&msg, "The following untracked working tree "
+		    "files would be overwritten by %s:\n%%s", cmd);
+	if (advice_commit_before_merge)
+		strbuf_addstr(&msg, remove_untracked_advice[idx]);
+	msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = strbuf_detach(&msg, NULL);
 
 	/*
 	 * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
-- 
1.7.10.2.549.g9354186

  parent reply	other threads:[~2012-05-31 13:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-31 11:20 [PATCH] i18n: apply: split to fix a partial i18n message Jiang Xin
2012-05-31 13:04 ` Nguyễn Thái Ngọc Duy
2012-05-31 13:04   ` [PATCH 1/6] Remove i18n legos in notifying new branch tracking setup Nguyễn Thái Ngọc Duy
2012-05-31 14:00     ` Jonathan Nieder
2012-05-31 13:04   ` [PATCH 2/6] reflog: remove i18n legos in pruning message Nguyễn Thái Ngọc Duy
2012-05-31 13:45     ` Jonathan Nieder
2012-05-31 14:00       ` Nguyen Thai Ngoc Duy
2012-05-31 14:10         ` Jonathan Nieder
2012-05-31 14:18           ` Nguyen Thai Ngoc Duy
2012-05-31 17:56       ` Junio C Hamano
2012-05-31 20:31         ` Jonathan Nieder
2012-05-31 13:04   ` [PATCH 3/6] merge-recursive: remove i18n legos in conflict messages Nguyễn Thái Ngọc Duy
2012-05-31 13:52     ` Jonathan Nieder
2012-05-31 13:56       ` Nguyen Thai Ngoc Duy
2012-05-31 13:04   ` [PATCH 4/6] notes-merge: remove i18n legos in merge result message Nguyễn Thái Ngọc Duy
2012-05-31 13:04   ` [PATCH 5/6] rerere: remove i18n legos in " Nguyễn Thái Ngọc Duy
2012-05-31 13:04   ` Nguyễn Thái Ngọc Duy [this message]
     [not found] <0001-Remove-i18n-legos-in-notifying-new-branch-tracking-s.patch>
2012-06-07 12:05 ` [PATCH 1/6] Remove i18n legos in notifying new branch tracking setup Nguyễn Thái Ngọc Duy
2012-06-07 12:05   ` [PATCH 6/6] unpack-trees: remove i18n legos in unpack's porcelain error messages Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338469482-30936-7-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=worldhello.net@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.