# HG changeset patch # User Steven Brown # Date 2011-05-28 06:44:45 # Node ID 1d3e2349304aa003907410f8ddcdaec4a23848d1 # Parent 3a27faf9a999261344774e560c42991b1ceaa2d9 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. diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -263,12 +263,16 @@ def changeset(web, req, tmpl): node=ctx.hex(), file=f, parity=parity.next())) - parity = paritygen(web.stripecount) style = web.config('web', 'style', 'paper') if 'style' in req.form: style = req.form['style'][0] + parity = paritygen(web.stripecount) diffs = webutil.diffs(web.repo, tmpl, ctx, None, parity, style) + + parity = paritygen(web.stripecount) + diffstat = lambda: webutil.diffstat(tmpl, ctx, parity) + return tmpl('changeset', diff=diffs, rev=ctx.rev(), @@ -282,6 +286,7 @@ def changeset(web, req, tmpl): desc=ctx.description(), date=ctx.date(), files=files, + diffstat=diffstat, archives=web.archivelist(ctx.hex()), tags=webutil.nodetagsdict(web.repo, ctx.node()), bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()), diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py +++ b/mercurial/hgweb/webutil.py @@ -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 @@ def diffs(repo, tmpl, ctx, files, parity 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