[PATCH 1 of 4 evolve-ext] evolve: add _nextcandidates, to be used in evolve with no arg and with --all

Laurent Charignon lcharignon at fb.com
Mon Jun 22 17:42:00 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1435010266 25200
#      Mon Jun 22 14:57:46 2015 -0700
# Node ID 79e0d7418fa3a9dd71e39b4865542838e63f40eb
# Parent  4198e2fad6ba08c0798c217e7b643fae9c28e81b
evolve: add _nextcandidates, to be used in evolve with no arg and with --all

This patch adds _nextcandidates, an iterator, yieldind the revisions that will
evolve on the parent of the current working copy and its non obsolete
descendants. It is used later in this patch series to reimplement evolve with
no argument and make evolve --all only care about the changesets related to
the parent of the working copy.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -469,6 +469,45 @@ def _installalias(ui):
                 "! $HG rebase --dest . --rev $@ && $HG up tip")
 
 
+
+def _nextcandidates(repo):
+    """Iterator yielding every changeset that can evolve on a non obsolete
+       descendant of the parent of the working copy
+
+       It is used to implement _nextcandidate and _allnextcandidates that in
+       turn are used to implement hg evolve with no argument and hg evole --all
+    """
+    nonobsdescendants = sorted(repo.revs("(.::) - obsolete() - troubled()"))
+    troubled = repo.revs("troubled()")
+
+    # Build a dependency graph for all the troubled
+    successors = collections.defaultdict(list)
+    for t in troubled:
+        for p in repo[t].parents():
+            try:
+                s = _singlesuccessor(repo, repo[p])
+            except MultipleSuccessorsError, exc:
+                successors[s].extend(exc.successorssets)
+            successors[s].append(t)
+
+    # Yield the revs that will evolve on descendants of .
+    tovisit = collections.deque(nonobsdescendants)
+    while tovisit:
+        n = tovisit.popleft()
+        if not n in successors:
+            # no rev will evolve on that one
+            pass
+        elif len(successors[n]) > 1:
+            # ambiguity
+            msg = _("several successors for %d %s\n") % n
+            hint = _("select one with --rev\n") % successors[n]
+            raise error.Abort(msg, hint=hint)
+        else:
+            successor = successors[n][0]
+            if successor in troubled:
+                yield successor
+            tovisit.append(successor)
+
 ### Troubled revset symbol
 
 @eh.revset('troubled')


More information about the Mercurial-devel mailing list