changeset 14561:925d9f2b188b

web: include all files in the diffstat The webutil.diffstat function now returns a diffstat template for each file in the diff. It previously returned a template for each file returned by ctx.files() which did not work well for merge changesets.
author Steven Brown <StevenGBrown@gmail.com>
date Thu, 09 Jun 2011 01:14:22 +0800
parents 0980239cb20c
children fccd3b966da7
files mercurial/hgweb/webutil.py
diffstat 1 files changed, 12 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py	Fri Jun 10 20:38:02 2011 +0200
+++ b/mercurial/hgweb/webutil.py	Thu Jun 09 01:14:22 2011 +0800
@@ -212,24 +212,23 @@
                lines=prettyprintlines(''.join(block)))
 
 def diffstat(tmpl, ctx, parity):
-    '''Return a diffstat template for each file in the cset.'''
+    '''Return a diffstat template for each file in the diff.'''
 
     stats = patch.diffstatdata(util.iterlines(ctx.diff()))
     maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats)
+    files = ctx.files()
 
-    statsdict = {}
-    if maxtotal > 0:
-        for filename, adds, removes, isbinary in stats:
-            total = adds + removes
-            addpct = (float(adds) / maxtotal) * 100
-            removepct = (float(removes) / maxtotal) * 100
-            statsdict[filename] = (total, addpct, removepct)
+    def pct(i):
+        if maxtotal == 0:
+            return 0
+        return (float(i) / maxtotal) * 100
 
-    for f in ctx.files():
-        template = f in ctx and 'diffstatlink' or 'diffstatnolink'
-        total, addpct, removepct = statsdict.get(f, ('', 0, 0))
-        yield tmpl(template, node=ctx.hex(), file=f, total=total,
-            addpct=addpct, removepct=removepct, parity=parity.next())
+    for filename, adds, removes, isbinary in stats:
+        template = filename in files and 'diffstatlink' or 'diffstatnolink'
+        total = adds + removes
+        yield tmpl(template, node=ctx.hex(), file=filename,
+                   total=total, addpct=pct(adds), removepct=pct(removes),
+                   parity=parity.next())
 
 class sessionvars(object):
     def __init__(self, vars, start='?'):