evolve: preserve branch change
authorPierre-Yves David <pierre-yves.david@fb.com>
Sat, 01 Nov 2014 13:48:34 +0000
changeset 1141 ca17770d2ee9
parent 1140 b7d85cd8ec7b
child 1142 9d85fd6e1474
evolve: preserve branch change evolve will now preserve branch change. If the evolved changeset had a different phases than its parent, this branch name will be preserved. This allow propagation of branch change during amend but do not overwrite special branch name on children,
README
hgext/evolve.py
tests/test-evolve.t
--- a/README	Sat Oct 25 22:25:42 2014 -0400
+++ b/README	Sat Nov 01 13:48:34 2014 +0000
@@ -60,6 +60,7 @@
 5.0.1 --
 
 - amend: fix --logfile argument
+- evolve: preserve branch change when evolving
 
 5.0.0 -- 2014-10-22
 
--- a/hgext/evolve.py	Sat Oct 25 22:25:42 2014 -0400
+++ b/hgext/evolve.py	Sat Nov 01 13:48:34 2014 +0000
@@ -758,7 +758,7 @@
 class MergeFailure(util.Abort):
     pass
 
-def relocate(repo, orig, dest):
+def relocate(repo, orig, dest, keepbranch=False):
     """rewrite <rev> on dest"""
     if orig.rev() == dest.rev():
         raise util.Abort(_('tried to relocate a node on top of itself'),
@@ -811,8 +811,15 @@
             if r[-1]: #some conflict
                 raise util.Abort(
                         'unresolved merge conflicts (see hg help resolve)')
+            if keepbranch:
+                def _extrafn(ctx, extra):
+                    extra['branch'] = ctx.branch()
+            else:
+                _extrafn = (lambda ctx, extra: None)
+
             nodenew = rebase.concludenode(repo, orig.node(), dest.node(),
-                                          node.nullid, commitmsg)
+                                          node.nullid, commitmsg,
+                                          extrafn=_extrafn)
         except util.Abort, exc:
             repo.dirstate.beginparentchange()
             repo.setparents(repo['.'].node(), nullid)
@@ -1341,8 +1348,9 @@
     else:
         repo.ui.note(todo)
         if progresscb: progresscb()
+        keepbranch = orig.p1().branch() != orig.branch()
         try:
-            relocate(repo, orig, target)
+            relocate(repo, orig, target, keepbranch)
         except MergeFailure:
             repo.opener.write('graftstate', orig.hex() + '\n')
             repo.ui.write_err(_('evolve failed!\n'))
--- a/tests/test-evolve.t	Sat Oct 25 22:25:42 2014 -0400
+++ b/tests/test-evolve.t	Sat Nov 01 13:48:34 2014 +0000
@@ -770,3 +770,79 @@
   7 - 5c9c8d9c2e4e another feature (child of ba0ec09b1bab) (public)
   6 - ba0ec09b1bab a nifty feature (public)
   0 - e55e0562ee93 base (public)
+
+  $ cd ..
+
+Test branch preservation:
+===========================
+
+  $ hg init evolving-branch
+  $ cd evolving-branch
+  $ touch a
+  $ hg add a
+  $ hg ci -m 'a0'
+  $ echo 1 > a
+  $ hg ci -m 'a1'
+  $ echo 2 > a
+  $ hg ci -m 'a2'
+  $ echo 3 > a
+  $ hg ci -m 'a3'
+
+  $ hg log -G --template '{rev} [{branch}] {desc|firstline}\n'
+  @  3 [default] a3
+  |
+  o  2 [default] a2
+  |
+  o  1 [default] a1
+  |
+  o  0 [default] a0
+  
+
+branch change propagated
+
+  $ hg up 'desc(a2)'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg branch mybranch
+  marked working directory as branch mybranch
+  (branches are permanent and global, did you want a bookmark?)
+  $ hg amend
+  1 new unstable changesets
+
+  $ hg evolve
+  move:[3] a3
+  atop:[5] a2
+  working directory is now at 7c5649f73d11
+
+  $ hg log -G --template '{rev} [{branch}] {desc|firstline}\n'
+  @  6 [mybranch] a3
+  |
+  o  5 [mybranch] a2
+  |
+  o  1 [default] a1
+  |
+  o  0 [default] a0
+  
+
+branch change preserved
+
+  $ hg up 'desc(a1)'
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg amend -m 'a1_'
+  2 new unstable changesets
+  $ hg evolve
+  move:[5] a2
+  atop:[7] a1_
+  working directory is now at 5406c5cfee42
+  $ hg evolve
+  move:[6] a3
+  atop:[8] a2
+  working directory is now at c7661e655801
+  $ hg log -G --template '{rev} [{branch}] {desc|firstline}\n'
+  @  9 [mybranch] a3
+  |
+  o  8 [mybranch] a2
+  |
+  o  7 [default] a1_
+  |
+  o  0 [default] a0
+