rebase: skip resolved but emptied revisions
When rebasing, if a conflict occurs and is resolved in a way the rebased
revision becomes empty, it is not skipped, unlike revisions being emptied
without conflicts.
The reason is:
- File 'x' is merged and resolved, merge.update() marks it as 'm' in the
dirstate.
- rebase.concludenode() calls localrepo.commit(), which calls
localrepo.status() which calls dirstate.status(). 'x' shows up as 'm' and is
unconditionnally added to the modified files list, instead of being checked
again.
- localrepo.commit() detects 'x' as changed an create a new revision where only
the manifest parents and linkrev differ.
Marking 'x' as modified without checking it makes sense for regular merges. But
in rebase case, the merge looks normal but the second parent is usually
discarded. When this happens, 'm' files in dirstate are a bit irrelevant and
should be considered 'n' possibly dirty instead. That is what the current patch
does.
Another approach, maybe more efficient, would be to pass another flag to
merge.update() saying the 'branchmerge' is a bit of a lie and recordupdate()
should call dirstate.normallookup() instead of merge().
It is also tempting to add this logic to dirstate.setparents(), moving from two
to one parent is what invalidates the 'm' markers. But this is a far bigger
change to make.
v2: succumb to the temptation and move the logic in dirstate.setparents(). mpm
suggested trying _filecommit() first but it is called by commitctx() which
knows nothing about the dirstate and comes too late into the game. A second
approach was to rewrite the 'm' state into 'n' on the fly in dirstate.status()
which failed for graft in the following case:
$ hg init repo
$ cd repo
$ echo a > a
$ hg ci -qAm0
$ echo a >> a
$ hg ci -m1
$ hg up 0
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg mv a b
$ echo c > b
$ hg ci -m2
created new head
$ hg graft 1 --tool internal:local
grafting revision 1
$ hg --config extensions.graphlog= glog --template '{rev} {desc|firstline}\n'
@ 3 1
|
o 2 2
|
| o 1 1
|/
o 0 0
$ hg log -r 3 --debug --patch --git --copies
changeset: 3:19cd7d1417952af13161b94c32e901769104560c
tag: tip
phase: draft
parent: 2:b5c505595c9e9a12d5dd457919c143e05fc16fb8
parent: -1:0000000000000000000000000000000000000000
manifest: 3:3d27ce8d02241aa59b60804805edf103c5c0cda4
user: test
date: Thu Jan 01 00:00:00 1970 +0000
extra: branch=default
extra: source=a03df74c41413a75c0a42997fc36c2de97b26658
description:
1
Here, revision 3 is created because there is a copy record for 'b' in the
dirstate and thus 'b' is considered modified. But this information is discarded
at commit time since 'b' content is unchanged. I do not know if discarding this
information is correct or not, but at this time we cannot represent it anyway.
This patch therefore implements the last solution of moving the logic into
dirstate.setparents(). It does not sound crazy as 'm' files makes no sense with
only one parent. It also makes dirstate.merge() calls .lookupnormal() if there
is one parent, to preserve the invariant.
I am a bit concerned about introducing this kind of stateful behaviour to
existing code which historically treated setparents() as a basic setter without
side-effects. And doing that during the code freeze.
$ cat >> $HGRCPATH <<EOF
> [extensions]
> graphlog=
> rebase=
>
> [phases]
> publish=False
>
> [alias]
> tglog = log -G --template "{rev}: '{desc}' {branches}\n"
> EOF
$ hg init a
$ cd a
$ hg unbundle "$TESTDIR/bundles/rebase.hg"
adding changesets
adding manifests
adding file changes
added 8 changesets with 7 changes to 7 files (+2 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)
$ hg up tip
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd ..
Rebasing D onto H detaching from C:
$ hg clone -q -u . a a1
$ cd a1
$ hg tglog
@ 7: 'H'
|
| o 6: 'G'
|/|
o | 5: 'F'
| |
| o 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ hg phase --force --secret 3
$ hg rebase --detach -s 3 -d 7
saved backup bundle to $TESTTMP/a1/.hg/strip-backup/*-backup.hg (glob)
$ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n"
@ 7:secret 'D'
|
o 6:draft 'H'
|
| o 5:draft 'G'
|/|
o | 4:draft 'F'
| |
| o 3:draft 'E'
|/
| o 2:draft 'C'
| |
| o 1:draft 'B'
|/
o 0:draft 'A'
$ hg manifest
A
D
F
H
$ cd ..
Rebasing C onto H detaching from B:
$ hg clone -q -u . a a2
$ cd a2
$ hg tglog
@ 7: 'H'
|
| o 6: 'G'
|/|
o | 5: 'F'
| |
| o 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ hg rebase --detach -s 2 -d 7
saved backup bundle to $TESTTMP/a2/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
@ 7: 'D'
|
o 6: 'C'
|
o 5: 'H'
|
| o 4: 'G'
|/|
o | 3: 'F'
| |
| o 2: 'E'
|/
| o 1: 'B'
|/
o 0: 'A'
$ hg manifest
A
C
D
F
H
$ cd ..
Rebasing B onto H using detach (same as not using it):
$ hg clone -q -u . a a3
$ cd a3
$ hg tglog
@ 7: 'H'
|
| o 6: 'G'
|/|
o | 5: 'F'
| |
| o 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ hg rebase --detach -s 1 -d 7
saved backup bundle to $TESTTMP/a3/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
@ 7: 'D'
|
o 6: 'C'
|
o 5: 'B'
|
o 4: 'H'
|
| o 3: 'G'
|/|
o | 2: 'F'
| |
| o 1: 'E'
|/
o 0: 'A'
$ hg manifest
A
B
C
D
F
H
$ cd ..
Rebasing C onto H detaching from B and collapsing:
$ hg clone -q -u . a a4
$ cd a4
$ hg phase --force --secret 3
$ hg tglog
@ 7: 'H'
|
| o 6: 'G'
|/|
o | 5: 'F'
| |
| o 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ hg rebase --detach --collapse -s 2 -d 7
saved backup bundle to $TESTTMP/a4/.hg/strip-backup/*-backup.hg (glob)
$ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n"
@ 6:secret 'Collapsed revision
| * C
| * D'
o 5:draft 'H'
|
| o 4:draft 'G'
|/|
o | 3:draft 'F'
| |
| o 2:draft 'E'
|/
| o 1:draft 'B'
|/
o 0:draft 'A'
$ hg manifest
A
C
D
F
H
$ cd ..
Rebasing across null as ancestor
$ hg clone -q -U a a5
$ cd a5
$ echo x > x
$ hg add x
$ hg ci -m "extra branch"
created new head
$ hg tglog
@ 8: 'extra branch'
o 7: 'H'
|
| o 6: 'G'
|/|
o | 5: 'F'
| |
| o 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ hg rebase --detach -s 1 -d tip
saved backup bundle to $TESTTMP/a5/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
@ 8: 'D'
|
o 7: 'C'
|
o 6: 'B'
|
o 5: 'extra branch'
o 4: 'H'
|
| o 3: 'G'
|/|
o | 2: 'F'
| |
| o 1: 'E'
|/
o 0: 'A'
$ hg rebase -d 5 -s 7
saved backup bundle to $TESTTMP/a5/.hg/strip-backup/13547172c9c0-backup.hg (glob)
$ hg tglog
@ 8: 'D'
|
o 7: 'C'
|
| o 6: 'B'
|/
o 5: 'extra branch'
o 4: 'H'
|
| o 3: 'G'
|/|
o | 2: 'F'
| |
| o 1: 'E'
|/
o 0: 'A'
$ cd ..
Verify that target is not selected as external rev (issue3085)
$ hg clone -q -U a a6
$ cd a6
$ hg up -q 6
$ echo "I" >> E
$ hg ci -m "I"
$ hg merge 7
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
$ hg ci -m "Merge"
$ echo "J" >> F
$ hg ci -m "J"
$ hg rebase -s 8 -d 7 --collapse --detach --config ui.merge=internal:other
remote changed E which local deleted
use (c)hanged version or leave (d)eleted? c
saved backup bundle to $TESTTMP/a6/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
@ 8: 'Collapsed revision
| * I
| * Merge
| * J'
o 7: 'H'
|
| o 6: 'G'
|/|
o | 5: 'F'
| |
| o 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ hg parents
changeset: 8:9472f4b1d736
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Collapsed revision
$ cd ..
Ensure --continue restores a correct state (issue3046) and phase:
$ hg clone -q a a7
$ cd a7
$ hg up -q 3
$ echo 'H2' > H
$ hg ci -A -m 'H2'
adding H
$ hg phase --force --secret 8
$ hg rebase -s 8 -d 7 --detach --config ui.merge=internal:fail
merging H
warning: conflicts during merge.
merging H incomplete! (edit conflicts, then use 'hg resolve --mark')
abort: unresolved conflicts (see hg resolve, then hg rebase --continue)
[255]
$ hg resolve --all -t internal:local
$ hg rebase -c
saved backup bundle to $TESTTMP/a7/.hg/strip-backup/6215fafa5447-backup.hg (glob)
$ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n"
@ 7:draft 'H'
|
| o 6:draft 'G'
|/|
o | 5:draft 'F'
| |
| o 4:draft 'E'
|/
| o 3:draft 'D'
| |
| o 2:draft 'C'
| |
| o 1:draft 'B'
|/
o 0:draft 'A'