git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Avoid rename/add conflict when contents are identical
@ 2010-08-09 21:00 Schalk, Ken
  2010-08-09 21:24 ` Ævar Arnfjörð Bjarmason
  2010-08-13  1:18 ` Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Schalk, Ken @ 2010-08-09 21:00 UTC (permalink / raw)
  To: git@vger.kernel.org

Skip the entire rename/add conflict case if the file added on the
other branch has the same contents as the file being renamed.  This
avoids giving the user an extra copy of the same file and presenting a
conflict that is confusing and pointless.

Here's a simple sequence that generates this kind of conflict:

  git init
  echo content > fileA
  git add fileA
  git commit -m Initial
  git checkout -b abranch
  mv fileA fileB
  git add fileB
  rm fileA
  ln -s fileB fileA
  git add fileA
  git commit -m Linked
  git checkout master
  git mv fileA fileB
  git add fileB
  git commit -m Moved
  git merge --no-commit abranch

Signed-off-by: Ken Schalk <ken.schalk@intel.com>
---
 merge-recursive.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index fb6aa4a..57c7a85 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -955,6 +955,18 @@ 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);
+                               if (!o->call_depth)
+                                       update_stages(ren1_dst, NULL,
+                                                       branch1 == o->branch1 ?
+                                                       ren1->pair->two : NULL,
+                                                       branch1 == o->branch1 ?
+                                                       NULL : ren1->pair->two, 1);
                        } else if (!sha_eq(dst_other.sha1, null_sha1)) {
                                const char *new_path;
                                clean_merge = 0;
--
1.7.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid rename/add conflict when contents are identical
  2010-08-09 21:00 [PATCH] Avoid rename/add conflict when contents are identical Schalk, Ken
@ 2010-08-09 21:24 ` Ævar Arnfjörð Bjarmason
  2010-08-13  1:18 ` Junio C Hamano
  1 sibling, 0 replies; 8+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-08-09 21:24 UTC (permalink / raw)
  To: Schalk, Ken; +Cc: git@vger.kernel.org

On Mon, Aug 9, 2010 at 21:00, Schalk, Ken <ken.schalk@intel.com> wrote:

> Here's a simple sequence that generates this kind of conflict:
>
>  git init
>  echo content > fileA
>  git add fileA
>  git commit -m Initial
>  git checkout -b abranch
>  mv fileA fileB
>  git add fileB
>  rm fileA
>  ln -s fileB fileA
>  git add fileA
>  git commit -m Linked
>  git checkout master
>  git mv fileA fileB
>  git add fileB
>  git commit -m Moved
>  git merge --no-commit abranch

I don't know merge well enough to review the code in this patch, but
the patch would be much better if you turned this sequence of commands
(slightly altered, see t/README) into a now-passing test as part of
the patch.

t/t3030-merge-recursive.sh would be the right place to add it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid rename/add conflict when contents are identical
  2010-08-09 21:00 [PATCH] Avoid rename/add conflict when contents are identical Schalk, Ken
  2010-08-09 21:24 ` Ævar Arnfjörð Bjarmason
@ 2010-08-13  1:18 ` Junio C Hamano
  2010-08-27 22:14   ` Schalk, Ken
  1 sibling, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2010-08-13  1:18 UTC (permalink / raw)
  To: Schalk, Ken; +Cc: git@vger.kernel.org

"Schalk, Ken" <ken.schalk@intel.com> writes:

> diff --git a/merge-recursive.c b/merge-recursive.c
> index fb6aa4a..57c7a85 100644
> --- a/merge-recursive.c
> +++ b/merge-recursive.c
> @@ -955,6 +955,18 @@ 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);
> +                               if (!o->call_depth)
> +                                       update_stages(ren1_dst, NULL,
> +                                                       branch1 == o->branch1 ?
> +                                                       ren1->pair->two : NULL,
> +                                                       branch1 == o->branch1 ?
> +                                                       NULL : ren1->pair->two, 1);
>                         } else if (!sha_eq(dst_other.sha1, null_sha1)) {
>                                 const char *new_path;
>                                 clean_merge = 0;

The logic seems to be clear enough.  Could you write a test script instead
of description in the commit log message, so that future changes to the
codebase won't break this improvement?

Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH] Avoid rename/add conflict when contents are identical
  2010-08-13  1:18 ` Junio C Hamano
@ 2010-08-27 22:14   ` Schalk, Ken
  2010-08-28 10:12     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 8+ messages in thread
From: Schalk, Ken @ 2010-08-27 22:14 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org

>The logic seems to be clear enough.  Could you write a test script instead
>of description in the commit log message, so that future changes to the
>codebase won't break this improvement?

Here's a revised patch which fixes a problem with the earlier one and includes a test (where Ævar Bjarmason suggested it):

Skip the entire rename/add conflict case if the file added on the
other branch has the same contents as the file being renamed.  This
avoids giving the user an extra copy of the same file and presenting a
conflict that is confusing and pointless.

A simple test of this case has been added in
t/t3030-merge-recursive.sh.

Signed-off-by: Ken Schalk <ken.schalk@intel.com>
---
 merge-recursive.c          |    6 ++++++
 t/t3030-merge-recursive.sh |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index fb6aa4a..a2fba84 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -955,6 +955,12 @@ 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)) {
                                const char *new_path;
                                clean_merge = 0;
diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh
index d541544..6436582 100755
--- a/t/t3030-merge-recursive.sh
+++ b/t/t3030-merge-recursive.sh
@@ -23,6 +23,8 @@ test_expect_success 'setup 1' '
        git branch df-3 &&
        git branch remove &&
        git branch submod &&
+       git branch mv &&
+       git branch mv-ln &&

        echo hello >>a &&
        cp a d/e &&
@@ -248,6 +250,25 @@ test_expect_success 'setup 7' '
        git commit -m "make d/ a submodule"
 '

+test_expect_success 'setup 8' '
+
+       git checkout mv-ln &&
+       git mv a e &&
+       ln -s e a &&
+       git add a e &&
+       test_tick &&
+       git commit -m "rename a->e, symlink a->e"
+'
+
+test_expect_success 'setup 9' '
+
+       git checkout mv &&
+       git mv a e &&
+       git add e &&
+       test_tick &&
+       git commit -m "rename a->e"
+'
+
 test_expect_success 'merge-recursive simple' '

        rm -fr [abcd] &&
@@ -580,4 +601,23 @@ test_expect_failure 'merge-recursive simple w/submodule result' '
        test_cmp expected actual
 '

+test_expect_success 'merge-recursive rename vs. rename/symlink' '
+
+       git checkout -f mv &&
+       git merge mv-ln &&
+       ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+       (
+               echo "100644 blob $o0   b"
+               echo "100644 blob $o0   c"
+               echo "100644 blob $o0   d/e"
+               echo "100644 blob $o0   e"
+               echo "100644 $o0 0      b"
+               echo "100644 $o0 0      c"
+               echo "100644 $o0 0      d/e"
+               echo "100644 $o0 0      e"
+       ) >expected &&
+       test_cmp expected actual
+'
+
+
 test_done
--
1.7.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid rename/add conflict when contents are identical
  2010-08-27 22:14   ` Schalk, Ken
@ 2010-08-28 10:12     ` Ævar Arnfjörð Bjarmason
  2010-08-31 21:05       ` Schalk, Ken
  2010-09-01 20:15       ` Schalk, Ken
  0 siblings, 2 replies; 8+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-08-28 10:12 UTC (permalink / raw)
  To: Schalk, Ken; +Cc: Junio C Hamano, git@vger.kernel.org

On Fri, Aug 27, 2010 at 22:14, Schalk, Ken <ken.schalk@intel.com> wrote:

> +       ln -s e a &&

Due to this this (and maybe all the tests) need to depend on the
SYMLINKS prereq.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH] Avoid rename/add conflict when contents are identical
  2010-08-28 10:12     ` Ævar Arnfjörð Bjarmason
@ 2010-08-31 21:05       ` Schalk, Ken
  2010-09-01 20:15       ` Schalk, Ken
  1 sibling, 0 replies; 8+ messages in thread
From: Schalk, Ken @ 2010-08-31 21:05 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Junio C Hamano, git@vger.kernel.org

>On Fri, Aug 27, 2010 at 22:14, Schalk, Ken <ken.schalk@intel.com> wrote:

>> +       ln -s e a &&

>Due to this this (and maybe all the tests) need to depend on the
>SYMLINKS prereq.

I used a symlink here to try and duplicate the original problem case that a git user at Intel brought to me.  I admit I didn't consider the problem of testing on platforms without symlink support.

I'm having a little difficulty generating a rename/add conflict inside this test without using a symlink, which seems odd to me as the symlink doesn't seem to be necessary in an experiment I did by hand.  I'll either re-submit with this portion of the test conditional on symlink support, or with an alternate test that doesn't use symlinks (if I can get that to work in the test).

--Ken

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH] Avoid rename/add conflict when contents are identical
  2010-08-28 10:12     ` Ævar Arnfjörð Bjarmason
  2010-08-31 21:05       ` Schalk, Ken
@ 2010-09-01 20:15       ` Schalk, Ken
  2010-09-03 18:29         ` Junio C Hamano
  1 sibling, 1 reply; 8+ messages in thread
From: Schalk, Ken @ 2010-09-01 20:15 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Junio C Hamano, git@vger.kernel.org

>Due to this this (and maybe all the tests) need to depend on the
>SYMLINKS prereq.

Here's a third attempt with no use of symlinks in the test:

Skip the entire rename/add conflict case if the file added on the
other branch has the same contents as the file being renamed.  This
avoids giving the user an extra copy of the same file and presenting a
conflict that is confusing and pointless.

A simple test of this case has been added in
t/t3030-merge-recursive.sh.

Signed-off-by: Ken Schalk <ken.schalk@intel.com>
---
 merge-recursive.c          |    6 ++++++
 t/t3030-merge-recursive.sh |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index fb6aa4a..a2fba84 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -955,6 +955,12 @@ 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)) {
                                const char *new_path;
                                clean_merge = 0;
diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh
index d541544..b23bd9f 100755
--- a/t/t3030-merge-recursive.sh
+++ b/t/t3030-merge-recursive.sh
@@ -23,6 +23,8 @@ test_expect_success 'setup 1' '
        git branch df-3 &&
        git branch remove &&
        git branch submod &&
+       git branch copy &&
+       git branch rename &&

        echo hello >>a &&
        cp a d/e &&
@@ -248,6 +250,24 @@ test_expect_success 'setup 7' '
        git commit -m "make d/ a submodule"
 '

+test_expect_success 'setup 8' '
+
+       git checkout rename &&
+       git mv a e &&
+       git add e &&
+       test_tick &&
+       git commit -m "rename a->e"
+'
+
+test_expect_success 'setup 9' '
+
+       git checkout copy &&
+       cp a e &&
+       git add e &&
+       test_tick &&
+       git commit -m "copy a->e"
+'
+
 test_expect_success 'merge-recursive simple' '

        rm -fr [abcd] &&
@@ -580,4 +600,23 @@ test_expect_failure 'merge-recursive simple w/submodule result' '
        test_cmp expected actual
 '

+test_expect_success 'merge-recursive copy vs. rename' '
+
+       git checkout -f copy &&
+       git merge rename &&
+       ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+       (
+               echo "100644 blob $o0   b"
+               echo "100644 blob $o0   c"
+               echo "100644 blob $o0   d/e"
+               echo "100644 blob $o0   e"
+               echo "100644 $o0 0      b"
+               echo "100644 $o0 0      c"
+               echo "100644 $o0 0      d/e"
+               echo "100644 $o0 0      e"
+       ) >expected &&
+       test_cmp expected actual
+'
+
+
 test_done
--
1.7.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] Avoid rename/add conflict when contents are identical
  2010-09-01 20:15       ` Schalk, Ken
@ 2010-09-03 18:29         ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2010-09-03 18:29 UTC (permalink / raw)
  To: Schalk, Ken; +Cc: Ævar Arnfjörð Bjarmason, git@vger.kernel.org

Thanks; the patch somehow had all tabs expanded, but I can fix it up.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-09-03 18:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-09 21:00 [PATCH] Avoid rename/add conflict when contents are identical Schalk, Ken
2010-08-09 21:24 ` Ævar Arnfjörð Bjarmason
2010-08-13  1:18 ` Junio C Hamano
2010-08-27 22:14   ` Schalk, Ken
2010-08-28 10:12     ` Ævar Arnfjörð Bjarmason
2010-08-31 21:05       ` Schalk, Ken
2010-09-01 20:15       ` Schalk, Ken
2010-09-03 18:29         ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).