mercurial/hgweb/webutil.py
changeset 14561 925d9f2b188b
parent 14490 1d3e2349304a
child 14562 fccd3b966da7
equal deleted inserted replaced
14560:0980239cb20c 14561:925d9f2b188b
   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):
   214 def diffstat(tmpl, ctx, parity):
   215     '''Return a diffstat template for each file in the cset.'''
   215     '''Return a diffstat template for each file in the diff.'''
   216 
   216 
   217     stats = patch.diffstatdata(util.iterlines(ctx.diff()))
   217     stats = patch.diffstatdata(util.iterlines(ctx.diff()))
   218     maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats)
   218     maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats)
   219 
   219     files = ctx.files()
   220     statsdict = {}
   220 
   221     if maxtotal > 0:
   221     def pct(i):
   222         for filename, adds, removes, isbinary in stats:
   222         if maxtotal == 0:
   223             total = adds + removes
   223             return 0
   224             addpct = (float(adds) / maxtotal) * 100
   224         return (float(i) / maxtotal) * 100
   225             removepct = (float(removes) / maxtotal) * 100
   225 
   226             statsdict[filename] = (total, addpct, removepct)
   226     for filename, adds, removes, isbinary in stats:
   227 
   227         template = filename in files and 'diffstatlink' or 'diffstatnolink'
   228     for f in ctx.files():
   228         total = adds + removes
   229         template = f in ctx and 'diffstatlink' or 'diffstatnolink'
   229         yield tmpl(template, node=ctx.hex(), file=filename,
   230         total, addpct, removepct = statsdict.get(f, ('', 0, 0))
   230                    total=total, addpct=pct(adds), removepct=pct(removes),
   231         yield tmpl(template, node=ctx.hex(), file=f, total=total,
   231                    parity=parity.next())
   232             addpct=addpct, removepct=removepct, parity=parity.next())
       
   233 
   232 
   234 class sessionvars(object):
   233 class sessionvars(object):
   235     def __init__(self, vars, start='?'):
   234     def __init__(self, vars, start='?'):
   236         self.start = start
   235         self.start = start
   237         self.vars = vars
   236         self.vars = vars