[PATCH] hg stable: fix issue 4748; origin of a renamed file is lost after merge

Jeremy Parente jeremy.parente at oneaccess-net.com
Mon Jul 13 12:43:27 CDT 2015


# HG changeset patch
# User jepa, system HG Jeremy Parente <jeremy.parente at oneaccess-net.com>
# Date 1436802799 -7200
#      Mon Jul 13 17:53:19 2015 +0200
# Branch stable
# Node ID b8c73f1f0d2e89aeb852f722bd3814112484d262
# Parent  540cd0ddac49c1125b2e013aa2ff18ecbd4dd954
hg: merge renamed file in c2 not modified in c1 treated as a copy (issue4748)

Change how to handle divergent that is a rename in c2 but unmodified in c1 to
keep origin, we treat such case like a copy to be able to track diff between
renamed file and original file.

diff -r 540cd0ddac49 -r b8c73f1f0d2e mercurial/copies.py
--- a/mercurial/copies.py	Mon Jun 29 19:09:42 2015 -0700
+++ b/mercurial/copies.py	Mon Jul 13 17:53:19 2015 +0200
@@ -337,6 +337,12 @@
                  # out files that have been renamed and then deleted
                  renamedelete[of] = [f for f in fl if f in c1 or f in c2]
                  renamedelete2.update(fl) # reverse map for below
+            elif of in c1 and of not in c2:
+                # fix: issue4748; not divergent, just matching renames else we
+                # lost the origin information and can't anymore diff the new
+                # file with an older revision where the file is named with the
+                # original file name
+                copy[fl[0]] = of
          else:
              diverge2.update(fl) # reverse map for below

diff -r 540cd0ddac49 -r b8c73f1f0d2e tests/test-commit-amend.t
--- a/tests/test-commit-amend.t	Mon Jun 29 19:09:42 2015 -0700
+++ b/tests/test-commit-amend.t	Mon Jul 13 17:53:19 2015 +0200
@@ -633,7 +633,7 @@
    (no more unresolved files)
    $ hg ci -m 'merge bar'
    $ hg log --config diff.git=1 -pr .
-  changeset:   23:93cd4445f720
+  changeset:   23:00530ee041cb
    tag:         tip
    parent:      22:30d96aeaf27b
    parent:      21:1aa437659d19
@@ -666,7 +666,7 @@
    $ HGEDITOR="sh .hg/checkeditform.sh" hg ci --amend -m 'merge bar (amend 
message)' --edit
    HGEDITFORM=commit.amend.merge
    $ hg log --config diff.git=1 -pr .
-  changeset:   24:832b50f2c271
+  changeset:   24:95901dec8caf
    tag:         tip
    parent:      22:30d96aeaf27b
    parent:      21:1aa437659d19
@@ -699,7 +699,7 @@
    $ hg mv zz z
    $ hg ci --amend -m 'merge bar (undo rename)'
    $ hg log --config diff.git=1 -pr .
-  changeset:   26:bdafc5c72f74
+  changeset:   26:b26049e2280c
    tag:         tip
    parent:      22:30d96aeaf27b
    parent:      21:1aa437659d19
@@ -735,9 +735,9 @@
    $ echo aa >> aaa
    $ hg ci -m 'merge bar again'
    $ hg log --config diff.git=1 -pr .
-  changeset:   28:32f19415b634
+  changeset:   28:043883f1ee2e
    tag:         tip
-  parent:      26:bdafc5c72f74
+  parent:      26:b26049e2280c
    parent:      27:4c94d5bc65f5
    user:        test
    date:        Thu Jan 01 00:00:00 1970 +0000
@@ -770,9 +770,9 @@
    $ hg mv aaa aa
    $ hg ci --amend -m 'merge bar again (undo rename)'
    $ hg log --config diff.git=1 -pr .
-  changeset:   30:1e2a06b3d312
+  changeset:   30:a3ac3d1ec482
    tag:         tip
-  parent:      26:bdafc5c72f74
+  parent:      26:b26049e2280c
    parent:      27:4c94d5bc65f5
    user:        test
    date:        Thu Jan 01 00:00:00 1970 +0000
@@ -810,9 +810,9 @@
    use (c)hanged version or (d)elete? c
    $ hg ci -m 'merge bar (with conflicts)'
    $ hg log --config diff.git=1 -pr .
-  changeset:   33:97a298b0c59f
+  changeset:   33:4fd48f6e2dfe
    tag:         tip
-  parent:      32:3d78ce4226b8
+  parent:      32:874800cc4ebf
    parent:      31:67db8847a540
    user:        test
    date:        Thu Jan 01 00:00:00 1970 +0000
@@ -822,9 +822,9 @@
    $ hg rm aa
    $ hg ci --amend -m 'merge bar (with conflicts, amended)'
    $ hg log --config diff.git=1 -pr .
-  changeset:   35:6de0c1bde1c8
+  changeset:   35:14ad99f27692
    tag:         tip
-  parent:      32:3d78ce4226b8
+  parent:      32:874800cc4ebf
    parent:      31:67db8847a540
    user:        test
    date:        Thu Jan 01 00:00:00 1970 +0000
@@ -922,7 +922,7 @@
    HG: M:
    HG: A: foo
    HG: R:
-  HG: diff -r 6de0c1bde1c8 foo
+  HG: diff -r 14ad99f27692 foo
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
@@ -936,12 +936,12 @@
    HG: M:
    HG: A: foo y
    HG: R:
-  HG: diff -r 6de0c1bde1c8 foo
+  HG: diff -r 14ad99f27692 foo
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
    HG: +foo
-  HG: diff -r 6de0c1bde1c8 y
+  HG: diff -r 14ad99f27692 y
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/y	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
@@ -954,18 +954,18 @@
    HG: M:
    HG: A: foo y
    HG: R: a
-  HG: diff -r 6de0c1bde1c8 a
+  HG: diff -r 14ad99f27692 a
    HG: --- a/a	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -1,2 +0,0 @@
    HG: -a
    HG: -a
-  HG: diff -r 6de0c1bde1c8 foo
+  HG: diff -r 14ad99f27692 foo
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
    HG: +foo
-  HG: diff -r 6de0c1bde1c8 y
+  HG: diff -r 14ad99f27692 y
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/y	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
@@ -978,23 +978,23 @@
    HG: M:
    HG: A: foo y
    HG: R: a x
-  HG: diff -r 6de0c1bde1c8 a
+  HG: diff -r 14ad99f27692 a
    HG: --- a/a	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -1,2 +0,0 @@
    HG: -a
    HG: -a
-  HG: diff -r 6de0c1bde1c8 foo
+  HG: diff -r 14ad99f27692 foo
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
    HG: +foo
-  HG: diff -r 6de0c1bde1c8 x
+  HG: diff -r 14ad99f27692 x
    HG: --- a/x	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -1,1 +0,0 @@
    HG: -x
-  HG: diff -r 6de0c1bde1c8 y
+  HG: diff -r 14ad99f27692 y
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/y	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
@@ -1009,23 +1009,23 @@
    HG: M:
    HG: A: foo y
    HG: R: a x
-  HG: diff -r 6de0c1bde1c8 a
+  HG: diff -r 14ad99f27692 a
    HG: --- a/a	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -1,2 +0,0 @@
    HG: -a
    HG: -a
-  HG: diff -r 6de0c1bde1c8 foo
+  HG: diff -r 14ad99f27692 foo
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
    HG: +foo
-  HG: diff -r 6de0c1bde1c8 x
+  HG: diff -r 14ad99f27692 x
    HG: --- a/x	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -1,1 +0,0 @@
    HG: -x
-  HG: diff -r 6de0c1bde1c8 y
+  HG: diff -r 14ad99f27692 y
    HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    HG: +++ b/y	Thu Jan 01 00:00:00 1970 +0000
    HG: @@ -0,0 +1,1 @@
diff -r 540cd0ddac49 -r b8c73f1f0d2e tests/test-convert-hg-startrev.t
--- a/tests/test-convert-hg-startrev.t	Mon Jun 29 19:09:42 2015 -0700
+++ b/tests/test-convert-hg-startrev.t	Mon Jul 13 17:53:19 2015 +0200
@@ -30,7 +30,7 @@
    $ hg ci -d '3 0' -qAm '3: change a'
    $ hg merge
    merging a and e to e
-  3 files updated, 1 files merged, 1 files removed, 0 files unresolved
+  3 files updated, 1 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)
    $ hg ci -d '4 0' -qAm '4: merge 2 and 3'
    $ echo a >> a
@@ -54,7 +54,7 @@
    $ glog full
    o  5 "5: change a" files: a
    |
-  o    4 "4: merge 2 and 3" files: e f
+  o    4 "4: merge 2 and 3" files: d e f
    |\
    | o  3 "3: change a" files: a
    | |
@@ -83,7 +83,7 @@
    $ glog full
    o  5 "5: change a" files: a
    |
-  o    4 "4: merge 2 and 3" files: e f
+  o    4 "4: merge 2 and 3" files: d e f
    |\
    | o  3 "3: change a" files: a
    | |
@@ -130,7 +130,7 @@
  (It seems like a bug in log that the following doesn't show rev 1.)

    $ hg log --follow --copies e
-  changeset:   2:82bbac3d2cf4
+  changeset:   2:54402235e79a
    user:        test
    date:        Thu Jan 01 00:00:04 1970 +0000
    summary:     4: merge 2 and 3
diff -r 540cd0ddac49 -r b8c73f1f0d2e tests/test-issue672.t
--- a/tests/test-issue672.t	Mon Jun 29 19:09:42 2015 -0700
+++ b/tests/test-issue672.t	Mon Jul 13 17:53:19 2015 +0200
@@ -29,19 +29,17 @@
      unmatched files in other:
       1a
      all copies found (* = to merge, ! = divergent, % = renamed and deleted):
-     src: '1' -> dst: '1a'
+     src: '1' -> dst: '1a' *
      checking for directory renames
    resolving manifests
     branchmerge: True, force: False, partial: False
     ancestor: 81f4b099af3d, local: c64f439569a9+, remote: c12dcd37c90a
-   1: other deleted -> r
+   preserving 1 for resolve of 1a
    removing 1
-  updating: 1 1/2 files (50.00%)
-   1a: remote created -> g
-  getting 1a
-  updating: 1a 2/2 files (100.00%)
     2: remote unchanged -> k
-  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+   1a: remote moved from 1 -> m
+  updating: 1a 1/1 files (100.00%)
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)

    $ hg ci -m merge1 # 3
@@ -65,13 +63,13 @@
      checking for directory renames
    resolving manifests
     branchmerge: True, force: False, partial: False
-   ancestor: c64f439569a9, local: e327dca35ac8+, remote: 746e9549ea96
+   ancestor: c64f439569a9, local: 7aff4c906f45+, remote: 746e9549ea96
     preserving 1a for resolve of 1a
     1a: local copied/moved from 1 -> m
    updating: 1a 1/1 files (100.00%)
    picked tool 'internal:merge' for 1a (binary False symlink False)
    merging 1a and 1 to 1a
-  my 1a at e327dca35ac8+ other 1 at 746e9549ea96 ancestor 1 at 81f4b099af3d
+  my 1a at 7aff4c906f45+ other 1 at 746e9549ea96 ancestor 1 at 81f4b099af3d
     premerge successful
    0 files updated, 1 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)
@@ -88,14 +86,14 @@
      checking for directory renames
    resolving manifests
     branchmerge: True, force: False, partial: False
-   ancestor: c64f439569a9, local: 746e9549ea96+, remote: e327dca35ac8
+   ancestor: c64f439569a9, local: 746e9549ea96+, remote: 7aff4c906f45
     preserving 1 for resolve of 1a
    removing 1
     1a: remote moved from 1 -> m
    updating: 1a 1/1 files (100.00%)
    picked tool 'internal:merge' for 1a (binary False symlink False)
    merging 1 and 1a to 1a
-  my 1a at 746e9549ea96+ other 1a at e327dca35ac8 ancestor 1 at 81f4b099af3d
+  my 1a at 746e9549ea96+ other 1a at 7aff4c906f45 ancestor 1 at 81f4b099af3d
     premerge successful
    0 files updated, 1 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)
diff -r 540cd0ddac49 -r b8c73f1f0d2e tests/test-merge-local.t
--- a/tests/test-merge-local.t	Mon Jun 29 19:09:42 2015 -0700
+++ b/tests/test-merge-local.t	Mon Jul 13 17:53:19 2015 +0200
@@ -55,7 +55,7 @@
    merging zzz1_merge_ok
    merging zzz2_merge_bad
    merging zzz2_merge_bad failed!
-  3 files updated, 1 files merged, 2 files removed, 1 files unresolved
+  3 files updated, 1 files merged, 1 files removed, 1 files unresolved
    use 'hg resolve' to retry unresolved file merges
    [1]

@@ -89,7 +89,7 @@
    merging zzz2_merge_bad
    warning: conflicts during merge.
    merging zzz2_merge_bad incomplete! (edit conflicts, then use 'hg resolve 
--mark')
-  3 files updated, 1 files merged, 2 files removed, 1 files unresolved
+  3 files updated, 1 files merged, 1 files removed, 1 files unresolved
    use 'hg resolve' to retry unresolved file merges
    [1]

@@ -125,7 +125,7 @@

    $ hg co
    merging zzz1_merge_ok
-  4 files updated, 1 files merged, 2 files removed, 0 files unresolved
+  4 files updated, 1 files merged, 1 files removed, 0 files unresolved

    $ hg diff --nodates | grep "^[+-][^<>]"
    --- a/zzz1_merge_ok
diff -r 540cd0ddac49 -r b8c73f1f0d2e tests/test-rename-dir-merge.t
--- a/tests/test-rename-dir-merge.t	Mon Jun 29 19:09:42 2015 -0700
+++ b/tests/test-rename-dir-merge.t	Mon Jul 13 17:53:19 2015 +0200
@@ -31,35 +31,35 @@
       b/a
       b/b
      all copies found (* = to merge, ! = divergent, % = renamed and deleted):
-     src: 'a/a' -> dst: 'b/a'
-     src: 'a/b' -> dst: 'b/b'
+     src: 'a/a' -> dst: 'b/a' *
+     src: 'a/b' -> dst: 'b/b' *
      checking for directory renames
       discovered dir src: 'a/' -> dst: 'b/'
       pending file src: 'a/c' -> dst: 'b/c'
    resolving manifests
     branchmerge: True, force: False, partial: False
     ancestor: f9b20c0d4c51, local: ce36d17b18fb+, remote: 397f8b00a740
-   a/a: other deleted -> r
+   preserving a/a for resolve of b/a
+   preserving a/b for resolve of b/b
    removing a/a
-   a/b: other deleted -> r
    removing a/b
-  updating: a/b 2/5 files (40.00%)
-   b/a: remote created -> g
-  getting b/a
-   b/b: remote created -> g
-  getting b/b
-  updating: b/b 4/5 files (80.00%)
+   b/a: remote moved from a/a -> m
+  updating: b/a 1/3 files (33.33%)
+   b/b: remote moved from a/b -> m
+  updating: b/b 2/3 files (66.67%)
     b/c: remote directory rename - move from a/c -> dm
-  updating: b/c 5/5 files (100.00%)
+  updating: b/c 3/3 files (100.00%)
    moving a/c to b/c (glob)
-  3 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)

    $ echo a/* b/*
    a/d b/a b/b b/c
    $ hg st -C
    M b/a
+    a/a
    M b/b
+    a/b
    A b/c
      a/c
    R a/a
@@ -71,7 +71,7 @@
    b/c renamed from a/c:354ae8da6e890359ef49ade27b68bbc361f3ca88 (glob)

    $ hg co -C 1
-  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 1 files removed, 0 files unresolved
    $ hg merge --debug 2
      searching for copies back to rev 1
      unmatched files in local:
@@ -168,12 +168,14 @@
    merging a/c and b/c to b/c
    warning: conflicts during merge.
    merging b/c incomplete! (edit conflicts, then use 'hg resolve --mark')
-  2 files updated, 0 files merged, 2 files removed, 1 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 1 files unresolved
    use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
    [1]
    $ hg st -A
    M b/a
+    a/a
    M b/b
+    a/b
    M b/c
      a/c
    R a/a
@@ -226,11 +228,13 @@
    (run 'hg heads' to see heads, 'hg merge' to merge)

    $ hg merge
-  2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  merging a/f and b/f to b/f
+  1 files updated, 1 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)

    $ hg st -C
    M b/f
+    a/f
    A b/aa/g
      a/aa/g
    R a/aa/g
diff -r 540cd0ddac49 -r b8c73f1f0d2e tests/test-rename-merge2.t
--- a/tests/test-rename-merge2.t	Mon Jun 29 19:09:42 2015 -0700
+++ b/tests/test-rename-merge2.t	Mon Jul 13 17:53:19 2015 +0200
@@ -293,29 +293,28 @@
      unmatched files in other:
       b
      all copies found (* = to merge, ! = divergent, % = renamed and deleted):
-     src: 'a' -> dst: 'b'
+     src: 'a' -> dst: 'b' *
      checking for directory renames
    resolving manifests
     branchmerge: True, force: False, partial: False
     ancestor: 924404dff337, local: 94b33a1b7f2d+, remote: bdb19105162a
+   preserving a for resolve of b
     preserving rev for resolve of rev
-   a: other deleted -> r
    removing a
-  updating: a 1/3 files (33.33%)
-   b: remote created -> g
-  getting b
-  updating: b 2/3 files (66.67%)
+   b: remote moved from a -> m
+  updating: b 1/2 files (50.00%)
     rev: versions differ -> m
-  updating: rev 3/3 files (100.00%)
+  updating: rev 2/2 files (100.00%)
    picked tool 'python ../merge' for rev (binary False symlink False)
    merging rev
    my rev at 94b33a1b7f2d+ other rev at bdb19105162a ancestor rev at 924404dff337
    launching merge tool: python ../merge *$TESTTMP/t/t/rev* * * (glob)
    merge tool returned: 0
-  1 files updated, 1 files merged, 1 files removed, 0 files unresolved
+  1 files updated, 1 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)
    --------------
    M b
+    a
    --------------

    $ tm "nm a b" "      " "      " "8  nothing"
diff -r 540cd0ddac49 -r b8c73f1f0d2e tests/test-revert.t
--- a/tests/test-revert.t	Mon Jun 29 19:09:42 2015 -0700
+++ b/tests/test-revert.t	Mon Jul 13 17:53:19 2015 +0200
@@ -350,7 +350,7 @@
  merge it with the other head

    $ hg merge # merge 1 into 2
-  2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
    (branch merge, don't forget to commit)
    $ hg summary
    parent: 2:b8ec310b2d4e tip
@@ -358,7 +358,7 @@
    parent: 1:f6180deb8fbe
     rename
    branch: default
-  commit: 2 modified, 1 removed (merge)
+  commit: 2 modified, 1 renamed (merge)
    update: (current)

  clarifies who added what
@@ -412,7 +412,6 @@
    $ hg status
    M base
    R allyour
-  R ignored
    R newadd

  Systematic behavior validation of most possible cases


More information about the Mercurial-devel mailing list