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

[PATCH] read-tree.c: rename local variables used in 3-way merge code.

From
Junio C Hamano <junkio@cox.net>
Date
Jun 9, 2005, 22:45 UTC
Message-ID
<7vvf4n9mjc.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.58.0506091152530.2286@ppc970.osdl.org>

I'd hate to do this, but every time I try to touch this code and validate what it does against the case matrix in t1000 test I get confused. The variable names are renamed to match the case matrix. Now they are named as:

    i -- entry from the index file (formerly known as "old")
    o -- merge base (formerly known as "a")
    a -- our head (formerly known as "b")
    b -- merge head (formerly known as "c")
Signed-off-by: Junio C Hamano <junkio@cox.net>
---

*** Re-submit. I've rebased the series from the last night. *** This is the first of them.

 read-tree.c |   40 ++++++++++++++++++++--------------------
 1 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/read-tree.c b/read-tree.c
--- a/read-tree.c
+++ b/read-tree.c
@@ -40,9 +40,9 @@ static int same(struct cache_entry *a, s
  * This removes all trivial merges that don't change the tree
  * and collapses them to state 0.
  */
-static struct cache_entry *merge_entries(struct cache_entry *a,
-					 struct cache_entry *b,
-					 struct cache_entry *c)
+static struct cache_entry *merge_entries(struct cache_entry *o,
+					 struct cache_entry *a,
+					 struct cache_entry *b)
 {
 	/*
 	 * Ok, all three entries describe the same
@@ -58,16 +58,16 @@ static struct cache_entry *merge_entries
 	 * The "all entries exactly the same" case falls out as
 	 * a special case of any of the "two same" cases.
 	 *
-	 * Here "a" is "original", and "b" and "c" are the two
+	 * Here "o" is "original", and "a" and "b" are the two
 	 * trees we are merging.
 	 */
-	if (a && b && c) {
-		if (same(b,c))
-			return c;
+	if (o && a && b) {
 		if (same(a,b))
-			return c;
-		if (same(a,c))
 			return b;
+		if (same(o,a))
+			return b;
+		if (same(o,b))
+			return a;
 	}
 	return NULL;
 }
@@ -126,29 +126,29 @@ static int merged_entry(struct cache_ent
 
 static int threeway_merge(struct cache_entry *stages[4], struct cache_entry **dst)
 {
-	struct cache_entry *old = stages[0];
-	struct cache_entry *a = stages[1], *b = stages[2], *c = stages[3];
+	struct cache_entry *i = stages[0];
+	struct cache_entry *o = stages[1], *a = stages[2], *b = stages[3];
 	struct cache_entry *merge;
 	int count;
 
 	/*
-	 * If we have an entry in the index cache ("old"), then we want
+	 * 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
-	 * branch", aka "b").
+	 * branch", aka "a").
 	 */
-	if (old) {
-		if (!b || !same(old, b))
+	if (i) {
+		if (!a || !same(i, a))
 			return -1;
 	}
-	merge = merge_entries(a, b, c);
+	merge = merge_entries(o, a, b);
 	if (merge)
-		return merged_entry(merge, old, dst);
-	if (old)
-		verify_uptodate(old);
+		return merged_entry(merge, i, dst);
+	if (i)
+		verify_uptodate(i);
 	count = 0;
+	if (o) { *dst++ = o; count++; }
 	if (a) { *dst++ = a; count++; }
 	if (b) { *dst++ = b; count++; }
-	if (c) { *dst++ = c; count++; }
 	return count;
 }
 
------------
Previous: Linus TorvaldsNext: Junio C Hamano
Message 30 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.