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

[PATCH 2/3] merge-recursive: Small code cleanup

From
Elijah Newren <newren@gmail.com>
Date
Sep 6, 2010, 20:47 UTC
Message-ID
<1283806070-22027-3-git-send-email-newren@gmail.com>
In-Reply-To
<AANLkTimz8qSwefp137-D+vEbsf6soG51u0im9EC911_O@mail.gmail.com>

process_renames() had a variable named "stage" and derived variables src_other and dst_other whose purpose was not entirely clear to me. Make the name of stage slightly more descriptive and add a brief comment explaining what is occurring.

Also, in d5af510 (RE: [PATCH] Avoid rename/add conflict when contents are identical 2010-09-01), a separate if-block was added to provide a special case for the rename/add conflict case that can be resolved (namely when the contents on the destination side are identical). However, as a separate if block, it's not immediately obvious that its code is related to the subsequent code checking for a rename/add conflict. We can combine and simplify the check slightly.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-recursive.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index c574698..5e2886a 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -923,15 +923,26 @@ static int process_renames(struct merge_options *o,
 			/* Renamed in 1, maybe changed in 2 */
 			struct string_list_item *item;
 			/* we only use sha1 and mode of these */
-			struct diff_filespec src_other, dst_other;
-			int try_merge, stage = a_renames == renames1 ? 3: 2;
+			struct diff_filespec src_other, dst_other, dst_renamed;
+			int try_merge;
 
-			remove_file(o, 1, ren1_src, o->call_depth || stage == 3);
+			/*
+			 * unpack_trees loads entries from common-commit
+			 * into stage 1, from head-commit into stage 2, and
+			 * from merge-commit into stage 3.  We keep track
+			 * of which side corresponds to the rename.
+			 */
+			int renamed_stage = a_renames == renames1 ? 2 : 3;
+			int other_stage =   a_renames == renames1 ? 3 : 2;
+
+			remove_file(o, 1, ren1_src, o->call_depth || renamed_stage == 2);
 
-			hashcpy(src_other.sha1, ren1->src_entry->stages[stage].sha);
-			src_other.mode = ren1->src_entry->stages[stage].mode;
-			hashcpy(dst_other.sha1, ren1->dst_entry->stages[stage].sha);
-			dst_other.mode = ren1->dst_entry->stages[stage].mode;
+			hashcpy(src_other.sha1, ren1->src_entry->stages[other_stage].sha);
+			src_other.mode = ren1->src_entry->stages[other_stage].mode;
+			hashcpy(dst_other.sha1, ren1->dst_entry->stages[other_stage].sha);
+			dst_other.mode = ren1->dst_entry->stages[other_stage].mode;
+			hashcpy(dst_renamed.sha1, ren1->dst_entry->stages[renamed_stage].sha);
+			dst_renamed.mode = ren1->dst_entry->stages[renamed_stage].mode;
 
 			try_merge = 0;
 
@@ -955,13 +966,8 @@ static int process_renames(struct merge_options *o,
 							ren1->pair->two : NULL,
 							branch1 == o->branch1 ?
 							NULL : ren1->pair->two, 1);
-			} else if ((dst_other.mode == ren1->pair->two->mode) &&
-				   sha_eq(dst_other.sha1, ren1->pair->two->sha1)) {
-				/* Added file on the other side
-				   identical to the file being
-				   renamed: clean merge */
-				update_file(o, 1, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
-			} else if (!sha_eq(dst_other.sha1, null_sha1)) {
+			} else if (!sha_eq(dst_other.sha1, null_sha1) &&
+				   !sha_eq(dst_other.sha1, dst_renamed.sha1)) {
 				const char *new_path;
 				clean_merge = 0;
 				try_merge = 1;
-- 
1.7.3.rc0.170.g5cfb0.dirty
Previous: Elijah NewrenNext: Elijah Newren
Message 7 of 14 in “cherry-picking a commit clobbers a file which is a directory in the target commit”
  1. NickSep 2, 2010
  2. NickSep 6, 2010
  3. Elijah NewrenSep 6, 2010
  4. 0/3 Fix resolvable rename + D/F conflict testcasesElijah Newren, Sep 6, 2010
  5. Elijah NewrenSep 6, 2010
  6. 1/3 t3509: Add rename + D/F conflict testcases that recursive strategy failsElijah Newren, Sep 6, 2010
  7. 2/3 merge-recursive: Small code cleanupElijah Newren, Sep 6, 2010
  8. Elijah NewrenSep 6, 2010
  9. Junio C HamanoSep 6, 2010
  10. Schalk, KenSep 7, 2010
  11. Elijah NewrenSep 8, 2010
  12. Schalk, KenSep 9, 2010
  13. Camille MoncelierOct 21, 2010
  14. 3/3 merge-recursive: D/F conflicts where was_a_dir/file -> was_a_dirElijah Newren, Sep 6, 2010

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.