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

2017-12-14 Thread Yuya Nishihara
On Wed, 13 Dec 2017 00:27:46 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov 
> # 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.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


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

2017-12-12 Thread Anton Shestakov
# HG changeset patch
# User Anton Shestakov 
# 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.

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})
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel