Patchwork [2,of,5] namespaces: use named args for namespace api

login
register
mail settings
Submitter Sean Farley
Date Jan. 15, 2015, 6:58 a.m.
Message ID <eb89945cb5f4535e5f8d.1421305098@laptop.local>
Download mbox | patch
Permalink /patch/7469/
State Accepted
Headers show

Comments

Sean Farley - Jan. 15, 2015, 6:58 a.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1421294120 28800
#      Wed Jan 14 19:55:20 2015 -0800
# Node ID eb89945cb5f4535e5f8d3f2dfc9935f864291de2
# Parent  e2309aabdb6e67fc9eb0082917b6d79c8798cfbf
namespaces: use named args for namespace api

This is just a style change but makes adding new arguments more robust for
callers.

Patch

diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py
--- a/mercurial/namespaces.py
+++ b/mercurial/namespaces.py
@@ -20,31 +20,31 @@  class namespaces(object):
     _names_version = 0
 
     def __init__(self):
         self._names = util.sortdict()
 
-        # shorten the class name for less indentation
-        ns = namespace
-
         # we need current mercurial named objects (bookmarks, tags, and
         # branches) to be initialized somewhere, so that place is here
-        n = ns("bookmarks", "bookmark",
-               lambda repo: repo._bookmarks.keys(),
-               lambda repo, name: tolist(repo._bookmarks.get(name)),
-               lambda repo, name: repo.nodebookmarks(name))
+        bmknames = lambda repo: repo._bookmarks.keys()
+        bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name))
+        bmknodemap = lambda repo, name: repo.nodebookmarks(name)
+        n = namespace("bookmarks", templatename="bookmark", listnames=bmknames,
+                      namemap=bmknamemap, nodemap=bmknodemap)
         self.addnamespace(n)
 
-        n = ns("tags", "tag",
-               lambda repo: [t for t, n in repo.tagslist()],
-               lambda repo, name: tolist(repo._tagscache.tags.get(name)),
-               lambda repo, name: repo.nodetags(name))
+        tagnames = lambda repo: [t for t, n in repo.tagslist()]
+        tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name))
+        tagnodemap = lambda repo, name: repo.nodetags(name)
+        n = namespace("tags", templatename="tag", listnames=tagnames,
+                      namemap=tagnamemap, nodemap=tagnodemap)
         self.addnamespace(n)
 
-        n = ns("branches", "branch",
-               lambda repo: repo.branchmap().keys(),
-               lambda repo, name: tolist(repo.branchtip(name, True)),
-               lambda repo, node: [repo[node].branch()])
+        bnames = lambda repo: repo.branchmap().keys()
+        bnamemap = lambda repo, name: tolist(repo.branchtip(name, True))
+        bnodemap = lambda repo, node: [repo[node].branch()]
+        n = namespace("branches", templatename="branch", listnames=bnames,
+                      namemap=bnamemap, nodemap=bnodemap)
         self.addnamespace(n)
 
     def __getitem__(self, namespace):
         """returns the namespace object"""
         return self._names[namespace]
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -1565,16 +1565,17 @@  Check that adding an arbitrary name show
   > """A small extension to test adding arbitrary names to a repo"""
   > from mercurial.namespaces import namespace
   > 
   > def reposetup(ui, repo):
   >     foo = {'foo': repo[0].node()}
-  >     ns = namespace("bars", "bar",
-  >                    lambda r: foo.keys(),
-  >                    lambda r, name: foo.get(name),
-  >                    lambda r, node: [name for name, n
-  >                                     in foo.iteritems()
-  >                                     if n == node])
+  >     names = lambda r: foo.keys()
+  >     namemap = lambda r, name: foo.get(name)
+  >     nodemap = lambda r, node: [name for name, n in foo.iteritems()
+  >                                if n == node]
+  >     ns = namespace("bars", templatename="bar", listnames=names,
+  >                    namemap=namemap, nodemap=nodemap)
+  > 
   >     repo.names.addnamespace(ns)
   > EOF
 
   $ hg --config extensions.names=../names.py log -r 0
   changeset:   0:65624cd9070a