evolve: (issue4386) cleanup, split, fold and bijection in `hg prune`
authorLaurent Charignon <lcharignon@fb.com>
Thu, 25 Jun 2015 13:33:50 -0700
changeset 1471 4140d680784e
parent 1470 c3f6e97c71b1
child 1473 89a1103bf139
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.
hgext/evolve.py
tests/test-corrupt.t
tests/test-evolve-split.t
tests/test-evolve.t
tests/test-prune.t
--- a/hgext/evolve.py	Tue Jun 30 18:32:12 2015 -0700
+++ b/hgext/evolve.py	Thu Jun 25 13:33:50 2015 -0700
@@ -2137,6 +2137,8 @@
      ('r', 'rev', [], _("revisions to prune")),
      ('k', 'keep', None, _("does not modify working copy during prune")),
      ('', 'biject', False, _("do a 1-1 map between rev and successor ranges")),
+     ('', 'fold', False, _("record a fold (multiple precursors, one successors)")),
+     ('', 'split', False, _("record a split (on precursor, multiple successors)")),
      ('B', 'bookmark', '', _("remove revs only reachable from given"
                              " bookmark"))] + metadataopts,
     _('[OPTION] [-r] REV...'))
@@ -2159,12 +2161,22 @@
     revisions to prune and successor changesets. This option may be removed in
     a future release (with the functionality absorbed automatically).
 
+    If you specify multiple revisions in --succ, you are recording a "split"
+    and have to acknowledge it by usng --split. The same logic apply when you
+    prune multiple changesets with a single successors, this will record a
+    "fold" requires a --fold flag.
     """
     revs = scmutil.revrange(repo, list(revs) + opts.get('rev'))
     succs = opts['new'] + opts['succ']
     bookmark = opts.get('bookmark')
     metadata = _getmetadata(**opts)
     biject = opts.get('biject')
+    fold = opts.get('fold')
+    split = opts.get('split')
+
+    options = [o for o in ('biject', 'fold', 'split') if opts.get(o)]
+    if 1 < len(options):
+        raise util.Abort(_("can only specify one of %s") % ', '.join(options))
 
     if bookmark:
         marks,revs = _reachablefrombookmark(repo, revs, bookmark)
@@ -2204,15 +2216,20 @@
         if not biject and len(sucs) > 1 and len(precs) > 1:
             msg = "Can't use multiple successors for multiple precursors"
             raise util.Abort(msg)
-
-        if biject and len(sucs) != len(precs):
+        elif biject and len(sucs) != len(precs):
             msg = "Can't use %d successors for %d precursors" \
                 % (len(sucs), len(precs))
             raise util.Abort(msg)
-
-        relations = [(p, sucs) for p in precs]
-        if biject:
+        elif (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)
+        elif 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)
+        elif biject:
             relations = [(p, (s,)) for p, s in zip(precs, sucs)]
+        else:
+            relations = [(p, sucs) for p in precs]
 
         wdp = repo['.']
 
--- a/tests/test-corrupt.t	Tue Jun 30 18:32:12 2015 -0700
+++ b/tests/test-corrupt.t	Thu Jun 25 13:33:50 2015 -0700
@@ -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
--- a/tests/test-evolve-split.t	Tue Jun 30 18:32:12 2015 -0700
+++ b/tests/test-evolve-split.t	Thu Jun 25 13:33:50 2015 -0700
@@ -43,7 +43,7 @@
   $ 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
--- a/tests/test-evolve.t	Tue Jun 30 18:32:12 2015 -0700
+++ b/tests/test-evolve.t	Thu Jun 25 13:33:50 2015 -0700
@@ -1372,7 +1372,7 @@
   $ 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::"
--- a/tests/test-prune.t	Tue Jun 30 18:32:12 2015 -0700
+++ b/tests/test-prune.t	Thu Jun 25 13:33:50 2015 -0700
@@ -32,6 +32,19 @@
   o  0:1f0dee641bb7[] (stable/public) add a
   
 
+Check arguments exclusive to each other
+---------------------------------------
+
+  $ hg prune --fold --biject
+  abort: can only specify one of biject, fold
+  [255]
+  $ hg prune --split --fold
+  abort: can only specify one of fold, split
+  [255]
+  $ hg prune --split --fold --biject
+  abort: can only specify one of biject, fold, split
+  [255]
+
 Check simple case
 ----------------------------
 
@@ -150,6 +163,9 @@
 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'}
@@ -190,6 +206,9 @@
 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'}