[PATCH 6 of 8] namespaces: add bookmarks to the names data structure

Sean Farley sean.michael.farley at gmail.com
Sun Dec 14 18:37:54 CST 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1418590430 28800
#      Sun Dec 14 12:53:50 2014 -0800
# Node ID f00702f9fa2d70ae1bf8e246cf86e42f022afa06
# Parent  6571c7c1c58e8f2eaac936b32d2195863c7b6ab9
namespaces: add bookmarks to the names data structure

This marks the first use of abstracting our different types of named objects
(bookmarks, tags, branches, etc.) and upcoming patches will use this to
simplify logic.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -16,10 +16,11 @@ import match as matchmod
 import merge as mergemod
 import tags as tagsmod
 from lock import release
 import weakref, errno, os, time, inspect
 import branchmap, pathutil
+import namespaces
 propertycache = util.propertycache
 filecache = scmutil.filecache
 
 class repofilecache(filecache):
     """All filecache usage on repo are done for logic that should be unfiltered
@@ -295,10 +296,13 @@ class localrepository(object):
         # - new obsolescence marker,
         # - working directory parent change,
         # - bookmark changes
         self.filteredrevcache = {}
 
+        # generic mapping between names and nodes
+        self.names = namespaces.namespaces(self)
+
     def close(self):
         pass
 
     def _restrictcapabilities(self, caps):
         # bundle2 is not ready for prime time, drop it unless explicitly
diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
--- a/mercurial/namespaces.py
+++ b/mercurial/namespaces.py
@@ -44,10 +44,22 @@ class namespaces(object):
 
     def __init__(self, repo):
         self._names = util.sortdict()
         self._repo = weakref.ref(repo)
 
+        # shorten the method name
+        addns = self.addnamespace
+
+        # we need current mercurial named objects (bookmarks, tags, and
+        # branches) to be initialized somewhere, so that place is here
+        addns("bookmarks", "bookmark",
+              lambda repo: repo._bookmarks.keys(),
+              lambda repo, name: multify(repo._bookmarks.get(name)),
+              lambda repo, node: [name for name, n in
+                                  repo._bookmarks.iteritems()
+                                  if n == node])
+
     @property
     def repo(self):
         return self._repo()
 
     def addnamespace(self, namespace, singular, names, namemap, nodemap,


More information about the Mercurial-devel mailing list