annotate hgext/remotenames.py @ 48536:8537a64c4e2b stable

Added tag 6.0.1 for changeset 799fdf4cca80
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 05 Jan 2022 17:53:03 +0100
parents f38bf44e077f
children 6000f5b25c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
37817
678ab0de7296 remotenames: mark the extension as EXPERIMENTAL
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37090
diff changeset
9 """ showing remotebookmarks and remotebranches in UI (EXPERIMENTAL)
36062
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
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
17 Boolean value to enable or disable showing of remotebookmarks (default: True)
36062
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
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
20 Boolean value to enable or disable showing of remotebranches (default: True)
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
21
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
22 remotenames.hoistedpeer
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
23 Name of the peer whose remotebookmarks should be hoisted into the top-level
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
24 namespace (default: 'default')
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
25 """
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
26
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
27 from __future__ import absolute_import
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
28
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
29 from mercurial.i18n import _
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
30
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
31 from mercurial.node import bin
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
32 from mercurial import (
37090
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
33 bookmarks,
40069
fd4d59cf2ebb remotenames: abort if literal revset pattern matches nothing
Yuya Nishihara <yuya@tcha.org>
parents: 40068
diff changeset
34 error,
37090
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
35 extensions,
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
36 logexchange,
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
37 namespaces,
36956
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
38 pycompat,
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
39 registrar,
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
40 revsetlang,
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
41 smartset,
36921
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36591
diff changeset
42 templateutil,
40066
fe64178103b7 remotenames: use util.always instead of handcrafted lambda
Yuya Nishihara <yuya@tcha.org>
parents: 40065
diff changeset
43 util,
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
44 )
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
45
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
46 from mercurial.utils import stringutil
40059
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
47
36956
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
48 if pycompat.ispy3:
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
49 import collections.abc
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
50
36956
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
51 mutablemapping = collections.abc.MutableMapping
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
52 else:
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
53 import collections
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
54
36956
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
55 mutablemapping = collections.MutableMapping
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
56
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
57 # 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
58 # 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
59 # 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
60 # leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
61 testedwith = b'ships-with-hg-core'
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
62
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
63 configtable = {}
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
64 configitem = registrar.configitem(configtable)
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
65 templatekeyword = registrar.templatekeyword()
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
66 revsetpredicate = registrar.revsetpredicate()
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
67
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
68 configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
69 b'remotenames',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
70 b'bookmarks',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
71 default=True,
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
72 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
73 configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
74 b'remotenames',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
75 b'branches',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
76 default=True,
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
77 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
78 configitem(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
79 b'remotenames',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
80 b'hoistedpeer',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 43105
diff changeset
81 default=b'default',
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
82 )
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
83
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
84
36956
b710fdebd0db remotenames: work around move of ABCs in collections
Augie Fackler <augie@google.com>
parents: 36921
diff changeset
85 class lazyremotenamedict(mutablemapping):
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
86 """
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
87 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
88
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
89 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
90 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
91 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
92 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
93 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
94 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
95 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
96
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
97 def __init__(self, kind, repo):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
98 self.cache = {}
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
99 self.potentialentries = {}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
100 self._kind = kind # bookmarks or branches
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
101 self._repo = repo
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
102 self.loaded = False
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
103
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
104 def _load(self):
47062
f38bf44e077f black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents: 45942
diff changeset
105 """Read the remotenames file, store entries matching selected kind"""
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
106 self.loaded = True
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
107 repo = self._repo
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
108 for node, rpath, rname in logexchange.readremotenamefile(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
109 repo, self._kind
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
110 ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
111 name = rpath + b'/' + rname
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
112 self.potentialentries[name] = (node, rpath, name)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
113
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
114 def _resolvedata(self, potentialentry):
47062
f38bf44e077f black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents: 45942
diff changeset
115 """Check that the node for potentialentry exists and return it"""
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
116 if not potentialentry in self.potentialentries:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
117 return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
118 node, remote, name = self.potentialentries[potentialentry]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
119 repo = self._repo
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
120 binnode = bin(node)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
121 # 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
122 try:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
123 repo.changelog.rev(binnode)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
124 except LookupError:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
125 return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
126 # Skip closed branches
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
127 if self._kind == b'branches' and repo[binnode].closesbranch():
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
128 return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
129 return [binnode]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
130
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
131 def __getitem__(self, key):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
132 if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
133 self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
134 val = self._fetchandcache(key)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
135 if val is not None:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
136 return val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
137 else:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
138 raise KeyError()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
139
36252
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
140 def __iter__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
141 return iter(self.potentialentries)
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
142
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
143 def __len__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
144 return len(self.potentialentries)
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
145
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
146 def __setitem__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
147 raise NotImplementedError
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
148
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
149 def __delitem__(self):
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
150 raise NotImplementedError
e37be270e163 remotenames: port partway to python3 by using collections.MutableMapping
Augie Fackler <augie@google.com>
parents: 36149
diff changeset
151
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
152 def _fetchandcache(self, key):
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
153 if key in self.cache:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
154 return self.cache[key]
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
155 val = self._resolvedata(key)
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
156 if val is not None:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
157 self.cache[key] = val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
158 return val
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
159 else:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
160 return None
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
161
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
162 def keys(self):
47062
f38bf44e077f black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents: 45942
diff changeset
163 """Get a list of bookmark or branch names"""
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
164 if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
165 self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
166 return self.potentialentries.keys()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
167
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
168 def iteritems(self):
47062
f38bf44e077f black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents: 45942
diff changeset
169 """Iterate over (name, node) tuples"""
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
170
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
171 if not self.loaded:
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
172 self._load()
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
173
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
174 for k, vtup in pycompat.iteritems(self.potentialentries):
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
175 yield (k, [bin(vtup[0])])
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
176
42603
3018749a71bb py3: source-transform only call-sites of iteritems(), not definitions
Martin von Zweigbergk <martinvonz@google.com>
parents: 40069
diff changeset
177 items = iteritems
3018749a71bb py3: source-transform only call-sites of iteritems(), not definitions
Martin von Zweigbergk <martinvonz@google.com>
parents: 40069
diff changeset
178
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
179
36463
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36440
diff changeset
180 class remotenames(object):
36060
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 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
183 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
184 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
185 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
186 """
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
187
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
188 def __init__(self, repo, *args):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
189 self._repo = repo
36061
be72f6420f3c remotenames: introduce a class to lazily resolve remotnames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36060
diff changeset
190 self.clearnames()
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
191
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
192 def clearnames(self):
47062
f38bf44e077f black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents: 45942
diff changeset
193 """Clear all remote names state"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
194 self.bookmarks = lazyremotenamedict(b"bookmarks", self._repo)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
195 self.branches = lazyremotenamedict(b"branches", self._repo)
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
196 self._invalidatecache()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
197
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
198 def _invalidatecache(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
199 self._nodetobmarks = None
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
200 self._nodetobranch = None
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
201 self._hoisttonodes = None
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
202 self._nodetohoists = None
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
203
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
204 def bmarktonodes(self):
36463
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36440
diff changeset
205 return self.bookmarks
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
206
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
207 def nodetobmarks(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
208 if not self._nodetobmarks:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
209 bmarktonodes = self.bmarktonodes()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
210 self._nodetobmarks = {}
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
211 for name, node in pycompat.iteritems(bmarktonodes):
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
212 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
213 return self._nodetobmarks
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
214
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
215 def branchtonodes(self):
36463
1bd132a021dd remotenames: don't inherit the remotenames class from dict class
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36440
diff changeset
216 return self.branches
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
217
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
218 def nodetobranch(self):
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
219 if not self._nodetobranch:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
220 branchtonodes = self.branchtonodes()
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
221 self._nodetobranch = {}
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
222 for name, nodes in pycompat.iteritems(branchtonodes):
36060
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
223 for node in nodes:
cabe8ef5c71e remotenames: introduce class to encapsulate remotenames info in an extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff changeset
224 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
225 return self._nodetobranch
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
226
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
227 def hoisttonodes(self, hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
228 if not self._hoisttonodes:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
229 marktonodes = self.bmarktonodes()
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
230 self._hoisttonodes = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
231 hoist += b'/'
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
232 for name, node in pycompat.iteritems(marktonodes):
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
233 if name.startswith(hoist):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
234 name = name[len(hoist) :]
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
235 self._hoisttonodes[name] = node
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
236 return self._hoisttonodes
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
237
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
238 def nodetohoists(self, hoist):
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
239 if not self._nodetohoists:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
240 marktonodes = self.bmarktonodes()
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
241 self._nodetohoists = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
242 hoist += b'/'
43105
649d3ac37a12 py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
243 for name, node in pycompat.iteritems(marktonodes):
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
244 if name.startswith(hoist):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
245 name = name[len(hoist) :]
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
246 self._nodetohoists.setdefault(node[0], []).append(name)
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
247 return self._nodetohoists
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
248
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
249
39746
25cc5616adc9 bookmarks: pass in formatter to printbookmarks() instead of opts (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37983
diff changeset
250 def wrapprintbookmarks(orig, ui, repo, fm, bmarks):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
251 if b'remotebookmarks' not in repo.names:
37090
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
252 return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
253 ns = repo.names[b'remotebookmarks']
37090
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
254
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
255 for name in ns.listnames(repo):
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
256 nodes = ns.nodes(repo, name)
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
257 if not nodes:
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
258 continue
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
259 node = nodes[0]
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
260
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
261 bmarks[name] = (node, b' ', b'')
37090
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
262
39746
25cc5616adc9 bookmarks: pass in formatter to printbookmarks() instead of opts (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37983
diff changeset
263 return orig(ui, repo, fm, bmarks)
37090
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
264
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
265
37090
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
266 def extsetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
267 extensions.wrapfunction(bookmarks, b'_printbookmarks', wrapprintbookmarks)
37090
a61fff493d98 remotenames: show remote bookmarks in `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37089
diff changeset
268
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
269
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
270 def reposetup(ui, repo):
37983
b9e6b71dc272 remotenames: enable the storage config option if extension is enabled
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37817
diff changeset
271
b9e6b71dc272 remotenames: enable the storage config option if extension is enabled
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37817
diff changeset
272 # set the config option to store remotenames
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
273 repo.ui.setconfig(b'experimental', b'remotenames', True, b'remotenames-ext')
37983
b9e6b71dc272 remotenames: enable the storage config option if extension is enabled
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37817
diff changeset
274
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
275 if not repo.local():
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
276 return
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
277
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
278 repo._remotenames = remotenames(repo)
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
279 ns = namespaces.namespace
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
280
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
281 if ui.configbool(b'remotenames', b'bookmarks'):
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
282 remotebookmarkns = ns(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
283 b'remotebookmarks',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
284 templatename=b'remotebookmarks',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
285 colorname=b'remotebookmark',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
286 logfmt=b'remote bookmark: %s\n',
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
287 listnames=lambda repo: repo._remotenames.bmarktonodes().keys(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
288 namemap=lambda repo, name: repo._remotenames.bmarktonodes().get(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
289 name, []
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
290 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
291 nodemap=lambda repo, node: repo._remotenames.nodetobmarks().get(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
292 node, []
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
293 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
294 )
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
295 repo.names.addnamespace(remotebookmarkns)
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
296
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
297 # hoisting only works if there are remote bookmarks
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
298 hoist = ui.config(b'remotenames', b'hoistedpeer')
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
299 if hoist:
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
300 hoistednamens = ns(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
301 b'hoistednames',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
302 templatename=b'hoistednames',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
303 colorname=b'hoistedname',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
304 logfmt=b'hoisted name: %s\n',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
305 listnames=lambda repo: repo._remotenames.hoisttonodes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
306 hoist
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
307 ).keys(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
308 namemap=lambda repo, name: repo._remotenames.hoisttonodes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
309 hoist
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
310 ).get(name, []),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
311 nodemap=lambda repo, node: repo._remotenames.nodetohoists(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
312 hoist
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
313 ).get(node, []),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
314 )
37089
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
315 repo.names.addnamespace(hoistednamens)
9938992c5bae remotenames: add functionality to hoist remotebookmarks
Pulkit Goyal <7895pulkit@gmail.com>
parents: 37068
diff changeset
316
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
317 if ui.configbool(b'remotenames', b'branches'):
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
318 remotebranchns = ns(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
319 b'remotebranches',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
320 templatename=b'remotebranches',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
321 colorname=b'remotebranch',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
322 logfmt=b'remote branch: %s\n',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
323 listnames=lambda repo: repo._remotenames.branchtonodes().keys(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
324 namemap=lambda repo, name: repo._remotenames.branchtonodes().get(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
325 name, []
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
326 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
327 nodemap=lambda repo, node: repo._remotenames.nodetobranch().get(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
328 node, []
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
329 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
330 )
36062
382aefea8faf remotenames: add new namespaces for remotebookmarks and remotebranches
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36061
diff changeset
331 repo.names.addnamespace(remotebranchns)
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
332
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
333
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
334 @templatekeyword(b'remotenames', requires={b'repo', b'ctx'})
36591
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36463
diff changeset
335 def remotenameskw(context, mapping):
36440
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36264
diff changeset
336 """List of strings. Remote names associated with the changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
337 repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
338 ctx = context.resource(mapping, b'ctx')
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
339
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
340 remotenames = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
341 if b'remotebookmarks' in repo.names:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
342 remotenames = repo.names[b'remotebookmarks'].names(repo, ctx.node())
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
343
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
344 if b'remotebranches' in repo.names:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
345 remotenames += repo.names[b'remotebranches'].names(repo, ctx.node())
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
346
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
347 return templateutil.compatlist(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
348 context, mapping, b'remotename', remotenames, plural=b'remotenames'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
349 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
350
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
351
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
352 @templatekeyword(b'remotebookmarks', requires={b'repo', b'ctx'})
36591
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36463
diff changeset
353 def remotebookmarkskw(context, mapping):
36440
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36264
diff changeset
354 """List of strings. Remote bookmarks associated with the changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
355 repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
356 ctx = context.resource(mapping, b'ctx')
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
357
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
358 remotebmarks = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
359 if b'remotebookmarks' in repo.names:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
360 remotebmarks = repo.names[b'remotebookmarks'].names(repo, ctx.node())
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
361
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
362 return templateutil.compatlist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
363 context,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
364 mapping,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
365 b'remotebookmark',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
366 remotebmarks,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
367 plural=b'remotebookmarks',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
368 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
369
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
370
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
371 @templatekeyword(b'remotebranches', requires={b'repo', b'ctx'})
36591
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36463
diff changeset
372 def remotebrancheskw(context, mapping):
36440
bb852a525633 remotenames: drop redundant templatekw names from help text
Yuya Nishihara <yuya@tcha.org>
parents: 36264
diff changeset
373 """List of strings. Remote branches associated with the changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
374 repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
375 ctx = context.resource(mapping, b'ctx')
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
376
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
377 remotebranches = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
378 if b'remotebranches' in repo.names:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
379 remotebranches = repo.names[b'remotebranches'].names(repo, ctx.node())
36063
5a53af7d09aa remotenames: introduce new template keywords for remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36062
diff changeset
380
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
381 return templateutil.compatlist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
382 context,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
383 mapping,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
384 b'remotebranch',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
385 remotebranches,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
386 plural=b'remotebranches',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
387 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
388
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
389
40065
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40060
diff changeset
390 def _revsetutil(repo, subset, x, rtypes):
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
391 """utility function to return a set of revs based on the rtypes"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
392 args = revsetlang.getargs(x, 0, 1, _(b'only one argument accepted'))
40065
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40060
diff changeset
393 if args:
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40060
diff changeset
394 kind, pattern, matcher = stringutil.stringmatcher(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
395 revsetlang.getstring(args[0], _(b'argument must be a string'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
396 )
40065
25533575d04e remotenames: inline _parseargs() into _revsetutil()
Yuya Nishihara <yuya@tcha.org>
parents: 40060
diff changeset
397 else:
40069
fd4d59cf2ebb remotenames: abort if literal revset pattern matches nothing
Yuya Nishihara <yuya@tcha.org>
parents: 40068
diff changeset
398 kind = pattern = None
40066
fe64178103b7 remotenames: use util.always instead of handcrafted lambda
Yuya Nishihara <yuya@tcha.org>
parents: 40065
diff changeset
399 matcher = util.always
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
400
40067
fba7428a0ef9 remotenames: don't call a set of nodes as "revs"
Yuya Nishihara <yuya@tcha.org>
parents: 40066
diff changeset
401 nodes = set()
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
402 cl = repo.changelog
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
403 for rtype in rtypes:
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
404 if rtype in repo.names:
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
405 ns = repo.names[rtype]
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
406 for name in ns.listnames(repo):
40060
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40059
diff changeset
407 if not matcher(name):
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40059
diff changeset
408 continue
40067
fba7428a0ef9 remotenames: don't call a set of nodes as "revs"
Yuya Nishihara <yuya@tcha.org>
parents: 40066
diff changeset
409 nodes.update(ns.nodes(repo, name))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
410 if kind == b'literal' and not nodes:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
411 raise error.RepoLookupError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
412 _(b"remote name '%s' does not exist") % pattern
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
413 )
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
414
40067
fba7428a0ef9 remotenames: don't call a set of nodes as "revs"
Yuya Nishihara <yuya@tcha.org>
parents: 40066
diff changeset
415 revs = (cl.rev(n) for n in nodes if cl.hasnode(n))
40068
b313f2c3b8c6 remotenames: remove unneeded sorted() from revset implementation
Yuya Nishihara <yuya@tcha.org>
parents: 40067
diff changeset
416 return subset & smartset.baseset(revs)
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
417
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
418
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
419 @revsetpredicate(b'remotenames([name])')
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
420 def remotenamesrevset(repo, subset, x):
40060
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40059
diff changeset
421 """All changesets which have a remotename on them. If `name` is
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40059
diff changeset
422 specified, only remotenames of matching remote paths are considered.
40059
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
423
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
424 Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
425 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
426 return _revsetutil(repo, subset, x, (b'remotebookmarks', b'remotebranches'))
40059
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
427
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
428
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
429 @revsetpredicate(b'remotebranches([name])')
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
430 def remotebranchesrevset(repo, subset, x):
40060
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40059
diff changeset
431 """All changesets which are branch heads on remotes. If `name` is
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40059
diff changeset
432 specified, only remotenames of matching remote paths are considered.
40059
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
433
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
434 Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
435 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
436 return _revsetutil(repo, subset, x, (b'remotebranches',))
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
437
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42603
diff changeset
438
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
439 @revsetpredicate(b'remotebookmarks([name])')
36149
828f44cdfee3 remotenames: add three new revsets related to remotenames
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36063
diff changeset
440 def remotebmarksrevset(repo, subset, x):
40060
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40059
diff changeset
441 """All changesets which have bookmarks on remotes. If `name` is
6346e21eecc8 remotenames: follow-up on D3639 to make revset funcs take only one arg
Augie Fackler <raf@durin42.com>
parents: 40059
diff changeset
442 specified, only remotenames of matching remote paths are considered.
40059
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
443
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
444 Pattern matching is supported for `name`. See :hg:`help revisions.patterns`.
fda1df3d4e06 remotenames: add names argument to remotenames revset
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39746
diff changeset
445 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
446 return _revsetutil(repo, subset, x, (b'remotebookmarks',))