Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/webutil.py @ 14570:9f908ef5a595
web: provide diff summary to the changeset page
This is the same message displayed at the end of the "diff --stat" command.
For example, "9 files changed, 1651 insertions(+), 2 deletions(-)".
The webutil.diffstatgen function allows the diffstat data to be lazily
calculated only once and then re-used.
author | Steven Brown <StevenGBrown@gmail.com> |
---|---|
date | Sat, 11 Jun 2011 21:11:43 +0800 |
parents | fccd3b966da7 |
children | 16e5271b216f |
comparison
equal
deleted
inserted
replaced
14569:017ab404e588 | 14570:9f908ef5a595 |
---|---|
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, util | 10 from mercurial import match, patch, scmutil, error, ui, util |
11 from mercurial.i18n import _ | |
11 from mercurial.node import hex, nullid | 12 from mercurial.node import hex, nullid |
12 | 13 |
13 def up(p): | 14 def up(p): |
14 if p[0] != "/": | 15 if p[0] != "/": |
15 p = "/" + p | 16 p = "/" + p |
209 chunk = ''.join(chunk.splitlines(True)[1:]) | 210 chunk = ''.join(chunk.splitlines(True)[1:]) |
210 block.append(chunk) | 211 block.append(chunk) |
211 yield tmpl('diffblock', parity=parity.next(), | 212 yield tmpl('diffblock', parity=parity.next(), |
212 lines=prettyprintlines(''.join(block))) | 213 lines=prettyprintlines(''.join(block))) |
213 | 214 |
214 def diffstat(tmpl, ctx, parity): | 215 def diffstatgen(ctx): |
215 '''Return a diffstat template for each file in the diff.''' | 216 '''Generator function that provides the diffstat data.''' |
216 | 217 |
217 stats = patch.diffstatdata(util.iterlines(ctx.diff())) | 218 stats = patch.diffstatdata(util.iterlines(ctx.diff())) |
218 maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats) | 219 maxname, maxtotal, addtotal, removetotal, binary = patch.diffstatsum(stats) |
220 while True: | |
221 yield stats, maxname, maxtotal, addtotal, removetotal, binary | |
222 | |
223 def diffsummary(statgen): | |
224 '''Return a short summary of the diff.''' | |
225 | |
226 stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next() | |
227 return _(' %d files changed, %d insertions(+), %d deletions(-)\n') % ( | |
228 len(stats), addtotal, removetotal) | |
229 | |
230 def diffstat(tmpl, ctx, statgen, parity): | |
231 '''Return a diffstat template for each file in the diff.''' | |
232 | |
233 stats, maxname, maxtotal, addtotal, removetotal, binary = statgen.next() | |
219 files = ctx.files() | 234 files = ctx.files() |
220 | 235 |
221 def pct(i): | 236 def pct(i): |
222 if maxtotal == 0: | 237 if maxtotal == 0: |
223 return 0 | 238 return 0 |