evolve: make sure divergence resolution doesn't undo changes (issue6203)
Before this patch, in content-divergence resolution logic if resolution
parent is not the parent of any of the two divergent changesets then
it could undo some changes introduced by previous revs (while resolving
stack of content-divergent changesets) as demonstrated by the test added in
previous patch.
To solve this, what this patch doing is: if divergent cset has obsolete
parent with a successor then first resolve the "orphan" instability of
divergent cset by relocating, then perform the content-divergence resolution.
After this change in logic, I found that it's kind of more correct as
reflected by the changes in tests/test-evolve-content-divergent-corner-cases.t
where it prevented creating conflicts while merging.
Changes in tests/test-evolve-content-divergent-stack.t demonstrate the fixed
behaviour.
Next patches will be covering the `evolve --continue` case for the relocation
of "divergent" cset.
--- a/hgext3rd/evolve/evolvecmd.py Sat Nov 23 20:25:16 2019 +0530
+++ b/hgext3rd/evolve/evolvecmd.py Sat Nov 23 16:17:04 2019 +0530
@@ -501,6 +501,21 @@
% divergent))
return (False, b".")
+ try:
+ succsdivp1 = utility._singlesuccessor(repo, divergent.p1())
+ except utility.MultipleSuccessorsError:
+ succsdivp1 = divergent.p1().rev()
+ # relocate divergent cset to its obsolete parent's successsor
+ if succsdivp1 != divergent.p1().rev():
+ ui.status(_(b'rebasing "divergent" content-divergent changeset %s on'
+ b' %s\n' % (divergent, repo[succsdivp1])))
+ with state.saver(evolvestate, {b'current': divergent.node()}):
+ newdivergent = relocate(repo, divergent, repo[succsdivp1],
+ evolvestate, keepbranch=True)
+ divergent = repo[newdivergent]
+ evolvestate[b'temprevs'].append(divergent.node())
+ evolvestate[b'divergent'] = divergent.node()
+
# Sometimes we already have the other cset where we want it
if relocatereq and other == divergent.p1():
relocatereq = False
--- a/tests/test-evolve-content-divergent-corner-cases.t Sat Nov 23 20:25:16 2019 +0530
+++ b/tests/test-evolve-content-divergent-corner-cases.t Sat Nov 23 16:17:04 2019 +0530
@@ -270,45 +270,22 @@
o 0:9092f1db7931 added a
() [default] draft
- $ hg evolve --content-divergent --any --update
+ $ hg evolve --content-divergent --any --update --config ui.interactive=true <<EOF
+ > c
+ > EOF
merge:[5] updated e
with: [6] updated e
base: [4] added e
- rebasing "other" content-divergent changeset de4ea3103326 on 9150fe93bec6
- merging d
- warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
- unresolved merge conflicts
- (see 'hg help evolve.interrupted')
- [1]
-
- $ hg diff --no-git --config diff.unified=3
- diff -r 9150fe93bec6 d
- --- a/d Thu Jan 01 00:00:00 1970 +0000
- +++ b/d Thu Jan 01 00:00:00 1970 +0000
- @@ -1,1 +1,5 @@
- +<<<<<<< destination: 9150fe93bec6 - test: added d
- d
- +=======
- +dd
- +>>>>>>> evolving: de4ea3103326 - test: updated e
- diff -r 9150fe93bec6 e
- --- /dev/null Thu Jan 01 00:00:00 1970 +0000
- +++ b/e Thu Jan 01 00:00:00 1970 +0000
- @@ -0,0 +1,1 @@
- +ee
-
- $ echo dresolved > d
- $ hg res -m
- (no more unresolved files)
- continue: hg evolve --continue
-
- $ hg evolve --continue
- evolving 6:de4ea3103326 "updated e"
- 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
- working directory is now at 83b1664a580f
+ rebasing "divergent" content-divergent changeset ff6f7cd76a7c on 155349b645be
+ rebasing "other" content-divergent changeset de4ea3103326 on 155349b645be
+ file 'd' was deleted in local but was modified in other.
+ You can use (c)hanged version, leave (d)eleted, or leave (u)nresolved.
+ What do you want to do? c
+ 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+ working directory is now at eb6357cd41b6
$ hg glog -l1
- @ 8:83b1664a580f updated e
+ @ 9:eb6357cd41b6 updated e
| () [default] draft
~
--- a/tests/test-evolve-content-divergent-interrupted.t Sat Nov 23 20:25:16 2019 +0530
+++ b/tests/test-evolve-content-divergent-interrupted.t Sat Nov 23 16:17:04 2019 +0530
@@ -195,6 +195,7 @@
merge:[5] added d
with: [7] added d
base: [4] added d
+ rebasing "divergent" content-divergent changeset e49523854bc8 on ddcf04e1458c
merging d
warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
0 files updated, 0 files merged, 0 files removed, 1 files unresolved
@@ -203,6 +204,7 @@
[1]
$ hg evolve --abort
+ 1 new orphan changesets
2 new content-divergent changesets
evolve aborted
working directory is now at 491e10505bae
--- a/tests/test-evolve-content-divergent-stack.t Sat Nov 23 20:25:16 2019 +0530
+++ b/tests/test-evolve-content-divergent-stack.t Sat Nov 23 16:17:04 2019 +0530
@@ -147,23 +147,26 @@
merge:[6] added b
with: [10] added b
base: [2] added b
+ rebasing "divergent" content-divergent changeset d5f148423c16 on f66f262fff6c
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
merge:[7] added c
with: [11] added c
base: [3] added c
+ rebasing "divergent" content-divergent changeset 3ce4be6d8e5e on eadfd9d70680
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
merge:[8] added d
with: [12] added d
base: [4] added d
+ rebasing "divergent" content-divergent changeset c72d2885eb51 on b2cac10f3836
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
working directory is now at f66f262fff6c
$ hg glog
- o 16:038fe7db3d88 added d
+ o 19:038fe7db3d88 added d
| () [default] draft
- o 15:b2cac10f3836 added c
+ o 17:b2cac10f3836 added c
| () [default] draft
- o 14:eadfd9d70680 added b
+ o 15:eadfd9d70680 added b
| () [default] draft
@ 13:f66f262fff6c watbar to a
| () [default] draft
@@ -315,26 +318,29 @@
merge:[11] added b
with: [6] added b
base: [2] added b
- rebasing "other" content-divergent changeset d5f148423c16 on c04ff147ef79
+ rebasing "divergent" content-divergent changeset 6eb54b5af3fb on 74fbf3e6a0b6
+ rebasing "other" content-divergent changeset d5f148423c16 on 74fbf3e6a0b6
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
merge:[12] added c
with: [7] added c
base: [3] added c
- rebasing "other" content-divergent changeset 3ce4be6d8e5e on 6eb54b5af3fb
+ rebasing "divergent" content-divergent changeset 8ed612937375 on 4e29776e83a5
+ rebasing "other" content-divergent changeset 3ce4be6d8e5e on 4e29776e83a5
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
merge:[13] added d
with: [8] added d
base: [4] added d
- rebasing "other" content-divergent changeset c72d2885eb51 on 8ed612937375
+ rebasing "divergent" content-divergent changeset d45f050514c2 on 77126af93a25
+ rebasing "other" content-divergent changeset c72d2885eb51 on 77126af93a25
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
working directory is now at 74fbf3e6a0b6
$ hg glog
- o 21:5f7a38bdb75c added d
+ o 24:c8f73c376a6e added d
| () [default] draft
- o 19:9865d598f0e0 added c
+ o 21:77126af93a25 added c
| () [default] draft
- o 17:ac70b8c8eb63 added b
+ o 18:4e29776e83a5 added b
| () [default] draft
@ 15:74fbf3e6a0b6 watbar to a
| () [default] draft
@@ -473,25 +479,17 @@
merge:[7] c
with: [4] c
base: [2] c
- rebasing "other" content-divergent changeset fef59171875e on fe788ccf5416
+ rebasing "divergent" content-divergent changeset ef4885dea3da on 0999c349998d
+ rebasing "other" content-divergent changeset fef59171875e on 0999c349998d
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
Expected result:
Changeset with description "b" only adds file "b" with content "b without typo".
Changeset with description "c" only adds file "c" with content "c".
-Actual result:
-In addition, changeset with description "c" also changes the content of file
-"b" from "b without typo" to "b with typo" (undoing the changes introduced by the amend).
$ hg glog -l2 -p
- o 11:344b9ba79c10 c
- | () [default] draftdiff -r 0999c349998d -r 344b9ba79c10 b
- | --- a/b Thu Jan 01 00:00:00 1970 +0000
- | +++ b/b Thu Jan 01 00:00:00 1970 +0000
- | @@ -1,1 +1,1 @@
- | -b without typo
- | +b with typo
- | diff -r 0999c349998d -r 344b9ba79c10 c
+ o 12:4ca627f76da9 c
+ | () [default] draftdiff -r 0999c349998d -r 4ca627f76da9 c
| --- /dev/null Thu Jan 01 00:00:00 1970 +0000
| +++ b/c Thu Jan 01 00:00:00 1970 +0000
| @@ -0,0 +1,1 @@