git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v9 29.25/30] merge-recursive: improve output precision around skipping updates

From
Elijah Newren <newren@gmail.com>
Date
Apr 13, 2018, 19:56 UTC
Message-ID
<20180413195607.18091-2-newren@gmail.com>
In-Reply-To
<20180413195607.18091-1-newren@gmail.com>

When a merge results in contents that already existed in HEAD (because the changes on a side branch were a subset of what was changed by HEAD), and those contents were already at the right path, the working directory updates can be skipped. However, the relevant code would sometimes claim the working directory update could be skipped despite the fact that the contents were at the wrong path. Make the output reflect the situation more precisely, including an additional message that tests can check for to make sure we are getting correct behavior.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-recursive.c       | 11 ++++++-----
 t/t6022-merge-rename.sh |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 4a1ecdea03..05250939c7 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -2761,21 +2761,22 @@ static int merge_content(struct merge_options *o,
 				       o->branch2, path2, &mfi))
 		return -1;
 
-	if (mfi.clean && !df_conflict_remains &&
-	    oid_eq(&mfi.oid, a_oid) && mfi.mode == a_mode) {
+	if (mfi.clean && oid_eq(&mfi.oid, a_oid) && mfi.mode == a_mode) {
 		int path_renamed_outside_HEAD;
-		output(o, 3, _("Skipped %s (merged same as existing)"), path);
 		/*
 		 * The content merge resulted in the same file contents we
 		 * already had.  We can return early if those file contents
 		 * are recorded at the correct path (which may not be true
-		 * if the merge involves a rename).
+		 * if the merge involves a rename or there's a D/F conflict).
 		 */
 		path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
-		if (!path_renamed_outside_HEAD) {
+		if (!df_conflict_remains && !path_renamed_outside_HEAD) {
+			output(o, 3, _("Skipped %s (merged same as existing)"), path);
 			add_cacheinfo(o, mfi.mode, &mfi.oid, path,
 				      0, (!o->call_depth), 0);
 			return mfi.clean;
+		} else {
+			output(o, 3, _("Had correct contents for %s, but not at right path"), path);
 		}
 	} else
 		output(o, 2, _("Auto-merging %s"), path);
diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh
index 05ebba7afa..574088bfaf 100755
--- a/t/t6022-merge-rename.sh
+++ b/t/t6022-merge-rename.sh
@@ -245,7 +245,7 @@ test_expect_success 'merge of identical changes in a renamed file' '
 	GIT_MERGE_VERBOSITY=3 git merge change | test_i18ngrep "^Skipped B" &&
 	git reset --hard HEAD^ &&
 	git checkout change &&
-	GIT_MERGE_VERBOSITY=3 git merge change+rename | test_i18ngrep "^Skipped B"
+	GIT_MERGE_VERBOSITY=3 git merge change+rename | test_i18ngrep "^Had correct contents for B, but not at right path"
 '
 
 test_expect_success 'setup for rename + d/f conflicts' '
-- 
2.16.0.35.g6dd7ede834
Previous: Stefan Beller
Message 13 of 13 in “[Git] recursive merge on 'master' severely broken?”
  1. Junio C HamanoApr 11, 2018
  2. Junio C HamanoApr 11, 2018
  3. Junio C HamanoApr 11, 2018
  4. Elijah NewrenApr 11, 2018
  5. Junio C HamanoApr 12, 2018
  6. 0/30 Add directory rename detection to gitElijah Newren, Apr 13, 2018
  7. 30/30 merge-recursive: fix check for skipability of working tree updatesElijah Newren, Apr 13, 2018
  8. 75/30 merge-recursive: Fix was_tracked() to quit lying with some renamed pathsElijah Newren, Apr 13, 2018
  9. Junio C HamanoApr 16, 2018
  10. Elijah NewrenApr 16, 2018
  11. 50/30 t6046: testcases checking whether updates can be skipped in a mergeElijah Newren, Apr 13, 2018
  12. Stefan BellerApr 13, 2018
  13. 25/30 merge-recursive: improve output precision around skipping updatesElijah Newren, Apr 13, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.