localrepo: extract bookmarkheads method to bookmarks.py
authorAugie Fackler <augie@google.com>
Thu, 18 May 2017 16:43:56 -0400
changeset 32381 b9942bc6b292
parent 32380 5db6d70fd30b
child 32382 c87db79b9507
localrepo: extract bookmarkheads method to bookmarks.py This method is only used internally by destutil, and it's obscure enough I'm willing to just move it without a deprecation warning, especially since the new method has more constrained functionality. Design-wise I'd also like to get active bookmark handling folded into the bookmark store, so that we don't squirrel away an extra attribute for the active bookmark on the repository object.
mercurial/bookmarks.py
mercurial/destutil.py
mercurial/localrepo.py
--- a/mercurial/bookmarks.py	Sat May 20 20:50:29 2017 -0400
+++ b/mercurial/bookmarks.py	Thu May 18 16:43:56 2017 -0400
@@ -226,6 +226,28 @@
                 deleted = True
     return deleted
 
+def headsforactive(repo):
+    """Given a repo with an active bookmark, return divergent bookmark nodes.
+
+    Args:
+      repo: A repository with an active bookmark.
+
+    Returns:
+      A list of binary node ids that is the full list of other
+      revisions with bookmarks divergent from the active bookmark. If
+      there were no divergent bookmarks, then this list will contain
+      only one entry.
+    """
+    if not repo._activebookmark:
+        raise ValueError(
+            'headsforactive() only makes sense with an active bookmark')
+    name = repo._activebookmark.split('@', 1)[0]
+    heads = []
+    for mark, n in repo._bookmarks.iteritems():
+        if mark.split('@', 1)[0] == name:
+            heads.append(n)
+    return heads
+
 def calculateupdate(ui, repo, checkout):
     '''Return a tuple (targetrev, movemarkfrom) indicating the rev to
     check out and where to move the active bookmark from, if needed.'''
--- a/mercurial/destutil.py	Sat May 20 20:50:29 2017 -0400
+++ b/mercurial/destutil.py	Thu May 18 16:43:56 2017 -0400
@@ -234,7 +234,7 @@
 def _destmergebook(repo, action='merge', sourceset=None, destspace=None):
     """find merge destination in the active bookmark case"""
     node = None
-    bmheads = repo.bookmarkheads(repo._activebookmark)
+    bmheads = bookmarks.headsforactive(repo)
     curhead = repo[repo._activebookmark].node()
     if len(bmheads) == 2:
         if curhead == bmheads[0]:
@@ -355,7 +355,7 @@
     return None
 
 def _statusotherbook(ui, repo):
-    bmheads = repo.bookmarkheads(repo._activebookmark)
+    bmheads = bookmarks.headsforactive(repo)
     curhead = repo[repo._activebookmark].node()
     if repo.revs('%n and parents()', curhead):
         # we are on the active bookmark
--- a/mercurial/localrepo.py	Sat May 20 20:50:29 2017 -0400
+++ b/mercurial/localrepo.py	Thu May 18 16:43:56 2017 -0400
@@ -507,14 +507,6 @@
     def _activebookmark(self):
         return self._bookmarks.active
 
-    def bookmarkheads(self, bookmark):
-        name = bookmark.split('@', 1)[0]
-        heads = []
-        for mark, n in self._bookmarks.iteritems():
-            if mark.split('@', 1)[0] == name:
-                heads.append(n)
-        return heads
-
     # _phaserevs and _phasesets depend on changelog. what we need is to
     # call _phasecache.invalidate() if '00changelog.i' was changed, but it
     # can't be easily expressed in filecache mechanism.