Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hgweb/webutil.py @ 14490:1d3e2349304a
web: provide diffstat to the changeset page
This includes all affected files, so it can be used for an extended view of
the files or as a replacement for the filenodelink and filenolink templates.
author | Steven Brown <StevenGBrown@gmail.com> |
---|---|
date | Sat, 28 May 2011 14:44:45 +0800 |
parents | 421d56a055fd |
children | 925d9f2b188b |
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py Tue May 31 16:24:47 2011 -0500 +++ b/mercurial/hgweb/webutil.py Sat May 28 14:44:45 2011 +0800 @@ -7,7 +7,7 @@ # GNU General Public License version 2 or any later version. import os, copy -from mercurial import match, patch, scmutil, error, ui +from mercurial import match, patch, scmutil, error, ui, util from mercurial.node import hex, nullid def up(p): @@ -211,6 +211,26 @@ yield tmpl('diffblock', parity=parity.next(), lines=prettyprintlines(''.join(block))) +def diffstat(tmpl, ctx, parity): + '''Return a diffstat template for each file in the cset.''' + + stats = patch.diffstatdata(util.iterlines(ctx.diff())) + maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats) + + 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) + + 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()) + class sessionvars(object): def __init__(self, vars, start='?'): self.start = start