Patchwork localrepo: extract bookmarkheads method to bookmarks.py

login
register
mail settings
Submitter Augie Fackler
Date May 20, 2017, 9:23 p.m.
Message ID <821f1d5ce5a641e7342c.1495315432@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/20778/
State Accepted
Headers show

Comments

Augie Fackler - May 20, 2017, 9:23 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1495140236 14400
#      Thu May 18 16:43:56 2017 -0400
# Node ID 821f1d5ce5a641e7342caffb245ec0a50b2c47f3
# Parent  f9d4dc738a3d3c20f745f815acbc239e469b08c7
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.
Yuya Nishihara - May 21, 2017, 3:59 a.m.
On Sat, 20 May 2017 17:23:52 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1495140236 14400
> #      Thu May 18 16:43:56 2017 -0400
> # Node ID 821f1d5ce5a641e7342caffb245ec0a50b2c47f3
> # Parent  f9d4dc738a3d3c20f745f815acbc239e469b08c7
> localrepo: extract bookmarkheads method to bookmarks.py

Looks good. Queued, thanks.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -226,6 +226,28 @@  def deletedivergent(repo, deletefrom, bm
                 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.'''
diff --git a/mercurial/destutil.py b/mercurial/destutil.py
--- a/mercurial/destutil.py
+++ b/mercurial/destutil.py
@@ -234,7 +234,7 @@  msgdestmerge = {
 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 @@  def desthistedit(ui, repo):
     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
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -507,14 +507,6 @@  class localrepository(object):
     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.