Patchwork D2807: remotenames: add functionality to hoist remotebookmarks

login
register
mail settings
Submitter phabricator
Date March 23, 2018, 6:45 p.m.
Message ID <41622739319cb54b41364c27dd994562@localhost.localdomain>
Download mbox | patch
Permalink /patch/29800/
State Not Applicable
Headers show

Comments

phabricator - March 23, 2018, 6:45 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG9938992c5bae: remotenames: add functionality to hoist remotebookmarks (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2807?vs=7247&id=7259

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

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

CHANGE DETAILS




To: pulkit, #hg-reviewers, durin42, indygreg
Cc: indygreg, 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
@@ -145,6 +145,7 @@ 
   | |  bookmark:    bar
   | |  remote bookmark:  $TESTTMP/server2/bar
   | |  remote bookmark:  default/bar
+  | |  hoisted name:  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
+  |  hoisted name:  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
+  hoisted name:  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
+  
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.hoistedpeer
+  Name of the peer whose remotebookmarks should be hoisted into the top-level
+  namespace (default: 'default')
 """
 
 from __future__ import absolute_import
@@ -61,6 +65,9 @@ 
 configitem('remotenames', 'branches',
     default=True,
 )
+configitem('remotenames', 'hoistedpeer',
+    default='default',
+)
 
 class lazyremotenamedict(mutablemapping):
     """
@@ -173,6 +180,8 @@ 
     def _invalidatecache(self):
         self._nodetobmarks = None
         self._nodetobranch = None
+        self._hoisttonodes = None
+        self._nodetohoists = None
 
     def bmarktonodes(self):
         return self.bookmarks
@@ -197,6 +206,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
@@ -217,6 +248,22 @@ 
                 repo._remotenames.nodetobmarks().get(node, []))
         repo.names.addnamespace(remotebookmarkns)
 
+        # hoisting only works if there are remote bookmarks
+        hoist = ui.config('remotenames', 'hoistedpeer')
+        if hoist:
+            hoistednamens = ns(
+                'hoistednames',
+                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, []))
+            repo.names.addnamespace(hoistednamens)
+
     if ui.configbool('remotenames', 'branches'):
         remotebranchns = ns(
             'remotebranches',