Mercurial > hg
annotate hgext/remotenames.py @ 36919:8fba319750c2
dagop: move lines() out of annotate()
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 28 Feb 2018 15:20:41 -0500 |
parents | 121a20e5da56 |
children | 32f9b7e3f056 |
rev | line source |
---|---|
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
1 # remotenames.py - extension to display remotenames |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
2 # |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2017 Augie Fackler <raf@durin42.com> |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
4 # Copyright 2017 Sean Farley <sean@farley.io> |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
5 # |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
7 # GNU General Public License version 2 or any later version. |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
8 |
36062
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
9 """ showing remotebookmarks and remotebranches in UI |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
10 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
11 By default both remotebookmarks and remotebranches are turned on. Config knob to |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
12 control the individually are as follows. |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
13 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
14 Config options to tweak the default behaviour: |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
15 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
16 remotenames.bookmarks |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
17 Boolean value to enable or disable showing of remotebookmarks |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
18 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
19 remotenames.branches |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
20 Boolean value to enable or disable showing of remotebranches |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
21 """ |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
22 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
23 from __future__ import absolute_import |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
24 |
36252
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
25 import collections |
36061
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
26 |
36149
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
27 from mercurial.i18n import _ |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
28 |
36061
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
29 from mercurial.node import ( |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
30 bin, |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
31 ) |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
32 from mercurial import ( |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
33 logexchange, |
36062
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
34 namespaces, |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
35 registrar, |
36149
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
36 revsetlang, |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
37 smartset, |
36063
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
38 templatekw, |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
39 ) |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
40 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
41 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
42 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
43 # be specifying the version(s) of Mercurial they are tested with, or |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
44 # leave the attribute unspecified. |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
45 testedwith = 'ships-with-hg-core' |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
46 |
36062
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
47 configtable = {} |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
48 configitem = registrar.configitem(configtable) |
36063
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
49 templatekeyword = registrar.templatekeyword() |
36149
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
50 revsetpredicate = registrar.revsetpredicate() |
36062
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
51 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
52 configitem('remotenames', 'bookmarks', |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
53 default=True, |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
54 ) |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
55 configitem('remotenames', 'branches', |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
56 default=True, |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
57 ) |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
58 |
36252
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
59 class lazyremotenamedict(collections.MutableMapping): |
36061
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
60 """ |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
61 Read-only dict-like Class to lazily resolve remotename entries |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
62 |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
63 We are doing that because remotenames startup was slow. |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
64 We lazily read the remotenames file once to figure out the potential entries |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
65 and store them in self.potentialentries. Then when asked to resolve an |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
66 entry, if it is not in self.potentialentries, then it isn't there, if it |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
67 is in self.potentialentries we resolve it and store the result in |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
68 self.cache. We cannot be lazy is when asked all the entries (keys). |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
69 """ |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
70 def __init__(self, kind, repo): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
71 self.cache = {} |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
72 self.potentialentries = {} |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
73 self._kind = kind # bookmarks or branches |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
74 self._repo = repo |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
75 self.loaded = False |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
76 |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
77 def _load(self): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
78 """ Read the remotenames file, store entries matching selected kind """ |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
79 self.loaded = True |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
80 repo = self._repo |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
81 for node, rpath, rname in logexchange.readremotenamefile(repo, |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
82 self._kind): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
83 name = rpath + '/' + rname |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
84 self.potentialentries[name] = (node, rpath, name) |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
85 |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
86 def _resolvedata(self, potentialentry): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
87 """ Check that the node for potentialentry exists and return it """ |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
88 if not potentialentry in self.potentialentries: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
89 return None |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
90 node, remote, name = self.potentialentries[potentialentry] |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
91 repo = self._repo |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
92 binnode = bin(node) |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
93 # if the node doesn't exist, skip it |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
94 try: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
95 repo.changelog.rev(binnode) |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
96 except LookupError: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
97 return None |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
98 # Skip closed branches |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
99 if (self._kind == 'branches' and repo[binnode].closesbranch()): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
100 return None |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
101 return [binnode] |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
102 |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
103 def __getitem__(self, key): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
104 if not self.loaded: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
105 self._load() |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
106 val = self._fetchandcache(key) |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
107 if val is not None: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
108 return val |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
109 else: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
110 raise KeyError() |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
111 |
36252
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
112 def __iter__(self): |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
113 return iter(self.potentialentries) |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
114 |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
115 def __len__(self): |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
116 return len(self.potentialentries) |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
117 |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
118 def __setitem__(self): |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
119 raise NotImplementedError |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
120 |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
121 def __delitem__(self): |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
122 raise NotImplementedError |
e37be270e163
remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents:
36149
diff
changeset
|
123 |
36061
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
124 def _fetchandcache(self, key): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
125 if key in self.cache: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
126 return self.cache[key] |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
127 val = self._resolvedata(key) |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
128 if val is not None: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
129 self.cache[key] = val |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
130 return val |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
131 else: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
132 return None |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
133 |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
134 def keys(self): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
135 """ Get a list of bookmark or branch names """ |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
136 if not self.loaded: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
137 self._load() |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
138 return self.potentialentries.keys() |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
139 |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
140 def iteritems(self): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
141 """ Iterate over (name, node) tuples """ |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
142 |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
143 if not self.loaded: |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
144 self._load() |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
145 |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
146 for k, vtup in self.potentialentries.iteritems(): |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
147 yield (k, [bin(vtup[0])]) |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
148 |
36463
1bd132a021dd
remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36440
diff
changeset
|
149 class remotenames(object): |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
150 """ |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
151 This class encapsulates all the remotenames state. It also contains |
36061
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
152 methods to access that state in convenient ways. Remotenames are lazy |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
153 loaded. Whenever client code needs to ensure the freshest copy of |
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
154 remotenames, use the `clearnames` method to force an eventual load. |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
155 """ |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
156 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
157 def __init__(self, repo, *args): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
158 self._repo = repo |
36061
be72f6420f3c
remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36060
diff
changeset
|
159 self.clearnames() |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
160 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
161 def clearnames(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
162 """ Clear all remote names state """ |
36463
1bd132a021dd
remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36440
diff
changeset
|
163 self.bookmarks = lazyremotenamedict("bookmarks", self._repo) |
1bd132a021dd
remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36440
diff
changeset
|
164 self.branches = lazyremotenamedict("branches", self._repo) |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
165 self._invalidatecache() |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
166 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
167 def _invalidatecache(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
168 self._nodetobmarks = None |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
169 self._nodetobranch = None |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
170 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
171 def bmarktonodes(self): |
36463
1bd132a021dd
remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36440
diff
changeset
|
172 return self.bookmarks |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
173 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
174 def nodetobmarks(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
175 if not self._nodetobmarks: |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
176 bmarktonodes = self.bmarktonodes() |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
177 self._nodetobmarks = {} |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
178 for name, node in bmarktonodes.iteritems(): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
179 self._nodetobmarks.setdefault(node[0], []).append(name) |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
180 return self._nodetobmarks |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
181 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
182 def branchtonodes(self): |
36463
1bd132a021dd
remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36440
diff
changeset
|
183 return self.branches |
36060
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
184 |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
185 def nodetobranch(self): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
186 if not self._nodetobranch: |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
187 branchtonodes = self.branchtonodes() |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
188 self._nodetobranch = {} |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
189 for name, nodes in branchtonodes.iteritems(): |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
190 for node in nodes: |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
191 self._nodetobranch.setdefault(node, []).append(name) |
cabe8ef5c71e
remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
192 return self._nodetobranch |
36062
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
193 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
194 def reposetup(ui, repo): |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
195 if not repo.local(): |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
196 return |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
197 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
198 repo._remotenames = remotenames(repo) |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
199 ns = namespaces.namespace |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
200 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
201 if ui.configbool('remotenames', 'bookmarks'): |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
202 remotebookmarkns = ns( |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
203 'remotebookmarks', |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
204 templatename='remotebookmarks', |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
205 colorname='remotebookmark', |
36264
18e29c65bc5c
remotenames: don't use the default value of logfmt for namespaces
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36252
diff
changeset
|
206 logfmt='remote bookmark: %s\n', |
36062
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
207 listnames=lambda repo: repo._remotenames.bmarktonodes().keys(), |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
208 namemap=lambda repo, name: |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
209 repo._remotenames.bmarktonodes().get(name, []), |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
210 nodemap=lambda repo, node: |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
211 repo._remotenames.nodetobmarks().get(node, [])) |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
212 repo.names.addnamespace(remotebookmarkns) |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
213 |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
214 if ui.configbool('remotenames', 'branches'): |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
215 remotebranchns = ns( |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
216 'remotebranches', |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
217 templatename='remotebranches', |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
218 colorname='remotebranch', |
36264
18e29c65bc5c
remotenames: don't use the default value of logfmt for namespaces
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36252
diff
changeset
|
219 logfmt='remote branch: %s\n', |
36062
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
220 listnames = lambda repo: repo._remotenames.branchtonodes().keys(), |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
221 namemap = lambda repo, name: |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
222 repo._remotenames.branchtonodes().get(name, []), |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
223 nodemap = lambda repo, node: |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
224 repo._remotenames.nodetobranch().get(node, [])) |
382aefea8faf
remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36061
diff
changeset
|
225 repo.names.addnamespace(remotebranchns) |
36063
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
226 |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
227 @templatekeyword('remotenames', requires={'repo', 'ctx', 'templ'}) |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
228 def remotenameskw(context, mapping): |
36440
bb852a525633
remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents:
36264
diff
changeset
|
229 """List of strings. Remote names associated with the changeset.""" |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
230 repo = context.resource(mapping, 'repo') |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
231 ctx = context.resource(mapping, 'ctx') |
36063
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
232 |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
233 remotenames = [] |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
234 if 'remotebookmarks' in repo.names: |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
235 remotenames = repo.names['remotebookmarks'].names(repo, ctx.node()) |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
236 |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
237 if 'remotebranches' in repo.names: |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
238 remotenames += repo.names['remotebranches'].names(repo, ctx.node()) |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
239 |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
240 return templatekw.compatlist(context, mapping, 'remotename', remotenames, |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
241 plural='remotenames') |
36063
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
242 |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
243 @templatekeyword('remotebookmarks', requires={'repo', 'ctx', 'templ'}) |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
244 def remotebookmarkskw(context, mapping): |
36440
bb852a525633
remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents:
36264
diff
changeset
|
245 """List of strings. Remote bookmarks associated with the changeset.""" |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
246 repo = context.resource(mapping, 'repo') |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
247 ctx = context.resource(mapping, 'ctx') |
36063
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
248 |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
249 remotebmarks = [] |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
250 if 'remotebookmarks' in repo.names: |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
251 remotebmarks = repo.names['remotebookmarks'].names(repo, ctx.node()) |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
252 |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
253 return templatekw.compatlist(context, mapping, 'remotebookmark', |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
254 remotebmarks, plural='remotebookmarks') |
36063
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
255 |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
256 @templatekeyword('remotebranches', requires={'repo', 'ctx', 'templ'}) |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
257 def remotebrancheskw(context, mapping): |
36440
bb852a525633
remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents:
36264
diff
changeset
|
258 """List of strings. Remote branches associated with the changeset.""" |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
259 repo = context.resource(mapping, 'repo') |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
260 ctx = context.resource(mapping, 'ctx') |
36063
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
261 |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
262 remotebranches = [] |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
263 if 'remotebranches' in repo.names: |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
264 remotebranches = repo.names['remotebranches'].names(repo, ctx.node()) |
5a53af7d09aa
remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36062
diff
changeset
|
265 |
36591
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
266 return templatekw.compatlist(context, mapping, 'remotebranch', |
121a20e5da56
templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents:
36463
diff
changeset
|
267 remotebranches, plural='remotebranches') |
36149
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
268 |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
269 def _revsetutil(repo, subset, x, rtypes): |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
270 """utility function to return a set of revs based on the rtypes""" |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
271 |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
272 revs = set() |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
273 cl = repo.changelog |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
274 for rtype in rtypes: |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
275 if rtype in repo.names: |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
276 ns = repo.names[rtype] |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
277 for name in ns.listnames(repo): |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
278 revs.update(ns.nodes(repo, name)) |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
279 |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
280 results = (cl.rev(n) for n in revs if cl.hasnode(n)) |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
281 return subset & smartset.baseset(sorted(results)) |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
282 |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
283 @revsetpredicate('remotenames()') |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
284 def remotenamesrevset(repo, subset, x): |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
285 """All changesets which have a remotename on them.""" |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
286 revsetlang.getargs(x, 0, 0, _("remotenames takes no arguments")) |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
287 return _revsetutil(repo, subset, x, ('remotebookmarks', 'remotebranches')) |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
288 |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
289 @revsetpredicate('remotebranches()') |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
290 def remotebranchesrevset(repo, subset, x): |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
291 """All changesets which are branch heads on remotes.""" |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
292 revsetlang.getargs(x, 0, 0, _("remotebranches takes no arguments")) |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
293 return _revsetutil(repo, subset, x, ('remotebranches',)) |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
294 |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
295 @revsetpredicate('remotebookmarks()') |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
296 def remotebmarksrevset(repo, subset, x): |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
297 """All changesets which have bookmarks on remotes.""" |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
298 revsetlang.getargs(x, 0, 0, _("remotebookmarks takes no arguments")) |
828f44cdfee3
remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36063
diff
changeset
|
299 return _revsetutil(repo, subset, x, ('remotebookmarks',)) |