[PATCH 2 of 2 evolve-ext] evolve: (issue4386) cleanup, split, fold and bijection in `hg prune`

Laurent Charignon lcharignon at fb.com
Thu Jun 25 19:17:15 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1435264430 25200
#      Thu Jun 25 13:33:50 2015 -0700
# Node ID d2da33829da4b22bd7afd354f4780e8ab3d670a3
# Parent  0a1bf08ebdd93bfb199c18db4ea4e23c071e73cc
evolve: (issue4386) cleanup, split, fold and bijection in `hg prune`

Before this patch, the prune command was splitting and folding implicitely
based on the number of successors and precursors. This patch makes the
two behavior explicit by requesting a flag to perform a split or a fold.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -2092,6 +2092,8 @@ def _getmetadata(**opts):
      ('s', 'succ', [], _("successor changeset")),
      ('r', 'rev', [], _("revisions to prune")),
      ('k', 'keep', None, _("does not modify working copy during prune")),
+     ('', 'fold', False, _("perform a fold")),
+     ('', 'split', False, _("perform a split")),
      ('B', 'bookmark', '', _("remove revs only reachable from given"
                              " bookmark"))] + metadataopts,
     _('[OPTION] [-r] REV...'))
@@ -2110,8 +2112,10 @@ def cmdprune(ui, repo, *revs, **opts):
     You can use the ``--succ`` option to inform mercurial that a newer version
     of the pruned changeset exists.
 
-    If you precise one revision to prune and multiple successor, it is a split.
-    If you precise several commits and a single successor, it is a fold.
+    If you precise one revision to prune and multiple successor, it is a split
+    and you have to add --split.
+    If you precise several commits and a single successor, it is a fold and you
+    have to add --fold.
     If you precise more than one revision to prune and more than one successor
     there has to be one successor per revision to prune and a 1-1 bijection
     is done.
@@ -2120,6 +2124,8 @@ def cmdprune(ui, repo, *revs, **opts):
     succs = opts['new'] + opts['succ']
     bookmark = opts.get('bookmark')
     metadata = _getmetadata(**opts)
+    fold = opts.get('fold')
+    split = opts.get('split')
 
     if bookmark:
         marks,revs = _reachablefrombookmark(repo, revs, bookmark)
@@ -2165,6 +2171,13 @@ def cmdprune(ui, repo, *revs, **opts):
                 raise util.Abort(msg)
             relations = [(p, (s,)) for p, s in zip(precs, sucs)]
         else:
+            if len(precs) == 1 and len(sucs) > 1 and not split:
+                msg = "please add --split if you want to do a split"
+                raise util.Abort(msg)
+            if len(sucs) == 1 and len(precs) > 1 and not fold:
+                msg = "please add --fold if you want to do a fold"
+                raise util.Abort(msg)
+
             relations = [(p, sucs) for p in precs]
 
         wdp = repo['.']
diff --git a/tests/test-corrupt.t b/tests/test-corrupt.t
--- a/tests/test-corrupt.t
+++ b/tests/test-corrupt.t
@@ -101,7 +101,7 @@
      summary:     add A
   
 
-  $ hg kill -n -1 -- -2 -3
+  $ hg kill --fold -n -1 -- -2 -3
   2 changesets pruned
   $ hg push ../other
   pushing to ../other
diff --git a/tests/test-evolve-split.t b/tests/test-evolve-split.t
--- a/tests/test-evolve-split.t
+++ b/tests/test-evolve-split.t
@@ -43,7 +43,7 @@ Create a split commit
   $ printf "pp" > pp;
   $ hg add pp
   $ hg commit -m "_pp"
-  $ hg prune --succ "desc(_oo) + desc(_pp)" -r "desc('oo+pp')"
+  $ hg prune --succ "desc(_oo) + desc(_pp)" -r "desc('oo+pp')" --split
   1 changesets pruned
   1 new unstable changesets
   $ hg log -G
diff --git a/tests/test-evolve.t b/tests/test-evolve.t
--- a/tests/test-evolve.t
+++ b/tests/test-evolve.t
@@ -1382,7 +1382,7 @@ Create a split commit
   $ printf "pp" > pp;
   $ hg add pp
   $ hg commit -m "_pp"
-  $ hg prune --succ "desc(_oo) + desc(_pp)" -r "desc('oo+pp')"
+  $ hg prune --succ "desc(_oo) + desc(_pp)" -r "desc('oo+pp')" --split
   1 changesets pruned
   1 new unstable changesets
   $ glog -r "18::"
diff --git a/tests/test-prune.t b/tests/test-prune.t
--- a/tests/test-prune.t
+++ b/tests/test-prune.t
@@ -150,6 +150,9 @@ one old, one new
 one old, two new
 
   $ hg prune 'desc("add dd")' -s 'desc("add nD")' -s 'desc("add nC")'
+  abort: please add --split if you want to do a split
+  [255]
+  $ hg prune 'desc("add dd")' -s 'desc("add nD")' -s 'desc("add nC")' --split
   1 changesets pruned
   $ hg debugobsolete
   9d206ffc875e1bc304590549be293be36821e66c 0 {47d2a3944de8b013de3be9578e8e344ea2e6c097} (Sat Dec 15 00:00:00 1979 +0000) {'user': 'blah'}
@@ -177,6 +180,9 @@ one old, two new
 two old, one new:
 
   $ hg prune 'desc("add cc")' 'desc("add bb")' -s 'desc("add nB")'
+  abort: please add --fold if you want to do a fold
+  [255]
+  $ hg prune 'desc("add cc")' 'desc("add bb")' -s 'desc("add nB")' --fold
   2 changesets pruned
   $ hg debugobsolete
   9d206ffc875e1bc304590549be293be36821e66c 0 {47d2a3944de8b013de3be9578e8e344ea2e6c097} (Sat Dec 15 00:00:00 1979 +0000) {'user': 'blah'}


More information about the Mercurial-devel mailing list