comparison mercurial/namespaces.py @ 23605:4c4c967814ef

namespaces: add template name of a namespace The template name property will be used in upcoming patches to automatically generate a template keyword. For example, given a namespace called 'babars', we will automatically generate a template keyword 'babar' such that we can use it in the following way, $ hg log -r . -T '{babars % "King: {babar}\n"}'
author Sean Farley <sean.michael.farley@gmail.com>
date Mon, 15 Dec 2014 00:09:52 -0800
parents 114992041625
children 80e3cbe227d1
comparison
equal deleted inserted replaced
23604:bb304f9b05d0 23605:4c4c967814ef
24 not be in its domain. In this case, each method should return an empty list 24 not be in its domain. In this case, each method should return an empty list
25 and not raise an error. 25 and not raise an error.
26 26
27 We'll have a dictionary '_names' where each key is a namespace and 27 We'll have a dictionary '_names' where each key is a namespace and
28 its value is a dictionary of functions: 28 its value is a dictionary of functions:
29 'templatename': name to use for templating (usually the singular form
30 of the plural namespace name)
29 'namemap': function that takes a name and returns a list of nodes 31 'namemap': function that takes a name and returns a list of nodes
30 """ 32 """
31 33
32 _names_version = 0 34 _names_version = 0
33 35
36 38
37 addns = self.addnamespace 39 addns = self.addnamespace
38 40
39 # we need current mercurial named objects (bookmarks, tags, and 41 # we need current mercurial named objects (bookmarks, tags, and
40 # branches) to be initialized somewhere, so that place is here 42 # branches) to be initialized somewhere, so that place is here
41 addns("bookmarks", 43 addns("bookmarks", "bookmark",
42 lambda repo, name: tolist(repo._bookmarks.get(name))) 44 lambda repo, name: tolist(repo._bookmarks.get(name)))
43 45
44 addns("tags", 46 addns("tags", "tag",
45 lambda repo, name: tolist(repo._tagscache.tags.get(name))) 47 lambda repo, name: tolist(repo._tagscache.tags.get(name)))
46 48
47 addns("branches", 49 addns("branches", "branch",
48 lambda repo, name: tolist(repo.branchtip(name))) 50 lambda repo, name: tolist(repo.branchtip(name)))
49 51
50 def addnamespace(self, namespace, namemap, order=None): 52 def addnamespace(self, namespace, templatename, namemap, order=None):
51 """ 53 """
52 register a namespace 54 register a namespace
53 55
54 namespace: the name to be registered (in plural form) 56 namespace: the name to be registered (in plural form)
57 templatename: the name to use for templating
55 namemap: function that inputs a node, output name(s) 58 namemap: function that inputs a node, output name(s)
56 order: optional argument to specify the order of namespaces 59 order: optional argument to specify the order of namespaces
57 (e.g. 'branches' should be listed before 'bookmarks') 60 (e.g. 'branches' should be listed before 'bookmarks')
58 """ 61 """
59 val = {'namemap': namemap} 62 val = {'templatename': templatename,
63 'namemap': namemap}
60 if order is not None: 64 if order is not None:
61 self._names.insert(order, namespace, val) 65 self._names.insert(order, namespace, val)
62 else: 66 else:
63 self._names[namespace] = val 67 self._names[namespace] = val
64 68