diff --git a/hgext/remotenames.py b/hgext/remotenames.py --- a/hgext/remotenames.py +++ b/hgext/remotenames.py @@ -14,10 +14,14 @@ Config options to tweak the default behaviour: remotenames.bookmarks - Boolean value to enable or disable showing of remotebookmarks + Boolean value to enable or disable showing of remotebookmarks (default: True) remotenames.branches - Boolean value to enable or disable showing of remotebranches + Boolean value to enable or disable showing of remotebranches (default: True) + +remotenames.hoist + Name of the peer whose remotebookmarks should be hoisted into the top-level + namespace (default: 'default') """ from __future__ import absolute_import @@ -55,6 +59,9 @@ configitem('remotenames', 'branches', default=True, ) +configitem('remotenames', 'hoist', + default='default', +) class lazyremotenamedict(collections.MutableMapping): """ @@ -167,6 +174,8 @@ def _invalidatecache(self): self._nodetobmarks = None self._nodetobranch = None + self._hoisttonodes = None + self._nodetohoists = None def bmarktonodes(self): return self.bookmarks @@ -191,6 +200,28 @@ self._nodetobranch.setdefault(node, []).append(name) return self._nodetobranch + def hoisttonodes(self, hoist): + if not self._hoisttonodes: + marktonodes = self.bmarktonodes() + self._hoisttonodes = {} + hoist += '/' + for name, node in marktonodes.iteritems(): + if name.startswith(hoist): + name = name[len(hoist):] + self._hoisttonodes[name] = node + return self._hoisttonodes + + def nodetohoists(self, hoist): + if not self._nodetohoists: + marktonodes = self.bmarktonodes() + self._nodetohoists = {} + hoist += '/' + for name, node in marktonodes.iteritems(): + if name.startswith(hoist): + name = name[len(hoist):] + self._nodetohoists.setdefault(node[0], []).append(name) + return self._nodetohoists + def reposetup(ui, repo): if not repo.local(): return @@ -211,6 +242,22 @@ repo._remotenames.nodetobmarks().get(node, [])) repo.names.addnamespace(remotebookmarkns) + # hoisting only works if there are remote bookmarks + hoist = ui.config('remotenames', 'hoist') + if hoist: + hoistednamens = ns( + 'hoistednames', + templatename='hoistednames', + colorname='hoistedname', + logfmt='hoistedname: %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, [])) + repo.names.addnamespace(hoistednamens) + if ui.configbool('remotenames', 'branches'): remotebranchns = ns( 'remotebranches', diff --git a/tests/test-logexchange.t b/tests/test-logexchange.t --- a/tests/test-logexchange.t +++ b/tests/test-logexchange.t @@ -145,6 +145,7 @@ | | bookmark: bar | | remote bookmark: $TESTTMP/server2/bar | | remote bookmark: default/bar + | | hoistedname: bar | | user: test | | date: Thu Jan 01 00:00:00 1970 +0000 | | summary: Added g @@ -163,6 +164,7 @@ | bookmark: foo | remote bookmark: $TESTTMP/server2/foo | remote bookmark: default/foo + | hoistedname: foo | user: test | date: Thu Jan 01 00:00:00 1970 +0000 | summary: Added d @@ -226,6 +228,28 @@ | o 0:18d04c59bb5d [] () +The `hoistednames` template keyword + + $ hg log -GT "{rev}:{node|short} ({hoistednames})" + @ 8:3e1487808078 () + | + | o 7:ec2426147f0e () + | | + | o 6:87d6d6676308 (bar) + | | + | o 5:825660c69f0c () + |/ + o 4:aa98ab95a928 () + | + o 3:62615734edd5 (foo) + | + o 2:28ad74487de9 () + | + o 1:29becc82797a () + | + o 0:18d04c59bb5d () + + Testing the revsets provided by remotenames extension `remotenames` revset @@ -259,3 +283,47 @@ o 3:62615734edd5 $TESTTMP/server2/foo default/foo | ~ + +Updating to revision using hoisted name + +Deleting local bookmark to make sure we update to hoisted name only + + $ hg bookmark -d bar + + $ hg up bar + 2 files updated, 0 files merged, 1 files removed, 0 files unresolved + + $ hg log -r . + changeset: 6:87d6d6676308 + remote bookmark: $TESTTMP/server2/bar + remote bookmark: default/bar + hoistedname: bar + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: Added g + +When both local bookmark and hoisted name exists but on different revs + + $ hg up 8 + 1 files updated, 0 files merged, 2 files removed, 0 files unresolved + + $ hg bookmark foo + moving bookmark 'foo' forward from 62615734edd5 + +Local bookmark should take precedence over hoisted name + + $ hg up foo + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + + $ hg log -r . + changeset: 8:3e1487808078 + branch: wat + bookmark: foo + tag: tip + remote branch: $TESTTMP/server2/wat + remote branch: default/wat + parent: 4:aa98ab95a928 + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: added bar +