# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2017-12-23 08:54:41 # Node ID 382aefea8fafdd1e31606f26d1c03dd827558854 # Parent be72f6420f3c849a925dabb8b015fb02814c764a remotenames: add new namespaces for remotebookmarks and remotebranches This patch adds two new namespaces which will be enabled by remotenames extension. The namespaces are remotebookmarks and remotebranches. Adding them as namespaces will show them in various commands' output such as log, show work. This will also unable to access changesets using that name. Tests are also added for the same. This is a part of moving hgremotenames extension to core. hgremotenames: https://bitbucket.org/seanfarley/hgremotenames Differential Revision: https://phab.mercurial-scm.org/D1758 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.node import ( ) from mercurial import ( logexchange, + namespaces, + registrar, ) # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for @@ -25,6 +39,16 @@ from mercurial import ( # 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 @@ -148,3 +172,36 @@ class remotenames(dict): for node in nodes: self._nodetobranch.setdefault(node, []).append(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='remote 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='remote 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 @@ Testing the functionality to pull remote > glog = log -G -T '{rev}:{node|short} {desc}' > [experimental] > remotenames = True + > [extensions] + > remotenames = + > show = > EOF Making a server repo @@ -66,6 +69,19 @@ Making a client repo ec2426147f0e39dbc9cef599b066be6035ce691d\x00default\x00default (esc) 3e1487808078543b0af6d10dadf5d46943578db0\x00default\x00wat (esc) + $ hg show work + o 3e14 (wat) (default/wat) added bar + | + ~ + @ ec24 (default/default) Added h + | + ~ + + $ hg update "default/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,63 @@ Pulling form the new server ec2426147f0e39dbc9cef599b066be6035ce691d\x00default\x00default (esc) ec2426147f0e39dbc9cef599b066be6035ce691d\x00$TESTTMP/server2\x00default (esc) 3e1487808078543b0af6d10dadf5d46943578db0\x00$TESTTMP/server2\x00wat (esc) + + $ hg log -G + @ changeset: 8:3e1487808078 + | branch: wat + | 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 + | + | o changeset: 7:ec2426147f0e + | | remote branch:$TESTTMP/server2/default + | | remote branch:default/default + | | user: test + | | date: Thu Jan 01 00:00:00 1970 +0000 + | | summary: Added h + | | + | o changeset: 6:87d6d6676308 + | | bookmark: bar + | | remote bookmark:$TESTTMP/server2/bar + | | remote bookmark:default/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 + | remote bookmark:$TESTTMP/server2/foo + | remote bookmark:default/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 +