Patchwork D1758: remotenames: add new namespaces for remotebookmarks and remotebranches

login
register
mail settings
Submitter phabricator
Date Dec. 25, 2017, 8:51 p.m.
Message ID <differential-rev-PHID-DREV-o64tijosavc7xrvikkyb-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26437/
State Superseded
Headers show

Comments

phabricator - Dec. 25, 2017, 8:51 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

AFFECTED FILES
  hgext/remotenames.py
  tests/test-logexchange.t

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 18, 2018, 8:06 p.m.
durin42 requested changes to this revision.
durin42 added a comment.
This revision now requires changes to proceed.


  Easiest path is to mark this as experimental, and then we can do an iteration in the next cycle and remove the warning label.

INLINE COMMENTS

> remotenames.py:189
> +            templatename='remotebookmarks',
> +            logname='bookmark',
> +            colorname='remotebookmark',

Hm, I'm not sure if we want to name remote{bookmarks,branches} the same as local ones in log output. It may make sense to defer this until after the freeze, or else mark the remotenames extension as experimental for a cycle.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

To: pulkit, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Jan. 19, 2018, 7:39 a.m.
pulkit added inline comments.

INLINE COMMENTS

> durin42 wrote in remotenames.py:189
> Hm, I'm not sure if we want to name remote{bookmarks,branches} the same as local ones in log output. It may make sense to defer this until after the freeze, or else mark the remotenames extension as experimental for a cycle.

I am fine either way.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

To: pulkit, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Jan. 22, 2018, 5:53 p.m.
pulkit added inline comments.

INLINE COMMENTS

> durin42 wrote in remotenames.py:189
> Hm, I'm not sure if we want to name remote{bookmarks,branches} the same as local ones in log output. It may make sense to defer this until after the freeze, or else mark the remotenames extension as experimental for a cycle.

> Hm, I'm not sure if we want to name remote{bookmarks,branches} the same as local ones in log > output.

Does remotebookmark, and remotebranch sounds good?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

To: pulkit, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Jan. 22, 2018, 6:10 p.m.
durin42 added inline comments.

INLINE COMMENTS

> pulkit wrote in remotenames.py:189
> > Hm, I'm not sure if we want to name remote{bookmarks,branches} the same as local ones in log > output.
> 
> Does remotebookmark, and remotebranch sounds good?

Works for me.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

To: pulkit, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Jan. 22, 2018, 6:14 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> pulkit wrote in remotenames.py:189
> > Hm, I'm not sure if we want to name remote{bookmarks,branches} the same as local ones in log > output.
> 
> Does remotebookmark, and remotebranch sounds good?

> Does remotebookmark, and remotebranch sounds good?

Will the log output get aligned for these longer names?

Should we include a space? "remote bookmark:" looks more user-friendly

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

To: pulkit, #hg-reviewers, durin42
Cc: martinvonz, durin42, mercurial-devel
phabricator - Feb. 2, 2018, 7:50 a.m.
pulkit added inline comments.

INLINE COMMENTS

> martinvonz wrote in remotenames.py:189
> > Does remotebookmark, and remotebranch sounds good?
> 
> Will the log output get aligned for these longer names?
> 
> Should we include a space? "remote bookmark:" looks more user-friendly

I made it `remote bookmark` and `remote branch` and the log output does not get aligned. :(

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

To: pulkit, #hg-reviewers, durin42
Cc: martinvonz, durin42, mercurial-devel
phabricator - Feb. 14, 2018, 7:11 a.m.
martinvonz added inline comments.

INLINE COMMENTS

> test-logexchange.t:130-131
> +  |  tag:         tip
> +  |  remote branch:$TESTTMP/server2/wat
> +  |  remote branch:default/wat
> +  |  parent:      4:aa98ab95a928

This is pretty hard to read. Should we at least add a space between the label-and-colon and the value?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

To: pulkit, #hg-reviewers, durin42
Cc: martinvonz, durin42, mercurial-devel
phabricator - Feb. 14, 2018, 10:04 a.m.
pulkit added inline comments.

INLINE COMMENTS

> martinvonz wrote in test-logexchange.t:130-131
> This is pretty hard to read. Should we at least add a space between the label-and-colon and the value?

I agree with you. I will send a followup for this.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1758

To: pulkit, #hg-reviewers, durin42
Cc: martinvonz, durin42, mercurial-devel

Patch

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
+  
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,14 +29,26 @@ 
 )
 from mercurial import (
     logexchange,
+    namespaces,
+    registrar,
 )
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
 # 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)