comparison 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
comparison
equal deleted inserted replaced
14489:3a27faf9a999 14490:1d3e2349304a
5 # 5 #
6 # This software may be used and distributed according to the terms of the 6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 import os, copy 9 import os, copy
10 from mercurial import match, patch, scmutil, error, ui 10 from mercurial import match, patch, scmutil, error, ui, util
11 from mercurial.node import hex, nullid 11 from mercurial.node import hex, nullid
12 12
13 def up(p): 13 def up(p):
14 if p[0] != "/": 14 if p[0] != "/":
15 p = "/" + p 15 p = "/" + p
209 chunk = ''.join(chunk.splitlines(True)[1:]) 209 chunk = ''.join(chunk.splitlines(True)[1:])
210 block.append(chunk) 210 block.append(chunk)
211 yield tmpl('diffblock', parity=parity.next(), 211 yield tmpl('diffblock', parity=parity.next(),
212 lines=prettyprintlines(''.join(block))) 212 lines=prettyprintlines(''.join(block)))
213 213
214 def diffstat(tmpl, ctx, parity):
215 '''Return a diffstat template for each file in the cset.'''
216
217 stats = patch.diffstatdata(util.iterlines(ctx.diff()))
218 maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats)
219
220 statsdict = {}
221 if maxtotal > 0:
222 for filename, adds, removes, isbinary in stats:
223 total = adds + removes
224 addpct = (float(adds) / maxtotal) * 100
225 removepct = (float(removes) / maxtotal) * 100
226 statsdict[filename] = (total, addpct, removepct)
227
228 for f in ctx.files():
229 template = f in ctx and 'diffstatlink' or 'diffstatnolink'
230 total, addpct, removepct = statsdict.get(f, ('', 0, 0))
231 yield tmpl(template, node=ctx.hex(), file=f, total=total,
232 addpct=addpct, removepct=removepct, parity=parity.next())
233
214 class sessionvars(object): 234 class sessionvars(object):
215 def __init__(self, vars, start='?'): 235 def __init__(self, vars, start='?'):
216 self.start = start 236 self.start = start
217 self.vars = vars 237 self.vars = vars
218 def __getitem__(self, key): 238 def __getitem__(self, key):