[PATCH 4 of 9 RFC] localrepo: add a method to return markers in a namespace

Sean Farley sean.michael.farley at gmail.com
Sun Mar 30 18:09:02 CDT 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1396218396 18000
#      Sun Mar 30 17:26:36 2014 -0500
# Node ID 0c5c36fe392d9dfbc56ac466e312a62bdeb2bf93
# Parent  1bb668ecda482ee83f31d505c2094e6402668931
localrepo: add a method to return markers in a namespace

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -671,10 +671,37 @@ class localrepository(object):
         RFC: should we allow tags and bookmarks to be set this way?
         '''
         self._createmarkernamespace(namespace)
         self._markers[namespace][name] = node
 
+    def markers(self, namespace=None, name=None):
+        '''Return markers in the namespace, otherwise return all markers.
+
+        If namespace is None, this will return a dictionary of dictionaries.
+
+        If namespace is passed but name is None, this function will return a
+        dictionary.
+
+        If both namespace and name are passed, this will return a value.
+
+        RFC: should this allow namespace=None and name='foo' to find all 'foo'
+        no matter the namespace?
+        '''
+        if namespace is None:
+            # create a read-only copy that adds tags and bookmarks
+            allmarks = self._markers.copy()
+            allmarks["tag"] = self.tags()
+            allmarks["bookmark"] = self._bookmarks
+            return allmarks
+
+        self._createmarkernamespace(namespace)
+
+        if name is not None:
+            return self._markers[namespace][name]
+
+        return self._markers[namespace]
+
     def branchmap(self):
         '''returns a dictionary {branch: [branchheads]} with branchheads
         ordered by increasing revision number'''
         branchmap.updatecache(self)
         return self._branchcaches[self.filtername]


More information about the Mercurial-devel mailing list