evolve: create a new commit instead of amending one of the divergents
This patch changes the behavior of evolve command while resolving
content-divergence to create a new commit instead of amending one of the
divergent ones.
In past, I have made this change, backed out this change and now today again I
am doing this change, so let's dive in some history.
Using cmdrewrite.amend() was never a good option as that requires hack to delete
the evolvestate and also gives us less control over things. We can't make the
commit on top of different parents as that of content-divergent ones. Due to all
these, I first made this change to create a new commit instead of amending one.
But, after few days, there was flakiness observed in the tests and turned out
that we need to do some dirstate dance as repo.dirstate.setparents() does not
always fix the dirstate. That flakiness was a blocker for progress at that time
and we decided to switch to amend back so that we can have things working with
some hacks and we can later fix the implementation part.
Now, yesterday while tackling resolving content-divergence of a stack which is
as follows:
C1 C2
| |
B1 B2
| |
A1 A2
\/
base
where, A1-A2, B1-B2, C1-C2 are content-divergent with each other. Now we can
resolve A1-A2 very well because they have the same parent and let's say that
resolution leads to A3.
Now, we want to resolve B1-B2 and make the new resolution commit on top of A3 so
that we can end up something like:
C3
|
B3
|
A3
|
base
however, amending one of the divergent changesets, it's not possible to create a
commit on a different parent like A3 here without some relocation. We should
prevent relocation as that may leads to some conflicts and should change the
parent before committing.
So, looking ahead, we can't move with using amend as still using that we will
need some relocation hacks making code ugly and prone to bad behaviors, bugs.
Let's change back to creating a new commit so that we can move forward in a good
way.
About repo.dirstate.setparents() not setting the dirstate, I have researched
yesterday night about how we can do that and found out that we can use
cmdrewrite._uncommitdirstate() here. Expect upcoming patches to improve the
documentation of that function.
There are lot of test changes because of change in hash but there is no behavior
change. The only behavior change is in test-evolve-abort-contentdiv.t which is
nice because creating a new commit helps us in stripping that while aborting.
We have a lot of testing of content-divergence and no behavior change gives
enough confidence for making this change.
I reviewed the patch carefully to make sure there is no behavior change and I
suggest reviewer to do the same.
$ cat >> $HGRCPATH <<EOF
> [extensions]
> EOF
$ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
$ glog() {
> hg log -G --template '{rev}:{node|short}@{branch}({separate("/", obsolete, phase)}) {desc|firstline}\n' "$@"
> }
$ hg init repo
$ cd repo
Cannot uncommit null changeset
$ hg uncommit
abort: cannot uncommit the null revision
(no changeset checked out)
[255]
Cannot uncommit public changeset
$ echo a > a
$ hg ci -Am adda a
$ hg phase --public .
$ hg uncommit
abort: cannot uncommit public changesets: 07f494440405
(see 'hg help phases' for details)
[255]
$ hg phase --force --draft .
Cannot uncommit merge
$ hg up -q null
$ echo b > b
$ echo c > c
$ echo d > d
$ echo f > f
$ echo g > g
$ echo j > j
$ echo m > m
$ echo n > n
$ echo o > o
$ hg ci -Am addmore
adding b
adding c
adding d
adding f
adding g
adding j
adding m
adding n
adding o
created new head
$ hg merge
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
$ hg uncommit
abort: cannot uncommit while merging
[255]
$ hg ci -m merge
$ hg uncommit
abort: cannot uncommit merge changeset
[255]
Prepare complicated changeset
$ hg branch bar
marked working directory as branch bar
(branches are permanent and global, did you want a bookmark?)
$ hg cp a aa
$ echo b >> b
$ hg rm c
$ echo d >> d
$ echo e > e
$ hg mv f ff
$ hg mv g h
$ echo j >> j
$ echo k > k
$ echo l > l
$ hg rm m
$ hg rm n
$ echo o >> o
$ hg ci -Am touncommit
adding e
adding k
adding l
$ hg st --copies --change .
M b
M d
M j
M o
A aa
a
A e
A ff
f
A h
g
A k
A l
R c
R f
R g
R m
R n
$ hg man -r .
a
aa
b
d
e
ff
h
j
k
l
o
Add a couple of bookmarks
$ glog --hidden
@ 3:5eb72dbe0cb4@bar(draft) touncommit
|
o 2:f63b90038565@default(draft) merge
|\
| o 1:f15c744d48e8@default(draft) addmore
|
o 0:07f494440405@default(draft) adda
$ hg bookmark -r 2 unrelated
$ hg bookmark touncommit-bm
$ hg bookmark --inactive touncommit-bm-inactive
$ hg bookmarks
* touncommit-bm 3:5eb72dbe0cb4
touncommit-bm-inactive 3:5eb72dbe0cb4
unrelated 2:f63b90038565
Prepare complicated working directory
$ hg branch foo
marked working directory as branch foo
$ hg mv ff f
$ hg mv h i
$ hg rm j
$ hg rm k
$ echo l >> l
$ echo m > m
$ echo o > o
Test uncommit without argument, should be a no-op
$ hg uncommit
abort: nothing to uncommit
(use --all to uncommit all files)
[255]
$ hg bookmarks
* touncommit-bm 3:5eb72dbe0cb4
touncommit-bm-inactive 3:5eb72dbe0cb4
unrelated 2:f63b90038565
Test no matches
$ hg uncommit --include nothere
abort: nothing to uncommit
(use --all to uncommit all files)
[255]
Enjoy uncommit
$ hg uncommit aa b c f ff g h j k l m o
$ hg branch
foo
$ hg st --copies
M b
A aa
a
A i
g
A l
R c
R g
R j
R m
$ cat aa
a
$ cat b
b
b
$ cat l
l
l
$ cat m
m
$ test -f c && echo 'error: c was removed!'
[1]
$ test -f j && echo 'error: j was removed!'
[1]
$ test -f k && echo 'error: k was removed!'
[1]
$ hg st --copies --change .
M d
A e
R n
$ hg man -r .
a
b
c
d
e
f
g
j
m
o
$ hg cat -r . d
d
d
$ hg cat -r . e
e
$ glog --hidden
@ 4:e8db4aa611f6@bar(draft) touncommit
|
| x 3:5eb72dbe0cb4@bar(obsolete/draft) touncommit
|/
o 2:f63b90038565@default(draft) merge
|\
| o 1:f15c744d48e8@default(draft) addmore
|
o 0:07f494440405@default(draft) adda
$ hg bookmarks
* touncommit-bm 4:e8db4aa611f6
touncommit-bm-inactive 4:e8db4aa611f6
unrelated 2:f63b90038565
$ hg debugobsolete
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 e8db4aa611f6d5706374288e6898e498f5c44098 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
Test phase is preserved, no local changes
$ hg up -C 3 --hidden
8 files updated, 0 files merged, 1 files removed, 0 files unresolved
(leaving bookmark touncommit-bm)
updated to hidden changeset 5eb72dbe0cb4
(hidden revision '5eb72dbe0cb4' was rewritten as: e8db4aa611f6)
working directory parent is obsolete! (5eb72dbe0cb4)
(use 'hg evolve' to update to its successor: e8db4aa611f6)
$ hg --config extensions.purge= purge
$ hg uncommit -I 'set:added() and e'
2 new content-divergent changesets
$ hg st --copies
A e
$ hg st --copies --change .
M b
M d
M j
M o
A aa
a
A ff
f
A h
g
A k
A l
R c
R f
R g
R m
R n
$ glog --hidden
@ 5:a1d4c1ad76cc@bar(draft) touncommit
|
| * 4:e8db4aa611f6@bar(draft) touncommit
|/
| x 3:5eb72dbe0cb4@bar(obsolete/draft) touncommit
|/
o 2:f63b90038565@default(draft) merge
|\
| o 1:f15c744d48e8@default(draft) addmore
|
o 0:07f494440405@default(draft) adda
$ hg debugobsolete
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 e8db4aa611f6d5706374288e6898e498f5c44098 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 a1d4c1ad76cc7eb5e8a36ef52396da334b6d59c5 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
Test --all
$ hg up -C 3 --hidden
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
updated to hidden changeset 5eb72dbe0cb4
(hidden revision '5eb72dbe0cb4' has diverged)
working directory parent is obsolete! (5eb72dbe0cb4)
(5eb72dbe0cb4 has diverged, use 'hg evolve --list --content-divergent' to resolve the issue)
$ hg --config extensions.purge= purge
$ hg uncommit --all -X e
1 new content-divergent changesets
$ hg st --copies
M b
M d
M j
M o
A aa
a
A ff
f
A h
g
A k
A l
R c
R f
R g
R m
R n
$ hg st --copies --change .
A e
$ hg debugobsolete
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 e8db4aa611f6d5706374288e6898e498f5c44098 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 a1d4c1ad76cc7eb5e8a36ef52396da334b6d59c5 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 c4cbebac3751269bdf12d1466deabcc78521d272 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
Display a warning if nothing left
$ hg uncommit e
new changeset is empty
(use 'hg prune .' to remove it)
$ hg debugobsolete
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 e8db4aa611f6d5706374288e6898e498f5c44098 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 a1d4c1ad76cc7eb5e8a36ef52396da334b6d59c5 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
5eb72dbe0cb409d094e3b4ae8eaa30071c1b8730 c4cbebac3751269bdf12d1466deabcc78521d272 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
c4cbebac3751269bdf12d1466deabcc78521d272 4f1c269eab68720f54e88ce3c1dc02b2858b6b89 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'operation': 'uncommit', 'user': 'test'}
Test instability warning
$ hg ci -m touncommit
$ echo unrelated > unrelated
$ hg ci -Am addunrelated unrelated
$ hg previous
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
[8] touncommit
$ hg uncommit aa
1 new orphan changesets
Test uncommiting agains a different base
$ hg cat b --rev .
b
b
$ hg cat b --rev .^
b
$ hg cat b --rev 0
b: no such file in rev 07f494440405
[1]
$ hg uncommit --rev . b
abort: cannot uncommit to parent changeset
[255]
$ hg uncommit --rev 0 b
$ hg cat b --rev .
b: no such file in rev 5b27f6b17da2
[1]
Test uncommiting precursors
$ hg uncommit --hidden --rev 'precursors(.)' b --traceback
$ hg cat b --rev .
b
b
Test date, message and user update
$ hg log -r .
changeset: 12:912ed871207c
branch: bar
tag: tip
parent: 7:4f1c269eab68
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: touncommit
$ hg uncommit -m 'to-uncommit' d --user test2 --date '1337 0'
$ hg log -r .
changeset: 13:f1efd9ec508c
branch: bar
tag: tip
parent: 7:4f1c269eab68
user: test2
date: Thu Jan 01 00:22:17 1970 +0000
summary: to-uncommit
test -U option
$ hg uncommit -U b
$ hg log -r .
changeset: 14:288da4a95941
branch: bar
tag: tip
parent: 7:4f1c269eab68
user: test
date: Thu Jan 01 00:22:17 1970 +0000
summary: to-uncommit
test the `hg amend --extract` entry point
$ hg status --change .
M j
M o
A e
A ff
A h
A k
A l
R c
R f
R g
R m
R n
$ hg status
M d
A aa
R b
$ hg amend --extract j
$ hg status --change .
M o
A e
A ff
A h
A k
A l
R c
R f
R g
R m
R n
$ hg status
M d
M j
A aa
R b
(with all)
$ hg amend --extract --all
new changeset is empty
(use 'hg prune .' to remove it)
$ hg status --change .
$ hg status
M d
M j
M o
A aa
A e
A ff
A h
A k
A l
R b
R c
R f
R g
R m
R n
Testing the --revert flag of `hg uncommit`
When working directory before uncommit is clean
$ hg amend
$ hg status
? b
$ hg diff -c . --stat
aa | 1 +
b | 1 -
c | 1 -
d | 1 +
e | 1 +
f | 1 -
ff | 1 +
g | 1 -
h | 1 +
j | 1 +
k | 1 +
l | 1 +
m | 1 -
n | 1 -
o | 1 +
15 files changed, 9 insertions(+), 6 deletions(-)
$ hg uncommit --revert --all
new changeset is empty
(use 'hg prune .' to remove it)
$ hg status
When working directory is dirty before uncommit
$ echo foo > a
$ echo foo > b
$ echo foo > c
$ hg status
M a
M b
M c
$ hg amend
$ echo foo > foo
$ hg add foo
$ hg status
A foo
$ hg uncommit --revert --all
new changeset is empty
(use 'hg prune .' to remove it)
$ hg status
? foo