Patchwork [2,of,2] hgweb: use webutil.commonentry() for nodes (but not for jsdata yet) in /graph

login
register
mail settings
Submitter Anton Shestakov
Date Nov. 20, 2017, 2:36 p.m.
Message ID <40a30e6f1ac5cea9adde.1511188593@neuro>
Download mbox | patch
Permalink /patch/25652/
State Accepted
Headers show

Comments

Anton Shestakov - Nov. 20, 2017, 2:36 p.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1511186340 -28800
#      Mon Nov 20 21:59:00 2017 +0800
# Node ID 40a30e6f1ac5cea9addec2b373dcabb54541529f
# Parent  7a50f1a586182a0cf8237ef969f232a3b73c12a5
# EXP-Topic hgweb-cleanup
hgweb: use webutil.commonentry() for nodes (but not for jsdata yet) in /graph

This makes graphdata() simpler by using existing code that gets common
changeset properties for showing in hgweb. graphdata() is a nested function in
graph() that prepares entries for /graph view, but there are two different
lists of changesets prepared: "jsdata" for JavaScript-rendered graph and
"nodes" for everything else.

For "jsdata", properties "node", "user", "age" and "desc" are passed through
various template filters because we don't have these filters in JavaScript, so
the data has to be prepared server-side. But now that commonentry() is used for
producing "nodes" list (and it doesn't apply any filters), these filters need
to be added to the appropriate templates (only raw at this moment, everything
else either doesn't implement graph or uses JavaScript).

This is a bit of refactoring that will hopefully simplify future patches. The
end result is to have /graph that only renders the actual graph with nodes and
vertices in JavaScript, and the rest is done server-side. This way server-side
code can focus on showing a list of changesets, which is easy because we
already have /log, /shortlog, etc, and JavaScript code can be simplified,
making it easier to add obsolescence graph and other features.
Augie Fackler - Nov. 20, 2017, 10:02 p.m.
On Mon, Nov 20, 2017 at 10:36:33PM +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1511186340 -28800
> #      Mon Nov 20 21:59:00 2017 +0800
> # Node ID 40a30e6f1ac5cea9addec2b373dcabb54541529f
> # Parent  7a50f1a586182a0cf8237ef969f232a3b73c12a5
> # EXP-Topic hgweb-cleanup
> hgweb: use webutil.commonentry() for nodes (but not for jsdata yet) in /graph

queued, thanks

Patch

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -1241,51 +1241,49 @@  def graph(web, req, tmpl):
                              max([edge[1] for edge in edges] or [0]))
         return cols
 
-    def graphdata(usetuples, encodestr):
+    def graphdata(usetuples):
+        # {jsdata} will be passed to |json, so it must be in utf-8
+        encodestr = encoding.fromlocal
         data = []
 
         row = 0
         for (id, type, ctx, vtx, edges) in tree:
             if type != graphmod.CHANGESET:
                 continue
-            node = pycompat.bytestr(ctx)
-            age = encodestr(templatefilters.age(ctx.date()))
-            desc = templatefilters.firstline(encodestr(ctx.description()))
-            desc = url.escape(templatefilters.nonempty(desc))
-            user = url.escape(templatefilters.person(encodestr(ctx.user())))
-            branch = url.escape(encodestr(ctx.branch()))
-            try:
-                branchnode = web.repo.branchtip(ctx.branch())
-            except error.RepoLookupError:
-                branchnode = None
-            branch = branch, branchnode == ctx.node()
 
             if usetuples:
+                node = pycompat.bytestr(ctx)
+                age = encodestr(templatefilters.age(ctx.date()))
+                desc = templatefilters.firstline(encodestr(ctx.description()))
+                desc = url.escape(templatefilters.nonempty(desc))
+                user = templatefilters.person(encodestr(ctx.user()))
+                user = url.escape(user)
+                branch = url.escape(encodestr(ctx.branch()))
+                try:
+                    branchnode = web.repo.branchtip(ctx.branch())
+                except error.RepoLookupError:
+                    branchnode = None
+                branch = branch, branchnode == ctx.node()
+
                 data.append((node, vtx, edges, desc, user, age, branch,
                              [url.escape(encodestr(x)) for x in ctx.tags()],
                              [url.escape(encodestr(x))
                               for x in ctx.bookmarks()]))
             else:
+                entry = webutil.commonentry(web.repo, ctx)
                 edgedata = [{'col': edge[0], 'nextcol': edge[1],
                              'color': (edge[2] - 1) % 6 + 1,
                              'width': edge[3], 'bcolor': edge[4]}
                             for edge in edges]
 
-                data.append(
-                    {'node': node,
-                     'col': vtx[0],
+                entry.update(
+                    {'col': vtx[0],
                      'color': (vtx[1] - 1) % 6 + 1,
                      'edges': edgedata,
                      'row': row,
-                     'nextrow': row + 1,
-                     'desc': desc,
-                     'user': user,
-                     'age': age,
-                     'bookmarks': webutil.nodebookmarksdict(
-                         web.repo, ctx.node()),
-                     'branches': webutil.nodebranchdict(web.repo, ctx),
-                     'inbranch': webutil.nodeinbranch(web.repo, ctx),
-                     'tags': webutil.nodetagsdict(web.repo, ctx.node())})
+                     'nextrow': row + 1})
+
+                data.append(entry)
 
             row += 1
 
@@ -1302,9 +1300,8 @@  def graph(web, req, tmpl):
                 canvaswidth=(cols + 1) * bg_height,
                 truecanvasheight=rows * bg_height,
                 canvasheight=canvasheight, bg_height=bg_height,
-                # {jsdata} will be passed to |json, so it must be in utf-8
-                jsdata=lambda **x: graphdata(True, encoding.fromlocal),
-                nodes=lambda **x: graphdata(False, pycompat.bytestr),
+                jsdata=lambda **x: graphdata(True),
+                nodes=lambda **x: graphdata(False),
                 node=ctx.hex(), changenav=changenav)
 
 def _getdoc(e):
diff --git a/mercurial/templates/raw/graphnode.tmpl b/mercurial/templates/raw/graphnode.tmpl
--- a/mercurial/templates/raw/graphnode.tmpl
+++ b/mercurial/templates/raw/graphnode.tmpl
@@ -1,7 +1,7 @@ 
-changeset:   {node}
-user:        {user}
-date:        {age}
-summary:     {desc}
+changeset:   {node|short}
+user:        {author|person}
+date:        {date|age}
+summary:     {desc|firstline|nonempty}
 {branches%branchname}{tags%tagname}{bookmarks%bookmarkname}
 node:        ({col}, {row}) (color {color})
 {edges%graphedge}