[PATCH 2 of 2] hgweb: reuse graph node-related functions from templates

Anton Shestakov av6 at dwimlabs.net
Wed May 9 00:20:10 EDT 2018


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1525777201 -28800
#      Tue May 08 19:00:01 2018 +0800
# Node ID a1829e98f2a1ef920a49e48c89a8c4dfdb3e0c97
# Parent  223f04ec87e4d17492a7ea7dc4bab1d9bd5c9fdf
hgweb: reuse graph node-related functions from templates

The difference between templatekw.getgraphnode() and webutil.getgraphnode() is
that the latter is not limited to 1 character.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -13,7 +13,7 @@ import os
 import re
 
 from ..i18n import _
-from ..node import hex, nullid, short
+from ..node import hex, short
 
 from .common import (
     ErrorResponse,
@@ -1314,24 +1314,6 @@ def graph(web):
         tree = list(item for item in graphmod.colored(dag, web.repo)
                     if item[1] == graphmod.CHANGESET)
 
-    def nodecurrent(ctx):
-        wpnodes = web.repo.dirstate.parents()
-        if wpnodes[1] == nullid:
-            wpnodes = wpnodes[:1]
-        if ctx.node() in wpnodes:
-            return '@'
-        return ''
-
-    def nodesymbol(ctx):
-        if ctx.obsolete():
-            return 'x'
-        elif ctx.isunstable():
-            return '*'
-        elif ctx.closesbranch():
-            return '_'
-        else:
-            return 'o'
-
     def fulltree():
         pos = web.repo[graphtop].rev()
         tree = []
@@ -1344,7 +1326,7 @@ def graph(web):
 
     def jsdata():
         return [{'node': pycompat.bytestr(ctx),
-                 'graphnode': nodecurrent(ctx) + nodesymbol(ctx),
+                 'graphnode': webutil.getgraphnode(web.repo, ctx),
                  'vertex': vtx,
                  'edges': edges}
                 for (id, type, ctx, vtx, edges) in fulltree()]
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -733,3 +733,7 @@ def getwebsubs(repo):
             repo.ui.warn(_("websub: invalid regexp for %s: %s\n")
                          % (key, regexp))
     return websubtable
+
+def getgraphnode(repo, ctx):
+    return (templatekw.getgraphnodecurrent(repo, ctx) +
+            templatekw.getgraphnodesymbol(ctx))


More information about the Mercurial-devel mailing list