Patchwork [1,of,4] hgweb: filter graphmod.colored() output before iterating over it

login
register
mail settings
Submitter Anton Shestakov
Date Dec. 12, 2017, 4:27 p.m.
Message ID <e35959da063b59443692.1513096066@neuro>
Download mbox | patch
Permalink /patch/26237/
State Accepted
Headers show

Comments

Anton Shestakov - Dec. 12, 2017, 4:27 p.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1512741011 -28800
#      Fri Dec 08 21:50:11 2017 +0800
# Node ID e35959da063b5944369277f3b2c69c3af06e2710
# Parent  b963750b125f6e342a0e2148535b7c7d0bc50e3b
hgweb: filter graphmod.colored() output before iterating over it

Consumers in this function use output of graphmod.colored(), but only want
items with type == CHANGESET, so let's filter it early.

This is primarily just a refactoring, but it also fixes a potential small bug
with `rows = len(tree)` (this variable is used for "Rows shown" line in
raw-graph) if there are items of other types.
Yuya Nishihara - Dec. 14, 2017, 12:05 p.m.
On Wed, 13 Dec 2017 00:27:46 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1512741011 -28800
> #      Fri Dec 08 21:50:11 2017 +0800
> # Node ID e35959da063b5944369277f3b2c69c3af06e2710
> # Parent  b963750b125f6e342a0e2148535b7c7d0bc50e3b
> hgweb: filter graphmod.colored() output before iterating over it

Queued the series, thanks.

Patch

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -1228,13 +1228,12 @@  def graph(web, req, tmpl):
         # since hgweb graphing code is not itself lazy yet.
         dag = graphmod.dagwalker(web.repo, smartset.baseset(revs))
         # As we said one line above... not lazy.
-        tree = list(graphmod.colored(dag, web.repo))
+        tree = list(item for item in graphmod.colored(dag, web.repo)
+                    if item[1] == graphmod.CHANGESET)
 
     def getcolumns(tree):
         cols = 0
         for (id, type, ctx, vtx, edges) in tree:
-            if type != graphmod.CHANGESET:
-                continue
             cols = max(cols, max([edge[0] for edge in edges] or [0]),
                              max([edge[1] for edge in edges] or [0]))
         return cols
@@ -1244,9 +1243,6 @@  def graph(web, req, tmpl):
 
         row = 0
         for (id, type, ctx, vtx, edges) in tree:
-            if type != graphmod.CHANGESET:
-                continue
-
             if usetuples:
                 node = pycompat.bytestr(ctx)
                 data.append({'node': node, 'vertex': vtx, 'edges': edges})