Mercurial > public > mercurial-scm > hg
diff hgext/remotenames.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 3018749a71bb |
children | 687b865b95ad |
line wrap: on
line diff
--- a/hgext/remotenames.py Sat Oct 05 10:29:34 2019 -0400 +++ b/hgext/remotenames.py Sun Oct 06 09:45:02 2019 -0400 @@ -28,9 +28,7 @@ from mercurial.i18n import _ -from mercurial.node import ( - bin, -) +from mercurial.node import bin from mercurial import ( bookmarks, error, @@ -45,15 +43,15 @@ util, ) -from mercurial.utils import ( - stringutil, -) +from mercurial.utils import stringutil if pycompat.ispy3: import collections.abc + mutablemapping = collections.abc.MutableMapping else: import collections + mutablemapping = collections.MutableMapping # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for @@ -67,16 +65,17 @@ templatekeyword = registrar.templatekeyword() revsetpredicate = registrar.revsetpredicate() -configitem('remotenames', 'bookmarks', - default=True, +configitem( + 'remotenames', 'bookmarks', default=True, ) -configitem('remotenames', 'branches', - default=True, +configitem( + 'remotenames', 'branches', default=True, ) -configitem('remotenames', 'hoistedpeer', - default='default', +configitem( + 'remotenames', 'hoistedpeer', default='default', ) + class lazyremotenamedict(mutablemapping): """ Read-only dict-like Class to lazily resolve remotename entries @@ -88,10 +87,11 @@ is in self.potentialentries we resolve it and store the result in self.cache. We cannot be lazy is when asked all the entries (keys). """ + def __init__(self, kind, repo): self.cache = {} self.potentialentries = {} - self._kind = kind # bookmarks or branches + self._kind = kind # bookmarks or branches self._repo = repo self.loaded = False @@ -99,8 +99,9 @@ """ Read the remotenames file, store entries matching selected kind """ self.loaded = True repo = self._repo - for node, rpath, rname in logexchange.readremotenamefile(repo, - self._kind): + for node, rpath, rname in logexchange.readremotenamefile( + repo, self._kind + ): name = rpath + '/' + rname self.potentialentries[name] = (node, rpath, name) @@ -117,7 +118,7 @@ except LookupError: return None # Skip closed branches - if (self._kind == 'branches' and repo[binnode].closesbranch()): + if self._kind == 'branches' and repo[binnode].closesbranch(): return None return [binnode] @@ -169,6 +170,7 @@ items = iteritems + class remotenames(object): """ This class encapsulates all the remotenames state. It also contains @@ -223,7 +225,7 @@ hoist += '/' for name, node in marktonodes.iteritems(): if name.startswith(hoist): - name = name[len(hoist):] + name = name[len(hoist) :] self._hoisttonodes[name] = node return self._hoisttonodes @@ -234,10 +236,11 @@ hoist += '/' for name, node in marktonodes.iteritems(): if name.startswith(hoist): - name = name[len(hoist):] + name = name[len(hoist) :] self._nodetohoists.setdefault(node[0], []).append(name) return self._nodetohoists + def wrapprintbookmarks(orig, ui, repo, fm, bmarks): if 'remotebookmarks' not in repo.names: return @@ -253,9 +256,11 @@ return orig(ui, repo, fm, bmarks) + def extsetup(ui): extensions.wrapfunction(bookmarks, '_printbookmarks', wrapprintbookmarks) + def reposetup(ui, repo): # set the config option to store remotenames @@ -274,10 +279,13 @@ colorname='remotebookmark', logfmt='remote bookmark: %s\n', listnames=lambda repo: repo._remotenames.bmarktonodes().keys(), - namemap=lambda repo, name: - repo._remotenames.bmarktonodes().get(name, []), - nodemap=lambda repo, node: - repo._remotenames.nodetobmarks().get(node, [])) + namemap=lambda repo, name: repo._remotenames.bmarktonodes().get( + name, [] + ), + nodemap=lambda repo, node: repo._remotenames.nodetobmarks().get( + node, [] + ), + ) repo.names.addnamespace(remotebookmarkns) # hoisting only works if there are remote bookmarks @@ -288,12 +296,16 @@ templatename='hoistednames', colorname='hoistedname', logfmt='hoisted name: %s\n', - listnames = lambda repo: - repo._remotenames.hoisttonodes(hoist).keys(), - namemap = lambda repo, name: - repo._remotenames.hoisttonodes(hoist).get(name, []), - nodemap = lambda repo, node: - repo._remotenames.nodetohoists(hoist).get(node, [])) + listnames=lambda repo: repo._remotenames.hoisttonodes( + hoist + ).keys(), + namemap=lambda repo, name: repo._remotenames.hoisttonodes( + hoist + ).get(name, []), + nodemap=lambda repo, node: repo._remotenames.nodetohoists( + hoist + ).get(node, []), + ) repo.names.addnamespace(hoistednamens) if ui.configbool('remotenames', 'branches'): @@ -302,13 +314,17 @@ templatename='remotebranches', colorname='remotebranch', logfmt='remote branch: %s\n', - listnames = lambda repo: repo._remotenames.branchtonodes().keys(), - namemap = lambda repo, name: - repo._remotenames.branchtonodes().get(name, []), - nodemap = lambda repo, node: - repo._remotenames.nodetobranch().get(node, [])) + listnames=lambda repo: repo._remotenames.branchtonodes().keys(), + namemap=lambda repo, name: repo._remotenames.branchtonodes().get( + name, [] + ), + nodemap=lambda repo, node: repo._remotenames.nodetobranch().get( + node, [] + ), + ) repo.names.addnamespace(remotebranchns) + @templatekeyword('remotenames', requires={'repo', 'ctx'}) def remotenameskw(context, mapping): """List of strings. Remote names associated with the changeset.""" @@ -322,8 +338,10 @@ if 'remotebranches' in repo.names: remotenames += repo.names['remotebranches'].names(repo, ctx.node()) - return templateutil.compatlist(context, mapping, 'remotename', remotenames, - plural='remotenames') + return templateutil.compatlist( + context, mapping, 'remotename', remotenames, plural='remotenames' + ) + @templatekeyword('remotebookmarks', requires={'repo', 'ctx'}) def remotebookmarkskw(context, mapping): @@ -335,8 +353,14 @@ if 'remotebookmarks' in repo.names: remotebmarks = repo.names['remotebookmarks'].names(repo, ctx.node()) - return templateutil.compatlist(context, mapping, 'remotebookmark', - remotebmarks, plural='remotebookmarks') + return templateutil.compatlist( + context, + mapping, + 'remotebookmark', + remotebmarks, + plural='remotebookmarks', + ) + @templatekeyword('remotebranches', requires={'repo', 'ctx'}) def remotebrancheskw(context, mapping): @@ -348,15 +372,22 @@ if 'remotebranches' in repo.names: remotebranches = repo.names['remotebranches'].names(repo, ctx.node()) - return templateutil.compatlist(context, mapping, 'remotebranch', - remotebranches, plural='remotebranches') + return templateutil.compatlist( + context, + mapping, + 'remotebranch', + remotebranches, + plural='remotebranches', + ) + def _revsetutil(repo, subset, x, rtypes): """utility function to return a set of revs based on the rtypes""" args = revsetlang.getargs(x, 0, 1, _('only one argument accepted')) if args: kind, pattern, matcher = stringutil.stringmatcher( - revsetlang.getstring(args[0], _('argument must be a string'))) + revsetlang.getstring(args[0], _('argument must be a string')) + ) else: kind = pattern = None matcher = util.always @@ -371,12 +402,14 @@ continue nodes.update(ns.nodes(repo, name)) if kind == 'literal' and not nodes: - raise error.RepoLookupError(_("remote name '%s' does not exist") - % pattern) + raise error.RepoLookupError( + _("remote name '%s' does not exist") % pattern + ) revs = (cl.rev(n) for n in nodes if cl.hasnode(n)) return subset & smartset.baseset(revs) + @revsetpredicate('remotenames([name])') def remotenamesrevset(repo, subset, x): """All changesets which have a remotename on them. If `name` is @@ -386,6 +419,7 @@ """ return _revsetutil(repo, subset, x, ('remotebookmarks', 'remotebranches')) + @revsetpredicate('remotebranches([name])') def remotebranchesrevset(repo, subset, x): """All changesets which are branch heads on remotes. If `name` is @@ -395,6 +429,7 @@ """ return _revsetutil(repo, subset, x, ('remotebranches',)) + @revsetpredicate('remotebookmarks([name])') def remotebmarksrevset(repo, subset, x): """All changesets which have bookmarks on remotes. If `name` is