Patchwork [2,of,4] bookmarks: extract function that looks up bookmark names by node

login
register
mail settings
Submitter Yuya Nishihara
Date May 6, 2018, 2:53 a.m.
Message ID <81ee88150e0e71017a09.1525575225@mimosa>
Download mbox | patch
Permalink /patch/31273/
State Accepted
Headers show

Comments

Yuya Nishihara - May 6, 2018, 2:53 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1525487643 -32400
#      Sat May 05 11:34:03 2018 +0900
# Node ID 81ee88150e0e71017a099067dc164bd8b49071a2
# Parent  9441c66b21500860f669c7a190e81c55a219f703
bookmarks: extract function that looks up bookmark names by node

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -138,6 +138,14 @@  class bmstore(object):
         self._clean = False
         del self._refmap[key]
 
+    def names(self, node):
+        """Return a sorted list of bookmarks pointing to the specified node"""
+        marks = []
+        for m, n in self._refmap.iteritems():
+            if n == node:
+                marks.append(m)
+        return sorted(marks)
+
     def changectx(self, mark):
         node = self._refmap[mark]
         return self._repo[node]
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1029,11 +1029,7 @@  class localrepository(object):
 
     def nodebookmarks(self, node):
         """return the list of bookmarks pointing to the specified node"""
-        marks = []
-        for bookmark, n in self._bookmarks.iteritems():
-            if n == node:
-                marks.append(bookmark)
-        return sorted(marks)
+        return self._bookmarks.names(node)
 
     def branchmap(self):
         '''returns a dictionary {branch: [branchheads]} with branchheads