[PATCH 1 of 3 RFC] web: provide diffstat summary to the changeset page
Steven Brown
stevengbrown at gmail.com
Sun May 15 09:30:29 CDT 2011
# HG changeset patch
# User Steven Brown <StevenGBrown at gmail.com>
# Date 1305468546 -28800
# Node ID 18a3fe97e85bd3cda2ef5919e83520b68c07051a
# Parent a90131b85fd8fff71758114980eb9e7271492ea7
web: provide diffstat summary to the changeset page
Add the diffstat keyword to the filenodelink template.
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -257,11 +257,13 @@
files = []
parity = paritygen(web.stripecount)
+ diffstats = webutil.diffstathist(web.repo, ctx)
for f in ctx.files():
template = f in ctx and 'filenodelink' or 'filenolink'
files.append(tmpl(template,
node=ctx.hex(), file=f,
- parity=parity.next()))
+ parity=parity.next(),
+ diffstat=diffstats.get(f)))
parity = paritygen(web.stripecount)
style = web.config('web', 'style', 'paper')
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,13 @@
yield tmpl('diffblock', parity=parity.next(),
lines=prettyprintlines(''.join(block)))
+def diffstathist(repo, ctx):
+ '''Return a dictionary of file names to diffstat histograms.'''
+
+ lines = util.iterlines(ctx.diff())
+ diffopts = patch.diffopts(repo.ui, untrusted=True)
+ return patch.diffstathist(lines, git=diffopts.git)
+
class sessionvars(object):
def __init__(self, vars, start='?'):
self.start = start
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1622,8 +1622,11 @@
yield (filename, adds, removes, isbinary)
def diffstat(lines, width=80, git=False):
+ stats = list(diffstatdata(lines))
+ return _diffstat(stats, width, git)
+
+def _diffstat(stats, width=80, git=False):
output = []
- stats = list(diffstatdata(lines))
maxtotal, maxname = 0, 0
totaladds, totalremoves = 0, 0
@@ -1691,3 +1694,13 @@
else:
yield (line, '')
yield ('\n', '')
+
+def diffstathist(lines, **kw):
+ '''Return a dictionary of file names to diffstat histograms.'''
+
+ stats = list(diffstatdata(lines))
+ hist = {}
+ for stat, line in zip(stats, _diffstat(stats, **kw).splitlines()):
+ filename = stat[0]
+ hist[filename] = line[1 + len(filename):].lstrip()[1:]
+ return hist
More information about the Mercurial-devel
mailing list