D1759: remotenames: introduce new template keywords for remotenames

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Mon Feb 12 16:33:38 EST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5a53af7d09aa: remotenames: introduce new template keywords for remotenames (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1759?vs=5148&id=5524

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

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

CHANGE DETAILS

diff --git a/tests/test-logexchange.t b/tests/test-logexchange.t
--- a/tests/test-logexchange.t
+++ b/tests/test-logexchange.t
@@ -182,3 +182,47 @@
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     Added a
   
+Testing the templates provided by remotenames extension
+
+`remotenames` keyword
+
+  $ hg log -G -T "{rev}:{node|short} {remotenames}\n"
+  @  8:3e1487808078 $TESTTMP/server2/wat default/wat
+  |
+  | o  7:ec2426147f0e $TESTTMP/server2/default default/default
+  | |
+  | o  6:87d6d6676308 $TESTTMP/server2/bar default/bar
+  | |
+  | o  5:825660c69f0c
+  |/
+  o  4:aa98ab95a928
+  |
+  o  3:62615734edd5 $TESTTMP/server2/foo default/foo
+  |
+  o  2:28ad74487de9
+  |
+  o  1:29becc82797a
+  |
+  o  0:18d04c59bb5d
+  
+`remotebookmarks` and `remotebranches` keywords
+
+  $ hg log -G -T "{rev}:{node|short} [{remotebookmarks}] ({remotebranches})"
+  @  8:3e1487808078 [] ($TESTTMP/server2/wat default/wat)
+  |
+  | o  7:ec2426147f0e [] ($TESTTMP/server2/default default/default)
+  | |
+  | o  6:87d6d6676308 [$TESTTMP/server2/bar default/bar] ()
+  | |
+  | o  5:825660c69f0c [] ()
+  |/
+  o  4:aa98ab95a928 [] ()
+  |
+  o  3:62615734edd5 [$TESTTMP/server2/foo default/foo] ()
+  |
+  o  2:28ad74487de9 [] ()
+  |
+  o  1:29becc82797a [] ()
+  |
+  o  0:18d04c59bb5d [] ()
+  
diff --git a/hgext/remotenames.py b/hgext/remotenames.py
--- a/hgext/remotenames.py
+++ b/hgext/remotenames.py
@@ -30,7 +30,9 @@
 from mercurial import (
     logexchange,
     namespaces,
+    pycompat,
     registrar,
+    templatekw,
 )
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -41,6 +43,7 @@
 
 configtable = {}
 configitem = registrar.configitem(configtable)
+templatekeyword = registrar.templatekeyword()
 
 configitem('remotenames', 'bookmarks',
     default=True,
@@ -205,3 +208,51 @@
             nodemap = lambda repo, node:
                 repo._remotenames.nodetobranch().get(node, []))
         repo.names.addnamespace(remotebranchns)
+
+ at templatekeyword('remotenames')
+def remotenameskw(**args):
+    """:remotenames: List of strings. List of remote names associated with the
+    changeset.
+    """
+    args = pycompat.byteskwargs(args)
+    repo, ctx = args['repo'], args['ctx']
+
+    remotenames = []
+    if 'remotebookmarks' in repo.names:
+        remotenames = repo.names['remotebookmarks'].names(repo, ctx.node())
+
+    if 'remotebranches' in repo.names:
+        remotenames += repo.names['remotebranches'].names(repo, ctx.node())
+
+    return templatekw.showlist('remotename', remotenames, args,
+                               plural='remotenames')
+
+ at templatekeyword('remotebookmarks')
+def remotebookmarkskw(**args):
+    """:remotebookmarks: List of strings. List of remote bookmarks associated
+    with the changeset.
+    """
+    args = pycompat.byteskwargs(args)
+    repo, ctx = args['repo'], args['ctx']
+
+    remotebmarks = []
+    if 'remotebookmarks' in repo.names:
+        remotebmarks = repo.names['remotebookmarks'].names(repo, ctx.node())
+
+    return templatekw.showlist('remotebookmark', remotebmarks, args,
+                               plural='remotebookmarks')
+
+ at templatekeyword('remotebranches')
+def remotebrancheskw(**args):
+    """:remotebranches: List of strings. List of remote branches associated
+    with the changeset.
+    """
+    args = pycompat.byteskwargs(args)
+    repo, ctx = args['repo'], args['ctx']
+
+    remotebranches = []
+    if 'remotebranches' in repo.names:
+        remotebranches = repo.names['remotebranches'].names(repo, ctx.node())
+
+    return templatekw.showlist('remotebranch', remotebranches, args,
+                               plural='remotebranches')



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


More information about the Mercurial-devel mailing list