bookmarks: extract function that looks up bookmark names by node
authorYuya Nishihara <yuya@tcha.org>
Sat, 05 May 2018 11:34:03 +0900
changeset 37848 6e2259847f5f
parent 37847 8256962e798c
child 37849 82a153e6dc4a
bookmarks: extract function that looks up bookmark names by node
mercurial/bookmarks.py
mercurial/localrepo.py
--- a/mercurial/bookmarks.py	Sat May 05 11:21:41 2018 +0900
+++ b/mercurial/bookmarks.py	Sat May 05 11:34:03 2018 +0900
@@ -138,6 +138,14 @@
         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]
--- a/mercurial/localrepo.py	Sat May 05 11:21:41 2018 +0900
+++ b/mercurial/localrepo.py	Sat May 05 11:34:03 2018 +0900
@@ -1029,11 +1029,7 @@
 
     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