mercurial/namespaces.py
changeset 23760 50229b4c33be
parent 23739 b8b246cffdee
child 23761 19d6271a70db
equal deleted inserted replaced
23759:cdfc47266e53 23760:50229b4c33be
    26         ns = namespace
    26         ns = namespace
    27 
    27 
    28         # we need current mercurial named objects (bookmarks, tags, and
    28         # we need current mercurial named objects (bookmarks, tags, and
    29         # branches) to be initialized somewhere, so that place is here
    29         # branches) to be initialized somewhere, so that place is here
    30         n = ns("bookmarks", "bookmark",
    30         n = ns("bookmarks", "bookmark",
       
    31                lambda repo: repo._bookmarks.keys(),
    31                lambda repo, name: tolist(repo._bookmarks.get(name)),
    32                lambda repo, name: tolist(repo._bookmarks.get(name)),
    32                lambda repo, name: repo.nodebookmarks(name))
    33                lambda repo, name: repo.nodebookmarks(name))
    33         self.addnamespace(n)
    34         self.addnamespace(n)
    34 
    35 
    35         n = ns("tags", "tag",
    36         n = ns("tags", "tag",
       
    37                lambda repo: [t for t, n in repo.tagslist()],
    36                lambda repo, name: tolist(repo._tagscache.tags.get(name)),
    38                lambda repo, name: tolist(repo._tagscache.tags.get(name)),
    37                lambda repo, name: repo.nodetags(name))
    39                lambda repo, name: repo.nodetags(name))
    38         self.addnamespace(n)
    40         self.addnamespace(n)
    39 
    41 
    40         n = ns("branches", "branch",
    42         n = ns("branches", "branch",
       
    43                lambda repo: repo.branchmap().keys(),
    41                lambda repo, name: tolist(repo.branchtip(name)),
    44                lambda repo, name: tolist(repo.branchtip(name)),
    42                lambda repo, node: [repo[node].branch()])
    45                lambda repo, node: [repo[node].branch()])
    43         self.addnamespace(n)
    46         self.addnamespace(n)
    44 
    47 
    45     def __getitem__(self, namespace):
    48     def __getitem__(self, namespace):
   102 
   105 
   103     This namespace object will define the properties we need:
   106     This namespace object will define the properties we need:
   104       'name': the namespace (plural form)
   107       'name': the namespace (plural form)
   105       'templatename': name to use for templating (usually the singular form
   108       'templatename': name to use for templating (usually the singular form
   106                       of the plural namespace name)
   109                       of the plural namespace name)
       
   110       'listnames': list of all names in the namespace (usually the keys of a
       
   111                    dictionary)
   107       'namemap': function that takes a name and returns a list of nodes
   112       'namemap': function that takes a name and returns a list of nodes
   108       'nodemap': function that takes a node and returns a list of names
   113       'nodemap': function that takes a node and returns a list of names
   109 
   114 
   110     """
   115     """
   111 
   116 
   112     def __init__(self, name, templatename, namemap, nodemap):
   117     def __init__(self, name, templatename, listnames, namemap, nodemap):
   113         """create a namespace
   118         """create a namespace
   114 
   119 
   115         name: the namespace to be registered (in plural form)
   120         name: the namespace to be registered (in plural form)
       
   121         listnames: function to list all names
   116         templatename: the name to use for templating
   122         templatename: the name to use for templating
   117         namemap: function that inputs a node, output name(s)
   123         namemap: function that inputs a node, output name(s)
   118         nodemap: function that inputs a name, output node(s)
   124         nodemap: function that inputs a name, output node(s)
   119 
   125 
   120         """
   126         """
   121         self.name = name
   127         self.name = name
   122         self.templatename = templatename
   128         self.templatename = templatename
       
   129         self.listnames = listnames
   123         self.namemap = namemap
   130         self.namemap = namemap
   124         self.nodemap = nodemap
   131         self.nodemap = nodemap
   125 
   132 
   126     def names(self, repo, node):
   133     def names(self, repo, node):
   127         """method that returns a (sorted) list of names in a namespace that
   134         """method that returns a (sorted) list of names in a namespace that