Skip to contentSkip to conversation

Fix multiple file rename across D/F conflict

PATCH In review Elijah Newren 2 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover Fix multiple file rename across D/F conflict

Another D/F conflict not fixed by the en/d-f-conflict-fix series in next was found in the wild, involving multiple file renames across a D/F conflict. That series would have fixed this case too, were it not for a stupid simple bug. Fix it, and add a testcase for good measure.

This series is on top of next; it needs both the en/d-f-conflict-fix series and the testcase requires em/checkout-orphan.

Elijah Newren (2):
t6031: Add a testcase covering multiple renames across a D/F conflict
merge-recursive: Fix triple file rename across D/F conflict

 merge-recursive.c          |    1 +
 t/t6031-merge-recursive.sh |   28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.2.1.227.g086c8
#1 lore raw

PATCH 1/2 t6031: Add a testcase covering multiple renames across a D/F conflict

---
 t/t6031-merge-recursive.sh |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
t/t6031-merge-recursive.sh +28 -0
index 8a3304f..aa235b9 100755
@@ -57,4 +57,32 @@ test_expect_success FILEMODE 'verify executable bit on file' '
 	test -x file2
 '
 
+test_expect_failure 'merging with triple rename across D/F conflict' '
+	git reset --hard HEAD &&
+	git checkout --orphan main &&
+	git rm -rf . &&
+
+	echo "just a file" > sub1 &&
+	mkdir -p sub2 &&
+	echo content > sub2/file1 &&
+	echo content > sub2/file2 &&
+	echo content > sub2/file3 &&
+	mkdir simple &&
+	echo base > simple/bar &&
+	git add -A &&
+	git commit -m base &&
+
+	git checkout -b other &&
+	echo more >> simple/bar &&
+	git commit -a -m changesimplefile &&
+
+	git checkout main &&
+	git rm sub1 &&
+	git mv sub2 sub1 &&
+	git commit -m changefiletodir &&
+
+	git merge other
+'
+
+
 test_done
Signature · 1 line
1.7.2.1.227.g086c8
#2 lore raw

PATCH 2/2 merge-recursive: Fix multiple file rename across D/F conflict

In reply to Elijah Newren

In 5a2580d (merge_recursive: Fix renames across paths below D/F conflicts 2010-07-09), detection was added for renames across paths involved in a directory<->file conflict. However, the change accidentally involved reusing an outer loop index ('i') in an inner loop, changing its values and causing a slightly different type of breakage for cases where there are multiple renames across the D/F conflict. Fix by creating a new temporary variable 'i'.

---
I'm really embarrased about this one... :-/

 merge-recursive.c          |    1 +
 t/t6031-merge-recursive.sh |    2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)
merge-recursive.c +1 -0
index af53b2a..f413e9f 100644
@@ -1018,6 +1018,7 @@ static int process_renames(struct merge_options *o,
 				if (mfi.clean &&
 				    sha_eq(mfi.sha, ren1->pair->two->sha1) &&
 				    mfi.mode == ren1->pair->two->mode) {
+					int i;
 					/*
 					 * This messaged is part of
 					 * t6022 test. If you change
t/t6031-merge-recursive.sh +1 -1
index aa235b9..25ae637 100755
@@ -57,7 +57,7 @@ test_expect_success FILEMODE 'verify executable bit on file' '
 	test -x file2
 '
 
-test_expect_failure 'merging with triple rename across D/F conflict' '
+test_expect_success 'merging with triple rename across D/F conflict' '
 	git reset --hard HEAD &&
 	git checkout --orphan main &&
 	git rm -rf . &&
Signature · 1 line
1.7.2.1.227.g086c8
#3 lore raw

Re: [PATCH 2/2] merge-recursive: Fix multiple file rename across D/F conflict

Quoted 1 line · Elijah Newren

I'm really embarrased about this one... :-/

Let's embarrass you even more ;-)

After 5a2580d, the merge has become very noisy, and I don't see a good reason for that change.

With a version of git built from 5a2580d^, for example, merging sp/fix-smart-http-deadlock-on-error into maint would give me this:

----------------

$ git merge sp/fix-smart-http-deadlock-on-error
Auto-merging remote-curl.c
Merge made by recursive.
 remote-curl.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
----------------

With 5a2580d, it has become this:

----------------

$ git merge sp/fix-smart-http-deadlock-on-error
Adding builtin/add.c
Auto-merging remote-curl.c
Merge made by recursive.
 remote-curl.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
----------------

And with this patch on top, it will make it a disaster:

----------------

$ git merge sp/fix-smart-http-deadlock-on-error
Adding builtin/add.c
... similar 97 Adding lines omitted ...
Adding gitweb/static/gitweb.js
Auto-merging remote-curl.c
Adding t/lib-t6000.sh
Adding t/t7810-grep.sh
Adding t/t9350-fast-export.sh
Merge made by recursive.
 remote-curl.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
----------------
#5 lore raw

Re: [PATCH 2/2] merge-recursive: Fix multiple file rename across D/F conflict

In reply to Elijah Newren
Quoted 11 lines · Elijah Newren

In 5a2580d (merge_recursive: Fix renames across paths below D/F conflicts 2010-07-09), detection was added for renames across paths involved in a directory<->file conflict. However, the change accidentally involved reusing an outer loop index ('i') in an inner loop, changing its values and causing a slightly different type of breakage for cases where there are multiple renames across the D/F conflict. Fix by creating a new temporary variable 'i'.

---
I'm really embarrased about this one... :-/

I am too ;-) Thanks for a fix.

#4 lore raw

Re: [PATCH 2/2] merge-recursive: Fix multiple file rename across D/F conflict

In reply to Junio C Hamano
Quoted 5 lines · Junio C Hamano
Quoted 1 line · Elijah Newren

I'm really embarrased about this one...  :-/

Let's embarrass you even more ;-)

Mission accomplished. :-/

Quoted 28 lines

After 5a2580d, the merge has become very noisy, and I don't see a good reason for that change.

With a version of git built from 5a2580d^, for example, merging sp/fix-smart-http-deadlock-on-error into maint would give me this:

----------------

$ git merge sp/fix-smart-http-deadlock-on-error
Auto-merging remote-curl.c
Merge made by recursive.
 remote-curl.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
----------------

With 5a2580d, it has become this:

----------------

$ git merge sp/fix-smart-http-deadlock-on-error
Adding builtin/add.c
Auto-merging remote-curl.c
Merge made by recursive.
 remote-curl.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
----------------

And with this patch on top, it will make it a disaster:

----------------

Quoted 12 lines
$ git merge sp/fix-smart-http-deadlock-on-error
Adding builtin/add.c
... similar 97 Adding lines omitted ...
Adding gitweb/static/gitweb.js
Auto-merging remote-curl.c
Adding t/lib-t6000.sh
Adding t/t7810-grep.sh
Adding t/t9350-fast-export.sh
Merge made by recursive.
 remote-curl.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
----------------

Ick.

Interestingly, the new paths I added for additional output are not being triggered here. Rather, "normal" renames are being considered unprocessed (I had a faulty assumption in the previous patch that a clean merge would have cleared out the higher stage entries in dst_entry as a side effect). Because of this, normal renames are needlessly re-processed in process_entry(), and trigger extra output as a side-effect. One could work around this by the following patch, though it'd be better to just avoid the extra reprocessing. I'll submit a better patch in a minute.

merge-recursive.c +1 -0
index 7ac0f57..5ec7f70 100644
@@ -75,6 +75,7 @@ struct stage_data
                unsigned char sha[20];
        } stages[4];
        unsigned processed:1;
+       unsigned silent:1;
 };
 
 static int show(struct merge_options *o, int v)
@@ -1033,9 +1034,11 @@ static int process_renames(struct merge_options *o,
                                         * conflict) that need to be resolved.
                                         */
                                        for (i = 1; i <= 3; i++) {
                                                if

(!ren1->dst_entry->stages[i].mode)

                                                        continue;
                                                ren1->dst_entry->processed = 0;
+                                               ren1->dst_entry->silent = 1;
                                                break;
                                        }
                                } else {
@@ -1188,7 +1198,8 @@ static int process_entry(struct merge_options *o,
                        remove_file(o, 0, path, !a_sha);
                        return 1; /* Assume clean till processed */
                } else {
-                       output(o, 2, "Adding %s", path);
+                       if (!entry->silent)
+                               output(o, 2, "Adding %s", path);
                        update_file(o, 1, sha, mode, path);
                }
        } else if (a_sha && b_sha) {