Patchwork [2,of,4] graphlog: extract "graphnode" template keyword that represents node symbol

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 3, 2015, 2:26 p.m.
Message ID <e60e6f49f4c83db91d57.1449152805@mimosa>
Download mbox | patch
Permalink /patch/11785/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 3, 2015, 2:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1447487898 -32400
#      Sat Nov 14 16:58:18 2015 +0900
# Node ID e60e6f49f4c83db91d57364a5308d95a9ce982f6
# Parent  aefccaa8788f27614d7b501abba00e28aa1d623f
graphlog: extract "graphnode" template keyword that represents node symbol

This provides a default node symbol. Tests will be added later.

"showparents" variable is renamed to "wpnodes" to avoid confusion with the
existing showparents() function.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2161,16 +2161,9 @@  def getlogrevs(repo, pats, opts):
 
 def displaygraph(ui, repo, dag, displayer, edgefn, getrenamed=None,
                  filematcher=None):
-    showparents = [ctx.node() for ctx in repo[None].parents()]
     seen, state = [], graphmod.asciistate()
     for rev, type, ctx, parents in dag:
-        char = 'o'
-        if ctx.node() in showparents:
-            char = '@'
-        elif ctx.obsolete():
-            char = 'x'
-        elif ctx.closesbranch():
-            char = '_'
+        char = templatekw.showgraphnode(repo, ctx)
         copies = None
         if getrenamed and ctx.rev():
             copies = []
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -340,6 +340,19 @@  def showfiles(**args):
     """
     return showlist('file', args['ctx'].files(), **args)
 
+def showgraphnode(repo, ctx, **args):
+    """:graphnode: String. The character representing the changeset node in
+    an ASCII revision graph"""
+    wpnodes = [pctx.node() for pctx in repo[None].parents()]
+    if ctx.node() in wpnodes:
+        return '@'
+    elif ctx.obsolete():
+        return 'x'
+    elif ctx.closesbranch():
+        return '_'
+    else:
+        return 'o'
+
 def showlatesttag(**args):
     """:latesttag: List of strings. The global tags on the most recent globally
     tagged ancestor of this changeset.
@@ -518,6 +531,7 @@  keywords = {
     'file_dels': showfiledels,
     'file_mods': showfilemods,
     'files': showfiles,
+    'graphnode': showgraphnode,
     'latesttag': showlatesttag,
     'latesttagdistance': showlatesttagdistance,
     'manifest': showmanifest,