[PATCH 1 of 2] rebase: fix phases movement
Matt Mackall
mpm at selenic.com
Tue Jan 17 12:38:03 CST 2012
On Tue, 2012-01-17 at 15:35 +0100, alain.leufroy at logilab.fr wrote:
> # HG changeset patch
> # User Alain Leufroy <alain.leufroyATgmailMYDOTcom>
> # Date 1326787934 -3600
> # Node ID 345cdd7b28c1cc042d76e2f1a5aec5a5afc8e793
> # Parent 476a981fdf341f5bedbd958ca6c8e930fe35b5f9
> rebase: fix phases movement
>
> Rebase now try to keep the phases of source changesets.
>
> diff -r 476a981fdf34 -r 345cdd7b28c1 hgext/rebase.py
> --- a/hgext/rebase.py Mon Jan 16 01:21:30 2012 -0600
> +++ b/hgext/rebase.py Tue Jan 17 09:12:14 2012 +0100
> @@ -21,6 +21,7 @@
> from mercurial.lock import release
> from mercurial.i18n import _
> import os, errno
> +import mercurial.phases as phases
Please group imports: mercurial imports before library imports.
> nullmerge = -2
>
> @@ -51,7 +52,7 @@
> 'branch')),
> ('t', 'tool', '', _('specify merge tool')),
> ('c', 'continue', False, _('continue an interrupted rebase')),
> - ('a', 'abort', False, _('abort an interrupted rebase'))] +
> + ('a', 'abort', False, _('abort an interrupted rebase (do not backup phase)'))] +
Not the place to document this sort of detail.
> templateopts,
> _('hg rebase [-s REV | -b REV] [-d REV] [options]\n'
> 'hg rebase {-a|-c}'))
> @@ -372,6 +373,9 @@
> newrev = repo.commit(text=commitmsg, user=ctx.user(),
> date=ctx.date(), extra=extra, editor=editor)
> repo.dirstate.setbranch(repo[newrev].branch())
> + targetphase = max(ctx.phase(), phases.draft)
> + # retractboundary doesn't overright upper phase inherited from parent
overwrite
> + phases.retractboundary(repo, targetphase, (repo[newrev].node(),))
(x,) is one of the ugliest things in Python, how about just [x]?
> return newrev
> except util.Abort:
> # Invalidate the previous setparents
> @@ -548,21 +552,25 @@
>
> def abort(repo, originalwd, target, state):
> 'Restore the repository to its original state'
> - if set(repo.changelog.descendants(target)) - set(state.values()):
> + descendants = repo.changelog.descendants
> + if any(repo._phaserev[r] == phases.public for r in descendants(target)):
> + repo.ui.warn("warning: immutable rebased changeset detected, "
> + "can't abort\n")
> + return -1
> + if set(descendants(target)) - set(state.values()):
> repo.ui.warn(_("warning: new changesets detected on target branch, "
> - "can't abort\n"))
> + "can't abort\n"))
Bad patch hygiene. This indent change has nothing to do with $SUBJECT.
> return -1
> - else:
> - # Strip from the first rebased revision
> - merge.update(repo, repo[originalwd].rev(), False, True, False)
> - rebased = filter(lambda x: x > -1 and x != target, state.values())
> - if rebased:
> - strippoint = min(rebased)
> - # no backup of rebased cset versions needed
> - repair.strip(repo.ui, repo, repo[strippoint].node())
> - clearstatus(repo)
> - repo.ui.warn(_('rebase aborted\n'))
> - return 0
> + # Strip from the first rebased revision
> + merge.update(repo, repo[originalwd].rev(), False, True, False)
> + rebased = filter(lambda x: x > -1 and x != target, state.values())
> + if rebased:
> + strippoint = min(rebased)
> + # no backup of rebased cset versions needed
> + repair.strip(repo.ui, repo, repo[strippoint].node())
> + clearstatus(repo)
> + repo.ui.warn(_('rebase aborted\n'))
> + return 0
More bad patch hygiene. I spent most of my time reviewing this patch
trying to figure out what this had to do with $SUBJECT. Answer: nothing
at all.
> def buildstate(repo, dest, rebaseset, detach):
> '''Define which revisions are going to be rebased and where
> diff -r 476a981fdf34 -r 345cdd7b28c1 tests/test-rebase-abort.t
> --- a/tests/test-rebase-abort.t Mon Jan 16 01:21:30 2012 -0600
> +++ b/tests/test-rebase-abort.t Tue Jan 17 09:12:14 2012 +0100
> @@ -7,7 +7,7 @@
> > publish=False
> >
> > [alias]
> - > tglog = log -G --template "{rev}: '{desc}' {branches}\n"
> + > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
> > EOF
>
>
> @@ -35,16 +35,18 @@
> $ mv common.new common
> $ hg ci -m L2
>
> + $ hg phase --force --secret 2
> +
> $ hg tglog
> - @ 4: 'L2'
> + @ 4:draft 'L2'
> |
> - o 3: 'L1'
> + o 3:draft 'L1'
> |
> - | o 2: 'C3'
> + | o 2:secret 'C3'
> |/
> - o 1: 'C2'
> + o 1:draft 'C2'
> |
> - o 0: 'C1'
> + o 0:draft 'C1'
>
>
> Conflicting rebase:
> @@ -63,15 +65,15 @@
> rebase aborted
>
> $ hg tglog
> - @ 4: 'L2'
> + @ 4:draft 'L2'
> |
> - o 3: 'L1'
> + o 3:draft 'L1'
> |
> - | o 2: 'C3'
> + | o 2:secret 'C3'
> |/
> - o 1: 'C2'
> + o 1:draft 'C2'
> |
> - o 0: 'C1'
> + o 0:draft 'C1'
>
> $ cd ..
>
> @@ -104,18 +106,21 @@
> $ hg ci -Am C1
> adding c
>
> + $ hg phase --force --secret 1
> + $ hg phase --public 1
> +
> Rebase and abort without generating new changesets:
>
> $ hg tglog
> - @ 4: 'C1'
> + @ 4:draft 'C1'
> |
> - o 3: 'B bis'
> + o 3:draft 'B bis'
> |
> - | o 2: 'C'
> + | o 2:secret 'C'
> | |
> - | o 1: 'B'
> + | o 1:public 'B'
> |/
> - o 0: 'A'
> + o 0:public 'A'
>
> $ hg rebase -b 4 -d 2
> merging c
> @@ -125,27 +130,27 @@
> [255]
>
> $ hg tglog
> - @ 4: 'C1'
> + @ 4:draft 'C1'
> |
> - o 3: 'B bis'
> + o 3:draft 'B bis'
> |
> - | @ 2: 'C'
> + | @ 2:secret 'C'
> | |
> - | o 1: 'B'
> + | o 1:public 'B'
> |/
> - o 0: 'A'
> + o 0:public 'A'
>
> $ hg rebase -a
> rebase aborted
>
> $ hg tglog
> - @ 4: 'C1'
> + @ 4:draft 'C1'
> |
> - o 3: 'B bis'
> + o 3:draft 'B bis'
> |
> - | o 2: 'C'
> + | o 2:secret 'C'
> | |
> - | o 1: 'B'
> + | o 1:public 'B'
> |/
> - o 0: 'A'
> + o 0:public 'A'
>
> diff -r 476a981fdf34 -r 345cdd7b28c1 tests/test-rebase-check-restore.t
> --- a/tests/test-rebase-check-restore.t Mon Jan 16 01:21:30 2012 -0600
> +++ b/tests/test-rebase-check-restore.t Tue Jan 17 09:12:14 2012 +0100
> @@ -7,7 +7,7 @@
> > publish=False
> >
> > [alias]
> - > tglog = log -G --template "{rev}: '{desc}' {branches}\n"
> + > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
> > EOF
>
>
> @@ -43,26 +43,28 @@
> $ echo F >> A
> $ hg ci -m F
>
> + $ hg phase --force --secret 2
> +
> $ cd ..
>
>
> -Rebasing B onto E - check keep:
> +Rebasing B onto E - check keep: and phases
>
> $ hg clone -q -u . a a1
> $ cd a1
>
> $ hg tglog
> - @ 5: 'F' notdefault
> + @ 5:draft 'F' notdefault
> |
> - | o 4: 'E'
> + | o 4:draft 'E'
> | |
> - | o 3: 'D'
> + | o 3:draft 'D'
> |/
> - | o 2: 'C'
> + | o 2:secret 'C'
> | |
> - | o 1: 'B'
> + | o 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> $ hg rebase -s 1 -d 4 --keep
> merging A
> @@ -79,21 +81,21 @@
> $ hg rebase --continue
>
> $ hg tglog
> - @ 7: 'C'
> + @ 7:secret 'C'
> |
> - o 6: 'B'
> + o 6:draft 'B'
> |
> - | o 5: 'F' notdefault
> + | o 5:draft 'F' notdefault
> | |
> - o | 4: 'E'
> + o | 4:draft 'E'
> | |
> - o | 3: 'D'
> + o | 3:draft 'D'
> |/
> - | o 2: 'C'
> + | o 2:secret 'C'
> | |
> - | o 1: 'B'
> + | o 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> $ cd ..
>
> @@ -104,17 +106,17 @@
> $ cd a2
>
> $ hg tglog
> - @ 5: 'F' notdefault
> + @ 5:draft 'F' notdefault
> |
> - | o 4: 'E'
> + | o 4:draft 'E'
> | |
> - | o 3: 'D'
> + | o 3:draft 'D'
> |/
> - | o 2: 'C'
> + | o 2:secret 'C'
> | |
> - | o 1: 'B'
> + | o 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> $ hg rebase -s 5 -d 4 --keepbranches
> merging A
> @@ -132,15 +134,15 @@
> saved backup bundle to $TESTTMP/a2/.hg/strip-backup/*-backup.hg (glob)
>
> $ hg tglog
> - @ 5: 'F' notdefault
> + @ 5:draft 'F' notdefault
> |
> - o 4: 'E'
> + o 4:draft 'E'
> |
> - o 3: 'D'
> + o 3:draft 'D'
> |
> - | o 2: 'C'
> + | o 2:secret 'C'
> | |
> - | o 1: 'B'
> + | o 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> diff -r 476a981fdf34 -r 345cdd7b28c1 tests/test-rebase-collapse.t
> --- a/tests/test-rebase-collapse.t Mon Jan 16 01:21:30 2012 -0600
> +++ b/tests/test-rebase-collapse.t Tue Jan 17 09:12:14 2012 +0100
> @@ -8,6 +8,7 @@
> >
> > [alias]
> > tglog = log -G --template "{rev}: '{desc}' {branches}\n"
> + > tglogp = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
> > EOF
>
> Create repo a:
> @@ -43,28 +44,31 @@
> $ cd ..
>
>
> -Rebasing B onto H:
> +Rebasing B onto H and collapsing changesets with different phases:
> +
>
> $ hg clone -q -u 3 a a1
> $ cd a1
>
> + $ hg phase --force --secret 3
> +
> $ hg rebase --collapse --keepbranches
> saved backup bundle to $TESTTMP/a1/.hg/strip-backup/*-backup.hg (glob)
>
> - $ hg tglog
> - @ 5: 'Collapsed revision
> + $ hg tglogp
> + @ 5:secret 'Collapsed revision
> | * B
> | * C
> | * D'
> - o 4: 'H'
> + o 4:draft 'H'
> |
> - | o 3: 'G'
> + | o 3:draft 'G'
> |/|
> - o | 2: 'F'
> + o | 2:draft 'F'
> | |
> - | o 1: 'E'
> + | o 1:draft 'E'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> $ hg manifest
> A
> @@ -82,6 +86,7 @@
> $ hg clone -q -u . a a2
> $ cd a2
>
> + $ hg phase --force --secret 6
> $ hg rebase --source 4 --collapse
> saved backup bundle to $TESTTMP/a2/.hg/strip-backup/*-backup.hg (glob)
>
> diff -r 476a981fdf34 -r 345cdd7b28c1 tests/test-rebase-conflicts.t
> --- a/tests/test-rebase-conflicts.t Mon Jan 16 01:21:30 2012 -0600
> +++ b/tests/test-rebase-conflicts.t Tue Jan 17 09:12:14 2012 +0100
> @@ -7,7 +7,7 @@
> > publish=False
> >
> > [alias]
> - > tglog = log -G --template "{rev}: '{desc}' {branches}\n"
> + > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
> > EOF
>
> $ hg init a
> @@ -37,18 +37,20 @@
> $ hg add extra2
> $ hg ci -m L3
>
> + $ hg phase --force --secret 4
> +
> $ hg tglog
> - @ 5: 'L3'
> + @ 5:secret 'L3'
> |
> - o 4: 'L2'
> + o 4:secret 'L2'
> |
> - o 3: 'L1'
> + o 3:draft 'L1'
> |
> - | o 2: 'C3'
> + | o 2:draft 'C3'
> |/
> - o 1: 'C2'
> + o 1:draft 'C2'
> |
> - o 0: 'C1'
> + o 0:draft 'C1'
>
> Try to call --continue:
>
> @@ -79,17 +81,17 @@
> saved backup bundle to $TESTTMP/a/.hg/strip-backup/*-backup.hg (glob)
>
> $ hg tglog
> - @ 5: 'L3'
> + @ 5:secret 'L3'
> |
> - o 4: 'L2'
> + o 4:secret 'L2'
> |
> - o 3: 'L1'
> + o 3:draft 'L1'
> |
> - o 2: 'C3'
> + o 2:draft 'C3'
> |
> - o 1: 'C2'
> + o 1:draft 'C2'
> |
> - o 0: 'C1'
> + o 0:draft 'C1'
>
> Check correctness:
>
> diff -r 476a981fdf34 -r 345cdd7b28c1 tests/test-rebase-detach.t
> --- a/tests/test-rebase-detach.t Mon Jan 16 01:21:30 2012 -0600
> +++ b/tests/test-rebase-detach.t Tue Jan 17 09:12:14 2012 +0100
> @@ -47,25 +47,26 @@
> |/
> 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 tglog
> - @ 7: 'D'
> + $ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n"
> + @ 7:secret 'D'
> |
> - o 6: 'H'
> + o 6:draft 'H'
> |
> - | o 5: 'G'
> + | o 5:draft 'G'
> |/|
> - o | 4: 'F'
> + o | 4:draft 'F'
> | |
> - | o 3: 'E'
> + | o 3:draft 'E'
> |/
> - | o 2: 'C'
> + | o 2:draft 'C'
> | |
> - | o 1: 'B'
> + | o 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> $ hg manifest
> A
> @@ -185,6 +186,7 @@
>
> $ hg clone -q -u . a a4
> $ cd a4
> + $ hg phase --force --secret 3
>
> $ hg tglog
> @ 7: 'H'
> @@ -206,21 +208,21 @@
> $ hg rebase --detach --collapse -s 2 -d 7
> saved backup bundle to $TESTTMP/a4/.hg/strip-backup/*-backup.hg (glob)
>
> - $ hg tglog
> - @ 6: 'Collapsed revision
> + $ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n"
> + @ 6:secret 'Collapsed revision
> | * C
> | * D'
> - o 5: 'H'
> + o 5:draft 'H'
> |
> - | o 4: 'G'
> + | o 4:draft 'G'
> |/|
> - o | 3: 'F'
> + o | 3:draft 'F'
> | |
> - | o 2: 'E'
> + | o 2:draft 'E'
> |/
> - | o 1: 'B'
> + | o 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> $ hg manifest
> A
> @@ -360,13 +362,14 @@
>
> $ cd ..
>
> -Ensure --continue restores a correct state (issue3046):
> +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.
> @@ -376,23 +379,23 @@
> $ hg resolve --all -t internal:local
> $ hg rebase -c
> saved backup bundle to $TESTTMP/a7/.hg/strip-backup/6215fafa5447-backup.hg (glob)
> - $ hg tglog
> - @ 8: 'H2'
> + $ hg log -G --template "{rev}:{phase} '{desc}' {branches}\n"
> + @ 8:secret 'H2'
> |
> - o 7: 'H'
> + o 7:draft 'H'
> |
> - | o 6: 'G'
> + | o 6:draft 'G'
> |/|
> - o | 5: 'F'
> + o | 5:draft 'F'
> | |
> - | o 4: 'E'
> + | o 4:draft 'E'
> |/
> - | o 3: 'D'
> + | o 3:draft 'D'
> | |
> - | o 2: 'C'
> + | o 2:draft 'C'
> | |
> - | o 1: 'B'
> + | o 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
>
> diff -r 476a981fdf34 -r 345cdd7b28c1 tests/test-rebase-interruptions.t
> --- a/tests/test-rebase-interruptions.t Mon Jan 16 01:21:30 2012 -0600
> +++ b/tests/test-rebase-interruptions.t Tue Jan 17 09:12:14 2012 +0100
> @@ -8,6 +8,7 @@
> >
> > [alias]
> > tglog = log -G --template "{rev}: '{desc}' {branches}\n"
> + > tglogp = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
> > EOF
>
>
> @@ -71,20 +72,24 @@
> $ hg add Extra
> $ hg ci -m 'Extra'
>
> - $ hg tglog
> - @ 6: 'Extra'
> +Force this commit onto secret phase
> +
> + $ hg phase --force --secret 6
> +
> + $ hg tglogp
> + @ 6:secret 'Extra'
> |
> - | o 5: 'B'
> + | o 5:draft 'B'
> | |
> - | o 4: 'E'
> + | o 4:draft 'E'
> | |
> - | o 3: 'D'
> + | o 3:draft 'D'
> | |
> - o | 2: 'C'
> + o | 2:draft 'C'
> | |
> - o | 1: 'B'
> + o | 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> Resume the rebasing:
>
> @@ -104,22 +109,22 @@
> $ hg rebase --continue
> warning: new changesets detected on source branch, not stripping
>
> - $ hg tglog
> - @ 7: 'C'
> + $ hg tglogp
> + @ 7:draft 'C'
> |
> - | o 6: 'Extra'
> + | o 6:secret 'Extra'
> | |
> - o | 5: 'B'
> + o | 5:draft 'B'
> | |
> - o | 4: 'E'
> + o | 4:draft 'E'
> | |
> - o | 3: 'D'
> + o | 3:draft 'D'
> | |
> - | o 2: 'C'
> + | o 2:draft 'C'
> | |
> - | o 1: 'B'
> + | o 1:draft 'B'
> |/
> - o 0: 'A'
> + o 0:draft 'A'
>
> $ cd ..
>
> @@ -195,3 +200,68 @@
>
> $ cd ..
>
> +Changes during an interruption - abort (again):
> +
> + $ hg clone -q -u . a a3
> + $ cd a3
> +
> + $ hg tglogp
> + @ 4:draft 'E'
> + |
> + o 3:draft 'D'
> + |
> + | o 2:draft 'C'
> + | |
> + | o 1:draft 'B'
> + |/
> + o 0:draft 'A'
> +
> +Rebasing B onto E:
> +
> + $ hg rebase -s 1 -d 4
> + merging A
> + warning: conflicts during merge.
> + merging A incomplete! (edit conflicts, then use 'hg resolve --mark')
> + abort: unresolved conflicts (see hg resolve, then hg rebase --continue)
> + [255]
> +
> +Change phase on B and B'
> +
> + $ hg up -q -C 5
> + $ hg phase --public 1
> + $ hg phase --public 5
> + $ hg phase --secret -f 2
> +
> + $ hg tglogp
> + @ 5:public 'B'
> + |
> + o 4:public 'E'
> + |
> + o 3:public 'D'
> + |
> + | o 2:secret 'C'
> + | |
> + | o 1:public 'B'
> + |/
> + o 0:public 'A'
> +
> +Abort the rebasing:
> +
> + $ hg rebase --abort
> + warning: immutable rebased changeset detected, can't abort
> + [255]
> +
> + $ hg tglogp
> + @ 5:public 'B'
> + |
> + o 4:public 'E'
> + |
> + o 3:public 'D'
> + |
> + | o 2:secret 'C'
> + | |
> + | o 1:public 'B'
> + |/
> + o 0:public 'A'
> +
> + $ cd ..
> diff -r 476a981fdf34 -r 345cdd7b28c1 tests/test-rebase-scenario-global.t
> --- a/tests/test-rebase-scenario-global.t Mon Jan 16 01:21:30 2012 -0600
> +++ b/tests/test-rebase-scenario-global.t Tue Jan 17 09:12:14 2012 +0100
> @@ -282,6 +282,32 @@
> [255]
>
> $ hg rebase -d 5 -b 6 --keep
> +
> +Check rebasing mutable changeset
> +Source phase greater or equal to destination phase: new changeset get the phase of source:
> + $ hg rebase -s9 -d0
> + saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2b23e52411f4-backup.hg
> + $ hg log --template "{phase}\n" -r 9
> + draft
> + $ hg rebase -s9 -d1
> + saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2cb10d0cfc6c-backup.hg
> + $ hg log --template "{phase}\n" -r 9
> + draft
> + $ hg phase --force --secret 9
> + $ hg rebase -s9 -d0
> + saved backup bundle to $TESTTMP/a7/.hg/strip-backup/c5b12b67163a-backup.hg
> + $ hg log --template "{phase}\n" -r 9
> + secret
> + $ hg rebase -s9 -d1
> + saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2a0524f868ac-backup.hg
> + $ hg log --template "{phase}\n" -r 9
> + secret
> +Source phase lower than destination phase: new changeset get the phase of destination:
> + $ hg rebase -s7 -d9
> + saved backup bundle to $TESTTMP/a7/.hg/strip-backup/c9659aac0000-backup.hg
> + $ hg log --template "{phase}\n" -r 9
> + secret
> +
> $ cd ..
>
> Test for revset
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list