rewriteutil: move 'reachablefrombookmark' to the module
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 23 Jul 2017 06:11:33 +0200
changeset 2764 a4a6f4128be5
parent 2763 4a5b0c373e65
child 2765 8a2e1aac6b41
rewriteutil: move 'reachablefrombookmark' to the module
hgext3rd/evolve/__init__.py
hgext3rd/evolve/rewriteutil.py
--- a/hgext3rd/evolve/__init__.py	Sun Jul 23 05:42:41 2017 +0200
+++ b/hgext3rd/evolve/__init__.py	Sun Jul 23 06:11:33 2017 +0200
@@ -242,7 +242,6 @@
 
 import mercurial
 from mercurial import util
-from mercurial import repair
 
 from mercurial import obsolete
 if not obsolete._enabled:
@@ -2111,29 +2110,6 @@
     finally:
         lockmod.release(wlock)
 
-def _reachablefrombookmark(repo, revs, bookmarks):
-    """filter revisions and bookmarks reachable from the given bookmark
-    yoinked from mq.py
-    """
-    repomarks = repo._bookmarks
-    if not bookmarks.issubset(repomarks):
-        raise error.Abort(_("bookmark '%s' not found") %
-                          ','.join(sorted(bookmarks - set(repomarks.keys()))))
-
-    # If the requested bookmark is not the only one pointing to a
-    # a revision we have to only delete the bookmark and not strip
-    # anything. revsets cannot detect that case.
-    nodetobookmarks = {}
-    for mark, bnode in repomarks.iteritems():
-        nodetobookmarks.setdefault(bnode, []).append(mark)
-    for marks in nodetobookmarks.values():
-        if bookmarks.issuperset(marks):
-            rsrevs = repair.stripbmrevset(repo, marks[0])
-            revs = set(revs)
-            revs.update(set(rsrevs))
-            revs = sorted(revs)
-    return repomarks, revs
-
 def _deletebookmark(repo, repomarks, bookmarks):
     wlock = lock = tr = None
     try:
@@ -2212,7 +2188,8 @@
         raise error.Abort(_("can only specify one of %s") % ', '.join(options))
 
     if bookmarks:
-        repomarks, revs = _reachablefrombookmark(repo, revs, bookmarks)
+        reachablefrombookmark = rewriteutil.reachablefrombookmark
+        repomarks, revs = reachablefrombookmark(repo, revs, bookmarks)
         if not revs:
             # no revisions to prune - delete bookmark immediately
             _deletebookmark(repo, repomarks, bookmarks)
--- a/hgext3rd/evolve/rewriteutil.py	Sun Jul 23 05:42:41 2017 +0200
+++ b/hgext3rd/evolve/rewriteutil.py	Sun Jul 23 06:11:33 2017 +0200
@@ -21,6 +21,7 @@
     lock as lockmod,
     obsolete,
     phases,
+    repair,
     revset,
 )
 
@@ -77,6 +78,29 @@
     hg.update(repo, prev)
     commands.revert(ui, repo, rev=ctx.rev(), all=True)
 
+def reachablefrombookmark(repo, revs, bookmarks):
+    """filter revisions and bookmarks reachable from the given bookmark
+    yoinked from mq.py
+    """
+    repomarks = repo._bookmarks
+    if not bookmarks.issubset(repomarks):
+        raise error.Abort(_("bookmark '%s' not found") %
+                          ','.join(sorted(bookmarks - set(repomarks.keys()))))
+
+    # If the requested bookmark is not the only one pointing to a
+    # a revision we have to only delete the bookmark and not strip
+    # anything. revsets cannot detect that case.
+    nodetobookmarks = {}
+    for mark, bnode in repomarks.iteritems():
+        nodetobookmarks.setdefault(bnode, []).append(mark)
+    for marks in nodetobookmarks.values():
+        if bookmarks.issuperset(marks):
+            rsrevs = repair.stripbmrevset(repo, marks[0])
+            revs = set(revs)
+            revs.update(set(rsrevs))
+            revs = sorted(revs)
+    return repomarks, revs
+
 def rewrite(repo, old, updates, head, newbases, commitopts):
     """Return (nodeid, created) where nodeid is the identifier of the
     changeset generated by the rewrite process, and created is True if