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

[PATCH 2/3] read-tree -m 3-way: loosen index requirements that is too strict.

From
Junio C Hamano <junkio@cox.net>
Date
Jun 9, 2005, 07:05 UTC
Message-ID
<7vbr6growa.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<7voeagrp11.fsf_-_@assigned-by-dhcp.cox.net>

This patch teaches "read-tree -m O A B" that, when only "the other tree" changed a path, and if the work tree already has that change, we are not in a situation that would clobber the cache and the working tree, and lets the merge succeed; this is case #14ALT in t1000 test.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 read-tree.c                 |   16 ++++++++++++++++
 t/t1000-read-tree-m-3way.sh |    9 +++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/read-tree.c b/read-tree.c
--- a/read-tree.c
+++ b/read-tree.c
@@ -131,6 +131,22 @@ static int threeway_merge(struct cache_e
 	struct cache_entry *merge;
 	int count;
 
+	/* The case #14ALT is special in that it allows "i" to match
+	 * the "merged branch", aka "b" and even be dirty, as an
+	 * alternative to the usual 'must match "a" and be up-to-date'
+	 * rule.
+	 */
+	if (o && a && b && same(o, a) && !same(o, b)) {
+		if (i) {
+			if (same(i, b))
+				; /* case #14ALT exception */
+			else if (same(i, a))
+				verify_uptodate(i);
+			else
+				return -1;
+		}
+	}
+	else /* otherwise the original rule applies */
 	/*
 	 * If we have an entry in the index cache ("i"), then we want
 	 * to make sure that it matches any entries in stage 2 ("first
diff --git a/t/t1000-read-tree-m-3way.sh b/t/t1000-read-tree-m-3way.sh
--- a/t/t1000-read-tree-m-3way.sh
+++ b/t/t1000-read-tree-m-3way.sh
@@ -455,6 +455,15 @@ test_expect_success \
      git-read-tree -m $tree_O $tree_A $tree_B &&
      check_result"
 
+test_expect_success \
+    '14ALT - in O && A && B && O==A && O!=B case, matching B is also OK' \
+    "rm -f .git/index NM &&
+     cp .orig-B/NM NM &&
+     git-update-cache --add NM &&
+     echo extra >>NM &&
+     git-read-tree -m $tree_O $tree_A $tree_B &&
+     check_result"
+
 test_expect_failure \
     '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \
     "rm -f .git/index NM &&
------------
Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 33 in “Handling merge conflicts a bit more gracefully..”
  1. Linus TorvaldsJun 8, 2005
  2. Junio C HamanoJun 8, 2005
  3. Linus TorvaldsJun 8, 2005
  4. Junio C HamanoJun 9, 2005
  5. Linus TorvaldsJun 9, 2005
  6. Junio C HamanoJun 9, 2005
  7. Junio C HamanoJun 9, 2005
  8. Linus TorvaldsJun 9, 2005
  9. Junio C HamanoJun 9, 2005
  10. Linus TorvaldsJun 9, 2005
  11. Junio C HamanoJun 9, 2005
  12. Linus TorvaldsJun 9, 2005
  13. Junio C HamanoJun 9, 2005
  14. 0/3 Handling merge conflicts a bit more gracefullyJunio C Hamano, Jun 9, 2005
  15. 1/3 read-tree.c: rename local variables used in 3-way merge code.Junio C Hamano, Jun 9, 2005
  16. 2/3 read-tree -m 3-way: loosen index requirements that is too strict.Junio C Hamano, Jun 9, 2005
  17. 3/3 read-tree -m 3-way: handle more trivial merges internallyJunio C Hamano, Jun 9, 2005
  18. Linus TorvaldsJun 9, 2005
  19. Junio C HamanoJun 9, 2005
  20. Linus TorvaldsJun 9, 2005
  21. Junio C HamanoJun 9, 2005
  22. Add git-diff-stages command.Junio C Hamano, Jun 9, 2005
  23. Linus TorvaldsJun 9, 2005
  24. diff-stages: unuglify the too big main() function.Junio C Hamano, Jun 11, 2005
  25. Junio C HamanoJun 10, 2005
  26. Herbert XuJun 18, 2005
  27. Linus TorvaldsJun 18, 2005
  28. Jeff GarzikJun 9, 2005
  29. Linus TorvaldsJun 9, 2005
  30. read-tree.c: rename local variables used in 3-way merge code.Junio C Hamano, Jun 9, 2005
  31. Handle entry removals during merge correctly.Junio C Hamano, Jun 9, 2005
  32. read-tree -m 3-way: loosen an index requirement that was too strict.Junio C Hamano, Jun 9, 2005
  33. read-tree -m 3-way: handle more trivial merges internally.Junio C Hamano, Jun 9, 2005

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.