rebase: fix phases movement
authorAlain Leufroy <alain.leufroyATgmailMYDOTcom>
Tue, 17 Jan 2012 09:12:14 +0100
changeset 15917 e66084ef8449
parent 15916 c96148346af8
child 15918 4f9853e7f690
rebase: fix phases movement Rebase now try to keep the phases of source changesets.
hgext/rebase.py
tests/test-rebase-abort.t
tests/test-rebase-check-restore.t
tests/test-rebase-collapse.t
tests/test-rebase-conflicts.t
tests/test-rebase-detach.t
tests/test-rebase-interruptions.t
tests/test-rebase-scenario-global.t
--- a/hgext/rebase.py	Wed Jan 18 11:33:14 2012 +0100
+++ b/hgext/rebase.py	Tue Jan 17 09:12:14 2012 +0100
@@ -15,7 +15,7 @@
 '''
 
 from mercurial import hg, util, repair, merge, cmdutil, commands, bookmarks
-from mercurial import extensions, patch, scmutil
+from mercurial import extensions, patch, scmutil, phases
 from mercurial.commands import templateopts
 from mercurial.node import nullrev
 from mercurial.lock import release
@@ -372,6 +372,10 @@
         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 overwrite upper phase inherited from parent
+        newnode = repo[newrev].node()
+        phases.retractboundary(repo, targetphase, [newnode])
         return newrev
     except util.Abort:
         # Invalidate the previous setparents
@@ -552,7 +556,13 @@
 
 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
+    ispublic = lambda r: repo._phaserev[r] == phases.public
+    if filter(ispublic, descendants(target)):
+        repo.ui.warn(_("warning: immutable rebased changeset detected, "
+                       "can't abort\n"))
+        return -1
+    elif set(descendants(target)) - set(state.values()):
         repo.ui.warn(_("warning: new changesets detected on target branch, "
                                                     "can't abort\n"))
         return -1
--- a/tests/test-rebase-abort.t	Wed Jan 18 11:33:14 2012 +0100
+++ 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'
-  |
-  o  3: 'L1'
+  @  4:draft 'L2'
   |
-  | o  2: 'C3'
+  o  3:draft 'L1'
+  |
+  | 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'
   
--- a/tests/test-rebase-check-restore.t	Wed Jan 18 11:33:14 2012 +0100
+++ 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
 
 
@@ -46,23 +46,24 @@
   $ cd ..
 
 
-Rebasing B onto E - check keep:
+Rebasing B onto E - check keep: and phases
 
   $ hg clone -q -u . a a1
   $ cd a1
+  $ hg phase --force --secret 2
 
   $ 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 +80,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 ..
 
@@ -102,19 +103,20 @@
 
   $ hg clone -q -u . a a2
   $ cd a2
+  $ hg phase --force --secret 2
 
   $ 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'
   
--- a/tests/test-rebase-collapse.t	Wed Jan 18 11:33:14 2012 +0100
+++ 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)
 
--- a/tests/test-rebase-conflicts.t	Wed Jan 18 11:33:14 2012 +0100
+++ 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:
 
--- a/tests/test-rebase-detach.t	Wed Jan 18 11:33:14 2012 +0100
+++ 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'
   
 
--- a/tests/test-rebase-interruptions.t	Wed Jan 18 11:33:14 2012 +0100
+++ 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  4: 'E'
+  | o  5:draft 'B'
   | |
-  | o  3: 'D'
+  | o  4:draft 'E'
   | |
-  o |  2: 'C'
+  | o  3:draft 'D'
   | |
-  o |  1: 'B'
+  o |  2:draft 'C'
+  | |
+  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 ..
--- a/tests/test-rebase-scenario-global.t	Wed Jan 18 11:33:14 2012 +0100
+++ 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