evolve: consider all potential candidates on bare evolve
authorPierre-Yves David <pierre-yves.david@fb.com>
Mon, 22 Jun 2015 19:24:21 -0700
changeset 1420 0b714c4ad9ff
parent 1419 b54524ae77c0
child 1421 8f18c7b3af14
evolve: consider all potential candidates on bare evolve Instead of stopping at the first resolution, we returns all matches. If there is ambiguity, we abort. The function itself seems fairly flawed but will do the job in simple case.
README
hgext/evolve.py
tests/test-stabilize-order.t
--- a/README	Tue Jun 23 13:20:00 2015 -0700
+++ b/README	Mon Jun 22 19:24:21 2015 -0700
@@ -58,7 +58,9 @@
 - evolve: properly skip unstable revision with non-evolved unstable parent
 - evolve: gain --unstable --divergent --bumped flag to select the trouble
 - evolve: issue more useful error message and hint when evolve has nothing to
-  do as invocated.
+          do as invocated.
+- evolve: bare `hg evolve` commands now abort when multiple changesets could be
+          a target.
 
 5.1.5 --
 
--- a/hgext/evolve.py	Tue Jun 23 13:20:00 2015 -0700
+++ b/hgext/evolve.py	Mon Jun 22 19:24:21 2015 -0700
@@ -1410,9 +1410,12 @@
     elif anyopt:
         revs = repo.revs('first(%s())' % (targetcat))
     elif targetcat == 'unstable':
-        tro = _stabilizableunstable(repo, repo['.'])
-        if tro is not None:
-            revs = set([tro])
+        revs = set(_aspiringchildren(repo, repo['.']))
+        if 1 < len(revs):
+            msg = "multiple evolve candidates"
+            hint = (_("select one of %s with --rev")
+                    % ', '.join([str(repo[r]) for r in sorted(revs)]))
+            raise error.Abort(msg, hint=hint)
     elif targetcat in repo['.'].troubles():
         revs = set([repo['.'].rev()])
     return revs
@@ -1586,10 +1589,9 @@
     progresscb()
     _cleanup(ui, repo, startnode, showprogress)
 
-def _stabilizableunstable(repo, pctx):
-    """Return a changectx for an unstable changeset which can be
-    stabilized on top of pctx or one of its descendants. None if none
-    can be found.
+def _aspiringchildren(repo, pctx):
+    """Return a list of changectx which can be stabilized on top of pctx or
+    one of its descendants. Empty list if none can be found.
     """
     def selfanddescendants(repo, pctx):
         yield pctx
@@ -1602,14 +1604,15 @@
 
     # Look for an unstable which can be stabilized as a child of
     # node. The unstable must be a child of one of node predecessors.
+    result = []
     directdesc = set([pctx.rev()])
     for ctx in selfanddescendants(repo, pctx):
         for child in ctx.children():
             if ctx.rev() in directdesc and not child.obsolete():
                 directdesc.add(child.rev())
             elif child.unstable():
-                return child
-    return None
+                result.append(child)
+    return result
 
 def _solveunstable(ui, repo, orig, dryrun=False, confirm=False,
                    progresscb=None):
--- a/tests/test-stabilize-order.t	Tue Jun 23 13:20:00 2015 -0700
+++ b/tests/test-stabilize-order.t	Mon Jun 22 19:24:21 2015 -0700
@@ -182,3 +182,66 @@
   $ hg evolve --any -v
   no unstable changesets to evolve
   [1]
+
+Ambiguous evolution
+  $ echo a > k
+  $ hg add k
+  $ hg ci -m firstambiguous
+  $ hg up .^
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo a > l
+  $ hg add l
+  $ hg ci -m secondambiguous
+  created new head
+  $ hg up .^
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg commit --amend -m "newmessage"
+  2 new unstable changesets
+  $ hg log -G
+  @  changeset:   15:49773ccde390
+  |  tag:         tip
+  |  parent:      11:036cf654e942
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     newmessage
+  |
+  | o  changeset:   14:a9892777b519
+  | |  parent:      12:e99ecf51c867
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     secondambiguous
+  | |
+  | | o  changeset:   13:0b6e26b2472d
+  | |/   user:        test
+  | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    summary:     firstambiguous
+  | |
+  | x  changeset:   12:e99ecf51c867
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     addc
+  |
+  o  changeset:   11:036cf654e942
+  |  parent:      7:005fe5914f78
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     addb
+  |
+  o  changeset:   7:005fe5914f78
+  |  parent:      0:c471ef929e6a
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     adda
+  |
+  o  changeset:   0:c471ef929e6a
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     addroot
+  
+  $ hg evolve
+  abort: multiple evolve candidates
+  (select one of *, * with --rev) (glob)
+  [255]
+
+
+