merge: when rename was made on both sides, use ancestor as merge base
When both sides of a merge have renamed a file to the same place, we
would treat that as a "both created" action in merge.py. That means
that we'd use an empty diffbase. It seems better to use the copy
source as diffbase. That can be done by simply dropping code that
prevented us from doing that. I think I did it that way in
57203e0210f8 (copies: calculate mergecopies() based on pathcopies(),
2019-04-11) only to preserve the existing behavior. I also suspect it
was just an accident that it behaved that way before that commit.
Note that until
fa9ad1da2e77 (merge: start using the per-side copy
dicts, 2020-01-23), it was non-deterministic (depending on iteration
order of the `allsources` set in `copies._fullcopytracing()`) which
source was used in the affected test case in test-rename-merge1.t. We
could easily have fixed that by sorting them, but now we can instead
detect the case (the TODO added in the previous patch).
Differential Revision: https://phab.mercurial-scm.org/D7974
--- a/mercurial/copies.py Fri Jan 31 08:47:32 2020 -0800
+++ b/mercurial/copies.py Wed Jan 22 13:29:26 2020 -0800
@@ -537,10 +537,7 @@
return
# modified on side 2
for dst in dsts1:
- if dst not in m2:
- # dst not added on side 2 (handle as regular
- # "both created" case in manifestmerge otherwise)
- copy[dst] = src
+ copy[dst] = src
class branch_copies(object):
--- a/tests/test-rename-merge1.t Fri Jan 31 08:47:32 2020 -0800
+++ b/tests/test-rename-merge1.t Wed Jan 22 13:29:26 2020 -0800
@@ -206,57 +206,31 @@
# Depending on which side they pick, we should take that rename and get
# the changes to the source from the other side. The unchanged file should
# remain.
-# we should not get the prompts about modify/delete conflicts
$ hg merge --debug 1 -t :merge3
all copies found (* = to merge, ! = divergent, % = renamed and deleted):
on local side:
- src: 'y' -> dst: 'z'
+ src: 'y' -> dst: 'z' *
on remote side:
- src: 'x' -> dst: 'z'
+ src: 'x' -> dst: 'z' *
checking for directory renames
resolving manifests
branchmerge: True, force: False, partial: False
ancestor: 5151c134577e, local: 07fcbc9a74ed+, remote: f21419739508
- preserving x for resolve of x
preserving z for resolve of z
starting 4 threads for background file closing (?)
- x: prompt changed/deleted -> m (premerge)
- picked tool ':prompt' for x (binary False symlink False changedelete True)
- file 'x' was deleted in other [merge rev] but was modified in local [working copy].
- You can use (c)hanged version, (d)elete, or leave (u)nresolved.
- What do you want to do? u
- y: prompt deleted/changed -> m (premerge)
- picked tool ':prompt' for y (binary False symlink False changedelete True)
- file 'y' was deleted in local [working copy] but was modified in other [merge rev].
- You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved.
- What do you want to do? u
- z: both created -> m (premerge)
+ z: both renamed from y -> m (premerge)
picked tool ':merge3' for z (binary False symlink False changedelete False)
merging z
- my z@07fcbc9a74ed+ other z@f21419739508 ancestor z@000000000000
- z: both created -> m (merge)
- picked tool ':merge3' for z (binary False symlink False changedelete False)
- my z@07fcbc9a74ed+ other z@f21419739508 ancestor z@000000000000
- warning: conflicts while merging z! (edit, then use 'hg resolve --mark')
- 0 files updated, 0 files merged, 0 files removed, 3 files unresolved
- use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
- [1]
+ my z@07fcbc9a74ed+ other z@f21419739508 ancestor y@5151c134577e
+ premerge successful
+ 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+ (branch merge, don't forget to commit)
$ ls
x
- y
z
- z.orig
$ cat x
x
foo
- $ cat y
- y
- foo
# 'z' should have had the added 'foo' line
$ cat z
- <<<<<<< working copy: 07fcbc9a74ed - test: modify x, rename y to z
- y
- ||||||| base
- =======
x
- >>>>>>> merge rev: f21419739508 - test: modify y, rename x to z
--- a/tests/test-rename-merge2.t Fri Jan 31 08:47:32 2020 -0800
+++ b/tests/test-rename-merge2.t Wed Jan 22 13:29:26 2020 -0800
@@ -529,7 +529,7 @@
--------------
all copies found (* = to merge, ! = divergent, % = renamed and deleted):
on local side:
- src: 'a' -> dst: 'b'
+ src: 'a' -> dst: 'b' *
checking for directory renames
resolving manifests
branchmerge: True, force: False, partial: False
@@ -538,19 +538,15 @@
preserving rev for resolve of rev
a: remote is newer -> g
getting a
- b: both created -> m (premerge)
+ b: both renamed from a -> m (premerge)
picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
merging b
- my b@86a2aa42fc76+ other b@8dbce441892a ancestor b@000000000000
+ my b@86a2aa42fc76+ other b@8dbce441892a ancestor a@924404dff337
+ premerge successful
rev: versions differ -> m (premerge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
merging rev
my rev@86a2aa42fc76+ other rev@8dbce441892a ancestor rev@924404dff337
- b: both created -> m (merge)
- picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
- my b@86a2aa42fc76+ other b@8dbce441892a ancestor b@000000000000
- launching merge tool: * ../merge *$TESTTMP/t/t/b* * * (glob)
- merge tool returned: 0
rev: versions differ -> m (merge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
my rev@86a2aa42fc76+ other rev@8dbce441892a ancestor rev@924404dff337
@@ -611,7 +607,7 @@
--------------
all copies found (* = to merge, ! = divergent, % = renamed and deleted):
on local side:
- src: 'a' -> dst: 'b'
+ src: 'a' -> dst: 'b' *
checking for directory renames
resolving manifests
branchmerge: True, force: False, partial: False
@@ -620,19 +616,15 @@
preserving rev for resolve of rev
a: remote is newer -> g
getting a
- b: both created -> m (premerge)
+ b: both renamed from a -> m (premerge)
picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
merging b
- my b@86a2aa42fc76+ other b@8dbce441892a ancestor b@000000000000
+ my b@86a2aa42fc76+ other b@8dbce441892a ancestor a@924404dff337
+ premerge successful
rev: versions differ -> m (premerge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
merging rev
my rev@86a2aa42fc76+ other rev@8dbce441892a ancestor rev@924404dff337
- b: both created -> m (merge)
- picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
- my b@86a2aa42fc76+ other b@8dbce441892a ancestor b@000000000000
- launching merge tool: * ../merge *$TESTTMP/t/t/b* * * (glob)
- merge tool returned: 0
rev: versions differ -> m (merge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
my rev@86a2aa42fc76+ other rev@8dbce441892a ancestor rev@924404dff337
@@ -652,7 +644,7 @@
--------------
all copies found (* = to merge, ! = divergent, % = renamed and deleted):
on remote side:
- src: 'a' -> dst: 'b'
+ src: 'a' -> dst: 'b' *
checking for directory renames
resolving manifests
branchmerge: True, force: False, partial: False
@@ -660,19 +652,15 @@
preserving b for resolve of b
preserving rev for resolve of rev
starting 4 threads for background file closing (?)
- b: both created -> m (premerge)
+ b: both renamed from a -> m (premerge)
picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
merging b
- my b@0b76e65c8289+ other b@4ce40f5aca24 ancestor b@000000000000
+ my b@0b76e65c8289+ other b@4ce40f5aca24 ancestor a@924404dff337
+ premerge successful
rev: versions differ -> m (premerge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
merging rev
my rev@0b76e65c8289+ other rev@4ce40f5aca24 ancestor rev@924404dff337
- b: both created -> m (merge)
- picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
- my b@0b76e65c8289+ other b@4ce40f5aca24 ancestor b@000000000000
- launching merge tool: * ../merge *$TESTTMP/t/t/b* * * (glob)
- merge tool returned: 0
rev: versions differ -> m (merge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
my rev@0b76e65c8289+ other rev@4ce40f5aca24 ancestor rev@924404dff337
@@ -692,7 +680,7 @@
--------------
all copies found (* = to merge, ! = divergent, % = renamed and deleted):
on local side:
- src: 'a' -> dst: 'b'
+ src: 'a' -> dst: 'b' *
checking for directory renames
resolving manifests
branchmerge: True, force: False, partial: False
@@ -700,35 +688,24 @@
preserving b for resolve of b
preserving rev for resolve of rev
starting 4 threads for background file closing (?)
- a: prompt deleted/changed -> m (premerge)
- picked tool ':prompt' for a (binary False symlink False changedelete True)
- file 'a' was deleted in local [working copy] but was modified in other [merge rev].
- You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved.
- What do you want to do? u
- b: both created -> m (premerge)
+ b: both renamed from a -> m (premerge)
picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
merging b
- my b@02963e448370+ other b@8dbce441892a ancestor b@000000000000
+ my b@02963e448370+ other b@8dbce441892a ancestor a@924404dff337
+ premerge successful
rev: versions differ -> m (premerge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
merging rev
my rev@02963e448370+ other rev@8dbce441892a ancestor rev@924404dff337
- b: both created -> m (merge)
- picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
- my b@02963e448370+ other b@8dbce441892a ancestor b@000000000000
- launching merge tool: * ../merge *$TESTTMP/t/t/b* * * (glob)
- merge tool returned: 0
rev: versions differ -> m (merge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
my rev@02963e448370+ other rev@8dbce441892a ancestor rev@924404dff337
launching merge tool: * ../merge *$TESTTMP/t/t/rev* * * (glob)
merge tool returned: 0
- 0 files updated, 2 files merged, 0 files removed, 1 files unresolved
- use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
+ 0 files updated, 2 files merged, 0 files removed, 0 files unresolved
+ (branch merge, don't forget to commit)
--------------
- M a
M b
- abort: unresolved merge conflicts (see 'hg help resolve')
--------------
$ tm "up a b" "nm a b" " " "19 merge b no ancestor, prompt remove a"
@@ -738,44 +715,33 @@
--------------
all copies found (* = to merge, ! = divergent, % = renamed and deleted):
on remote side:
- src: 'a' -> dst: 'b'
+ src: 'a' -> dst: 'b' *
checking for directory renames
resolving manifests
branchmerge: True, force: False, partial: False
ancestor: 924404dff337, local: 0b76e65c8289+, remote: bdb19105162a
- preserving a for resolve of a
preserving b for resolve of b
preserving rev for resolve of rev
+ b: both renamed from a -> m (premerge)
starting 4 threads for background file closing (?)
- a: prompt changed/deleted -> m (premerge)
- picked tool ':prompt' for a (binary False symlink False changedelete True)
- file 'a' was deleted in other [merge rev] but was modified in local [working copy].
- You can use (c)hanged version, (d)elete, or leave (u)nresolved.
- What do you want to do? u
- b: both created -> m (premerge)
picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
merging b
- my b@0b76e65c8289+ other b@bdb19105162a ancestor b@000000000000
+ my b@0b76e65c8289+ other b@bdb19105162a ancestor a@924404dff337
+ premerge successful
rev: versions differ -> m (premerge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
merging rev
my rev@0b76e65c8289+ other rev@bdb19105162a ancestor rev@924404dff337
- b: both created -> m (merge)
- picked tool '* ../merge' for b (binary False symlink False changedelete False) (glob)
- my b@0b76e65c8289+ other b@bdb19105162a ancestor b@000000000000
- launching merge tool: * ../merge *$TESTTMP/t/t/b* * * (glob)
- merge tool returned: 0
rev: versions differ -> m (merge)
picked tool '* ../merge' for rev (binary False symlink False changedelete False) (glob)
my rev@0b76e65c8289+ other rev@bdb19105162a ancestor rev@924404dff337
launching merge tool: * ../merge *$TESTTMP/t/t/rev* * * (glob)
merge tool returned: 0
- 0 files updated, 2 files merged, 0 files removed, 1 files unresolved
- use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
+ 0 files updated, 2 files merged, 0 files removed, 0 files unresolved
+ (branch merge, don't forget to commit)
--------------
M b
C a
- abort: unresolved merge conflicts (see 'hg help resolve')
--------------
$ tm "up a " "um a b" " " "20 merge a and b to b, remove a"