Patchwork [5,of,9,RFC] localrepo: add a method to return markers associated with a node

login
register
mail settings
Submitter Sean Farley
Date March 30, 2014, 11:09 p.m.
Message ID <edf2cf8e1b4ba5796c8c.1396220943@laptop.local>
Download mbox | patch
Permalink /patch/4152/
State Deferred
Headers show

Comments

Sean Farley - March 30, 2014, 11:09 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1396218441 18000
#      Sun Mar 30 17:27:21 2014 -0500
# Node ID edf2cf8e1b4ba5796c8cec04956b0e080c089862
# Parent  0c5c36fe392d9dfbc56ac466e312a62bdeb2bf93
localrepo: add a method to return markers associated with a node

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -698,10 +698,38 @@  class localrepository(object):
         if name is not None:
             return self._markers[namespace][name]
 
         return self._markers[namespace]
 
+    def nodemarkers(self, node, namespace=None):
+        '''Return all markers (sorted) associated with a node optionally filtered by
+        namespace.
+
+        If namespace is passed, then this will return a sorted list of just the
+        names.
+        '''
+
+        # can't use a dictioniary because the result need to be sorted
+        nm = []
+        if namespace is None:
+            # singular name
+            nm.extend((b, 'bookmark') for b in self.nodebookmarks(node))
+            nm.extend((t, 'tag') for t in self.nodetags(node))
+
+            for marktype, data in self._markers.iteritems():
+                nm.extend((name, marktype) for name, n in data.iteritems()
+                if n == node)
+
+            # sort by type of mark, then by name
+            nm = sorted(nm, key=lambda tup: (tup[1], tup[0]))
+        else:
+            nm.extend(name for name, n in self.markers(namespace).iteritems()
+                      if n == node)
+            nm = sorted(nm)
+
+        return nm
+
     def branchmap(self):
         '''returns a dictionary {branch: [branchheads]} with branchheads
         ordered by increasing revision number'''
         branchmap.updatecache(self)
         return self._branchcaches[self.filtername]