git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@imag.fr>
To: git@vger.kernel.org, gitster@pobox.com
Cc: Diane Gasselin <diane.gasselin@ensimag.imag.fr>,
	Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: [PATCH 3/5] merge-recursive: distinguish "removed" and "overwritten" messages
Date: Mon,  9 Aug 2010 16:20:00 +0200	[thread overview]
Message-ID: <1281363602-27856-4-git-send-email-Matthieu.Moy@imag.fr> (raw)
In-Reply-To: <1281363602-27856-1-git-send-email-Matthieu.Moy@imag.fr>

To limit the number of possible error messages, the error messages for
the case would_lose_untracked_file and would_lose_orphaned in
unpack_trees_options.msgs were handled with a single string,
parameterized by an action string ("overwritten" or "removed").

Instead, we consider them as two different cases, with unparameterized
string. This will make it easier to make separate lists sorted by error
types later.

Only the bind_overlap case still takes two %s parameters, but that's
unavoidable.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 merge-recursive.c |   13 ++++++----
 unpack-trees.c    |   64 ++++++++++++++++++++++++++++++++--------------------
 unpack-trees.h    |    6 +++-
 3 files changed, 51 insertions(+), 32 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index bd26497..8c1b189 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1197,13 +1197,16 @@ void set_porcelain_error_msgs(const char **msgs, const char *cmd)
 		"Updating '%s' would lose untracked files in it.  Aborting.";
 
 	if (advice_commit_before_merge)
-		msg = "Untracked working tree file '%%s' would be %%s by %s.  Aborting"
+		msg = "Untracked working tree file '%%s' would be %s by %s.  Aborting"
 			"Please move or remove them before you can %s.";
 	else
-		msg = "Untracked working tree file '%%s' would be %%s by %s.  Aborting";
-	tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 3);
-	sprintf(tmp, msg, cmd, cmd2);
-	msgs[would_lose_untracked_file] = tmp;
+		msg = "Untracked working tree file '%%s' would be %s by %s.  Aborting";
+	tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("removed") + strlen(cmd2) - 4);
+	sprintf(tmp, msg, "removed", cmd, cmd2);
+	msgs[would_lose_untracked_removed] = tmp;
+	tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("overwritten") + strlen(cmd2) - 4);
+	sprintf(tmp, msg, "overwritten", cmd, cmd2);
+	msgs[would_lose_untracked_overwritten] = tmp;
 }
 
 int merge_trees(struct merge_options *o,
diff --git a/unpack-trees.c b/unpack-trees.c
index 538f228..143f897 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -27,8 +27,11 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
 	/* not_uptodate_dir */
 	"Updating '%s' would lose untracked files in it",
 
-	/* would_lose_untracked_file */
-	"Untracked working tree file '%s' would be %s by merge.",
+	/* would_lose_untracked_overwritten */
+	"Untracked working tree file '%s' would be overwritten by merge.",
+
+	/* would_lose_untracked_removed */
+	"Untracked working tree file '%s' would be removed by merge.",
 
 	/* bind_overlap */
 	"Entry '%s' overlaps with '%s'.  Cannot bind.",
@@ -36,8 +39,11 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
 	/* sparse_not_uptodate_file */
 	"Entry '%s' not uptodate. Cannot update sparse checkout.",
 
-	/* would_lose_orphaned */
-	"Working tree file '%s' would be %s by sparse checkout update.",
+	/* would_lose_orphaned_overwritten */
+	"Working tree file '%s' would be overwritten by sparse checkout update.",
+
+	/* would_lose_orphaned_removed */
+	"Working tree file '%s' would be removed by sparse checkout update.",
 };
 
 #define ERRORMSG(o,type) \
@@ -132,7 +138,7 @@ static int check_updates(struct unpack_trees_options *o)
 }
 
 static int verify_uptodate_sparse(struct cache_entry *ce, struct unpack_trees_options *o);
-static int verify_absent_sparse(struct cache_entry *ce, const char *action, struct unpack_trees_options *o);
+static int verify_absent_sparse(struct cache_entry *ce, enum unpack_trees_error_types, struct unpack_trees_options *o);
 
 static int will_have_skip_worktree(const struct cache_entry *ce, struct unpack_trees_options *o)
 {
@@ -175,7 +181,7 @@ static int apply_sparse_checkout(struct cache_entry *ce, struct unpack_trees_opt
 		ce->ce_flags |= CE_WT_REMOVE;
 	}
 	if (was_skip_worktree && !ce_skip_worktree(ce)) {
-		if (verify_absent_sparse(ce, "overwritten", o))
+		if (verify_absent_sparse(ce, would_lose_untracked_overwritten, o))
 			return -1;
 		ce->ce_flags |= CE_UPDATE;
 	}
@@ -860,7 +866,7 @@ static int same(struct cache_entry *a, struct cache_entry *b)
  */
 static int verify_uptodate_1(struct cache_entry *ce,
 				   struct unpack_trees_options *o,
-				   const char *error_msg)
+				   enum unpack_trees_error_types error_type)
 {
 	struct stat st;
 
@@ -885,7 +891,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
 	if (errno == ENOENT)
 		return 0;
 	return o->gently ? -1 :
-		error(error_msg, ce->name);
+		error(ERRORMSG(o, error_type), ce->name);
 }
 
 static int verify_uptodate(struct cache_entry *ce,
@@ -893,13 +899,13 @@ static int verify_uptodate(struct cache_entry *ce,
 {
 	if (!o->skip_sparse_checkout && will_have_skip_worktree(ce, o))
 		return 0;
-	return verify_uptodate_1(ce, o, ERRORMSG(o, not_uptodate_file));
+	return verify_uptodate_1(ce, o, not_uptodate_file);
 }
 
 static int verify_uptodate_sparse(struct cache_entry *ce,
 				  struct unpack_trees_options *o)
 {
-	return verify_uptodate_1(ce, o, ERRORMSG(o, sparse_not_uptodate_file));
+	return verify_uptodate_1(ce, o, sparse_not_uptodate_file);
 }
 
 static void invalidate_ce_path(struct cache_entry *ce, struct unpack_trees_options *o)
@@ -915,13 +921,15 @@ static void invalidate_ce_path(struct cache_entry *ce, struct unpack_trees_optio
  * Currently, git does not checkout subprojects during a superproject
  * checkout, so it is not going to overwrite anything.
  */
-static int verify_clean_submodule(struct cache_entry *ce, const char *action,
+static int verify_clean_submodule(struct cache_entry *ce,
+				      enum unpack_trees_error_types error_type,
 				      struct unpack_trees_options *o)
 {
 	return 0;
 }
 
-static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
+static int verify_clean_subdirectory(struct cache_entry *ce,
+				      enum unpack_trees_error_types error_type,
 				      struct unpack_trees_options *o)
 {
 	/*
@@ -942,7 +950,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
 		 */
 		if (!hashcmp(sha1, ce->sha1))
 			return 0;
-		return verify_clean_submodule(ce, action, o);
+		return verify_clean_submodule(ce, error_type, o);
 	}
 
 	/*
@@ -1011,9 +1019,9 @@ static int icase_exists(struct unpack_trees_options *o, struct cache_entry *dst,
  * We do not want to remove or overwrite a working tree file that
  * is not tracked, unless it is ignored.
  */
-static int verify_absent_1(struct cache_entry *ce, const char *action,
-				 struct unpack_trees_options *o,
-				 const char *error_msg)
+static int verify_absent_1(struct cache_entry *ce,
+				 enum unpack_trees_error_types error_type,
+				 struct unpack_trees_options *o)
 {
 	struct stat st;
 
@@ -1051,7 +1059,7 @@ static int verify_absent_1(struct cache_entry *ce, const char *action,
 			 * files that are in "foo/" we would lose
 			 * them.
 			 */
-			if (verify_clean_subdirectory(ce, action, o) < 0)
+			if (verify_clean_subdirectory(ce, error_type, o) < 0)
 				return -1;
 			return 0;
 		}
@@ -1068,22 +1076,28 @@ static int verify_absent_1(struct cache_entry *ce, const char *action,
 		}
 
 		return o->gently ? -1 :
-			error(ERRORMSG(o, would_lose_untracked_file), ce->name, action);
+			error(ERRORMSG(o, error_type), ce->name);
 	}
 	return 0;
 }
-static int verify_absent(struct cache_entry *ce, const char *action,
+static int verify_absent(struct cache_entry *ce,
+			 enum unpack_trees_error_types error_type,
 			 struct unpack_trees_options *o)
 {
 	if (!o->skip_sparse_checkout && will_have_skip_worktree(ce, o))
 		return 0;
-	return verify_absent_1(ce, action, o, ERRORMSG(o, would_lose_untracked_file));
+	return verify_absent_1(ce, error_type, o);
 }
 
-static int verify_absent_sparse(struct cache_entry *ce, const char *action,
+static int verify_absent_sparse(struct cache_entry *ce,
+			 enum unpack_trees_error_types error_type,
 			 struct unpack_trees_options *o)
 {
-	return verify_absent_1(ce, action, o, ERRORMSG(o, would_lose_orphaned));
+	enum unpack_trees_error_types orphaned_error = error_type;
+	if (orphaned_error == would_lose_untracked_overwritten)
+		orphaned_error = would_lose_orphaned_overwritten;
+
+	return verify_absent_1(ce, orphaned_error, o);
 }
 
 static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
@@ -1092,7 +1106,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
 	int update = CE_UPDATE;
 
 	if (!old) {
-		if (verify_absent(merge, "overwritten", o))
+		if (verify_absent(merge, would_lose_untracked_overwritten, o))
 			return -1;
 		invalidate_ce_path(merge, o);
 	} else if (!(old->ce_flags & CE_CONFLICTED)) {
@@ -1130,7 +1144,7 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old,
 {
 	/* Did it exist in the index? */
 	if (!old) {
-		if (verify_absent(ce, "removed", o))
+		if (verify_absent(ce, would_lose_untracked_removed, o))
 			return -1;
 		return 0;
 	}
@@ -1279,7 +1293,7 @@ int threeway_merge(struct cache_entry **stages, struct unpack_trees_options *o)
 			if (index)
 				return deleted_entry(index, index, o);
 			if (ce && !head_deleted) {
-				if (verify_absent(ce, "removed", o))
+				if (verify_absent(ce, would_lose_untracked_removed, o))
 					return -1;
 			}
 			return 0;
diff --git a/unpack-trees.h b/unpack-trees.h
index 3a6d2b4..edda877 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -13,10 +13,12 @@ enum unpack_trees_error_types {
 	would_overwrite = 0,
 	not_uptodate_file,
 	not_uptodate_dir,
-	would_lose_untracked_file,
+	would_lose_untracked_overwritten,
+	would_lose_untracked_removed,
 	bind_overlap,
 	sparse_not_uptodate_file,
-	would_lose_orphaned,
+	would_lose_orphaned_overwritten,
+	would_lose_orphaned_removed,
 	NB_UNPACK_TREES_ERROR_TYPES
 };
 
-- 
1.7.2.1.52.g95e25.dirty

  parent reply	other threads:[~2010-08-09 14:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-09 14:19 [PATCH 0/5] Better error messages for checkout and merge Matthieu Moy
2010-08-09 14:19 ` [PATCH 1/5] Turn unpack_trees_options.msgs into an array + enum Matthieu Moy
2010-08-09 19:47   ` Junio C Hamano
2010-08-09 20:49     ` Matthieu Moy
2010-08-11  8:38       ` [PATCH 1/5 v2] " Matthieu Moy
2010-08-11  8:38       ` [PATCH 2/5 v2] merge-recursive: porcelain messages for checkout Matthieu Moy
2010-08-11  8:38       ` [PATCH 3/5 v2] merge-recursive: distinguish "removed" and "overwritten" messages Matthieu Moy
2010-08-11  8:38       ` [PATCH 4/5 v2] unpack_trees: group error messages by type Matthieu Moy
2010-08-11  8:38       ` [PATCH 5/5 v2] t7609: test merge and checkout error messages Matthieu Moy
2010-08-09 14:19 ` [PATCH 2/5] merge-recursive: porcelain messages for checkout Matthieu Moy
2010-08-09 19:58   ` Junio C Hamano
2010-08-09 20:52     ` Matthieu Moy
2010-08-09 21:15       ` Ævar Arnfjörð Bjarmason
2010-08-09 14:20 ` Matthieu Moy [this message]
2010-08-09 14:20 ` [PATCH 4/5] unpack_trees: group error messages by type Matthieu Moy
2010-08-09 14:20 ` [PATCH 5/5] t7609: test merge and checkout error messages Matthieu Moy

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=1281363602-27856-4-git-send-email-Matthieu.Moy@imag.fr \
    --to=matthieu.moy@imag.fr \
    --cc=diane.gasselin@ensimag.imag.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).