annotate mercurial/namespaces.py @ 23553:7cebb6a8c75f

namespaces: introduce a generic way to map between names and nodes This patch begins the work to provide a way to register a namespace to handle 'names'. Benefits of this would be, - improved templating: This would provide {name} which could output any branch, bookmark, tag, or any extension registered namespace all without having the extension doing any extra work - improved tab completion: Since this provides a single source of all 'names', tab completion would not need to know of each namespace - changeset lookup: Similar to before, a unified place to get all 'names' will allow finding changesets without any extension code having to reimplement this Also, d226fe36e362 has shown us that for internal code which expects a certain type of method or behavior, we should provide an easy way for extensions to check this behavior.
author Sean Farley <sean.michael.farley@gmail.com>
date Sun, 14 Dec 2014 12:29:28 -0800
parents
children 75f9643cab1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23553
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
1 from mercurial import util
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
2
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
3 class namespaces(object):
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
4 """
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
5 provides an interface to register a generic many-to-many mapping between
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
6 some (namespaced) names and nodes. The goal here is to control the
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
7 pollution of jamming things into tags or bookmarks (in extension-land) and
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
8 to simplify internal bits of mercurial: log output, tab completion, etc.
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
9
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
10 More precisely, we define a list of names (the namespace) and a mapping of
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
11 names to nodes. This name mapping returns a list of nodes.
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
12
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
13 Furthermore, each name mapping will be passed a name to lookup which might
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
14 not be in its domain. In this case, each method should return an empty list
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
15 and not raise an error.
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
16
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
17 We'll have a dictionary '_names' where each key is a namespace and
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
18 its value is a dictionary of functions:
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
19 'namemap': function that takes a name and returns a list of nodes
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
20 """
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
21
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
22 _names_version = 0
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
23
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
24 def __init__(self):
7cebb6a8c75f namespaces: introduce a generic way to map between names and nodes
Sean Farley <sean.michael.farley@gmail.com>
parents:
diff changeset
25 self._names = util.sortdict()