Patchwork [04,of,12] localrepo: add a method to return labels in a namespace

login
register
mail settings
Submitter Sean Farley
Date Aug. 18, 2014, 9:18 p.m.
Message ID <0caba51170dc885e485d.1408396680@1.0.0.127.in-addr.arpa>
Download mbox | patch
Permalink /patch/5462/
State Changes Requested
Headers show

Comments

Sean Farley - Aug. 18, 2014, 9:18 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1396218396 18000
#      Sun Mar 30 17:26:36 2014 -0500
# Node ID 0caba51170dc885e485d1e159aabfc8d2e17efda
# Parent  8d39822184e18921690163fb4b5464e53d74f620
localrepo: add a method to return labels in a namespace

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -718,10 +718,25 @@  class localrepository(object):
     def label(self, namespace, name, node):
         '''Add a label to self._labels[namespace][name]'''
         self._createlabelnamespace(namespace)
         self._labels[namespace][name] = node
 
+    def labels(self, namespace):
+        '''Return a dictionary of labels in the namespace.
+
+        This also allows accessing bookmarks and tags.
+        '''
+        if namespace == "bookmarks":
+            return self._bookmarks
+
+        if namespace == "tags":
+            return self.tags()
+
+        # if the namespace doesn't exist, then we initialize it
+        self._createlabelnamespace(namespace)
+        return self._labels[namespace]
+
     def branchmap(self):
         '''returns a dictionary {branch: [branchheads]} with branchheads
         ordered by increasing revision number'''
         branchmap.updatecache(self)
         return self._branchcaches[self.filtername]