diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -262,10 +262,10 @@ def changeset(web, req, tmpl): files = [] parity = paritygen(web.stripecount) - for f in ctx.files(): + for blockno, f in enumerate(ctx.files()): template = f in ctx and 'filenodelink' or 'filenolink' files.append(tmpl(template, - node=ctx.hex(), file=f, + node=ctx.hex(), file=f, blockno=blockno + 1, parity=parity.next())) 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 @@ -173,8 +173,7 @@ def diffs(repo, tmpl, ctx, files, parity start += 1 blockcount = countgen() - def prettyprintlines(diff): - blockno = blockcount.next() + def prettyprintlines(diff, blockno): for lineno, l in enumerate(diff.splitlines(True)): lineno = "%d.%d" % (blockno, lineno + 1) if l.startswith('+'): @@ -203,14 +202,16 @@ def diffs(repo, tmpl, ctx, files, parity block = [] for chunk in patch.diff(repo, node1, node2, m, opts=diffopts): if chunk.startswith('diff') and block: - yield tmpl('diffblock', parity=parity.next(), - lines=prettyprintlines(''.join(block))) + blockno = blockcount.next() + yield tmpl('diffblock', parity=parity.next(), blockno=blockno, + lines=prettyprintlines(''.join(block), blockno)) block = [] if chunk.startswith('diff') and style != 'raw': chunk = ''.join(chunk.splitlines(True)[1:]) block.append(chunk) - yield tmpl('diffblock', parity=parity.next(), - lines=prettyprintlines(''.join(block))) + blockno = blockcount.next() + yield tmpl('diffblock', parity=parity.next(), blockno=blockno, + lines=prettyprintlines(''.join(block), blockno)) def diffstatgen(ctx): '''Generator function that provides the diffstat data.''' diff --git a/tests/test-hgweb-diffs.t b/tests/test-hgweb-diffs.t --- a/tests/test-hgweb-diffs.t +++ b/tests/test-hgweb-diffs.t @@ -552,6 +552,51 @@ test import rev as raw-rev $ cd test1 $ hg import -q --exact http://localhost:$HGPORT/rev/1 +raw revision with diff block numbers + + $ "$TESTDIR/killdaemons.py" + $ cat < .hg/hgrc + > [web] + > templates = rawdiff + > EOF + $ mkdir rawdiff + $ cat < rawdiff/map + > mimetype = 'text/plain; charset={encoding}' + > changeset = '{diff}' + > difflineplus = '{line}' + > difflineminus = '{line}' + > difflineat = '{line}' + > diffline = '{line}' + > filenodelink = '' + > filenolink = '' + > fileline = '{line}' + > diffblock = 'Block: {blockno}\n{lines}\n' + > EOF + $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log + $ cat hg.pid >> $DAEMON_PIDS + $ "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/raw-rev/0' + 200 Script output follows + + Block: 1 + diff -r 000000000000 -r 0cd96de13884 a + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/a Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +a + + Block: 2 + diff -r 000000000000 -r 0cd96de13884 b + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/b Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +b + + $ "$TESTDIR/killdaemons.py" + $ rm .hg/hgrc rawdiff/map + $ rmdir rawdiff + $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log + $ cat hg.pid >> $DAEMON_PIDS + errors $ cat ../test/errors.log