diff --git a/hgext/remotenames.py b/hgext/remotenames.py --- a/hgext/remotenames.py +++ b/hgext/remotenames.py @@ -6,7 +6,19 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -""" showing remotebookmarks and remotebranches in UI """ +""" showing remotebookmarks and remotebranches in UI + +By default both remotebookmarks and remotebranches are turned on. Config knob to +control the individually are as follows. + +Config options to tweak the default behaviour: + +remotenames.bookmarks + Boolean value to enable or disable showing of remotebookmarks + +remotenames.branches + Boolean value to enable or disable showing of remotebranches +""" from __future__ import absolute_import @@ -17,6 +29,8 @@ ) from mercurial import ( logexchange, + namespaces, + registrar, ) # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for @@ -25,6 +39,16 @@ # leave the attribute unspecified. testedwith = 'ships-with-hg-core' +configtable = {} +configitem = registrar.configitem(configtable) + +configitem('remotenames', 'bookmarks', + default=True, +) +configitem('remotenames', 'branches', + default=True, +) + class lazyremotenamedict(UserDict.DictMixin): """ Read-only dict-like Class to lazily resolve remotename entries @@ -65,8 +89,9 @@ except LookupError: return None # Skip closed branches - if (self.kind == 'branches' and _branchesenabled(repo.ui) and - repo[binnode].closesbranch()): + if (self._kind == 'branches' and + repo.ui.configbool('remotenames', 'branches') and + repo[binnode].closesbranch()): return None return [binnode] @@ -145,7 +170,40 @@ if not self._nodetobranch: branchtonodes = self.branchtonodes() self._nodetobranch = {} - for name, nodes in branchtonodes.iteritems(): + for name, nodes in sorted(branchtonodes.iteritems()): for node in nodes: self._nodetobranch[node] = [name] return self._nodetobranch + +def reposetup(ui, repo): + if not repo.local(): + return + + repo._remotenames = remotenames(repo) + ns = namespaces.namespace + + if ui.configbool('remotenames', 'bookmarks'): + remotebookmarkns = ns( + 'remotebookmarks', + templatename='remotebookmarks', + logname='bookmark', + colorname='remotebookmark', + 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, [])) + repo.names.addnamespace(remotebookmarkns) + + if ui.configbool('remotenames', 'branches'): + remotebranchns = ns( + 'remotebranches', + templatename='remotebranches', + logname='branch', + colorname='remotebranch', + 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) diff --git a/tests/test-logexchange.t b/tests/test-logexchange.t --- a/tests/test-logexchange.t +++ b/tests/test-logexchange.t @@ -6,6 +6,9 @@ > glog = log -G -T '{rev}:{node|short} {desc}' > [experimental] > remotenames = True + > [extensions] + > remotenames = + > show = > EOF Making a server repo @@ -66,6 +69,19 @@ ec2426147f0e39dbc9cef599b066be6035ce691d\x00$TESTTMP/server\x00default (esc) 3e1487808078543b0af6d10dadf5d46943578db0\x00$TESTTMP/server\x00wat (esc) + $ hg show work + o 3e14 (wat) ($TESTTMP/server/wat) added bar + | + ~ + @ ec24 ($TESTTMP/server/default) Added h + | + ~ + + $ hg update "$TESTTMP/server/wat" + 1 files updated, 0 files merged, 3 files removed, 0 files unresolved + $ hg identify + 3e1487808078 (wat) tip + Making a new server ------------------- @@ -106,3 +122,61 @@ ec2426147f0e39dbc9cef599b066be6035ce691d\x00$TESTTMP/server\x00default (esc) ec2426147f0e39dbc9cef599b066be6035ce691d\x00$TESTTMP/server2\x00default (esc) 3e1487808078543b0af6d10dadf5d46943578db0\x00$TESTTMP/server2\x00wat (esc) + + $ hg log -G + @ changeset: 8:3e1487808078 + | branch: wat + | tag: tip + | branch: $TESTTMP/server2/wat + | parent: 4:aa98ab95a928 + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: added bar + | + | o changeset: 7:ec2426147f0e + | | branch: $TESTTMP/server2/default + | | user: test + | | date: Thu Jan 01 00:00:00 1970 +0000 + | | summary: Added h + | | + | o changeset: 6:87d6d6676308 + | | bookmark: bar + | | bookmark: $TESTTMP/server/bar + | | bookmark: $TESTTMP/server2/bar + | | user: test + | | date: Thu Jan 01 00:00:00 1970 +0000 + | | summary: Added g + | | + | o changeset: 5:825660c69f0c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: Added f + | + o changeset: 4:aa98ab95a928 + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: Added e + | + o changeset: 3:62615734edd5 + | bookmark: foo + | bookmark: $TESTTMP/server/foo + | bookmark: $TESTTMP/server2/foo + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: Added d + | + o changeset: 2:28ad74487de9 + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: Added c + | + o changeset: 1:29becc82797a + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: Added b + | + o changeset: 0:18d04c59bb5d + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: Added a +