Mercurial > hg
comparison mercurial/hgweb/webutil.py @ 16308:2695aaf4eb72
hgweb: add block numbers to diff regions and related links
The changeset view may show several diff regions, one per file, and this patch
numbers each of them so that links produced by the filenodelink fragment can
reference each diff region produced by the diffblock fragment through the use
of the blockno variable made available to both of them. This permits
navigation to diff regions on the changeset page from the file list, and
where the :target pseudo-class is supported in browsers, permits selective
presentation of diffs, showing one at a time instead of potentially many in
what would otherwise be a very long page that is difficult to navigate.
author | Paul Boddie <paul@boddie.org.uk> |
---|---|
date | Fri, 23 Mar 2012 01:31:31 +0100 |
parents | 16e5271b216f |
children | e7bf09acd410 |
comparison
equal
deleted
inserted
replaced
16307:17a9a1f5cee2 | 16308:2695aaf4eb72 |
---|---|
171 while True: | 171 while True: |
172 yield start | 172 yield start |
173 start += 1 | 173 start += 1 |
174 | 174 |
175 blockcount = countgen() | 175 blockcount = countgen() |
176 def prettyprintlines(diff): | 176 def prettyprintlines(diff, blockno): |
177 blockno = blockcount.next() | |
178 for lineno, l in enumerate(diff.splitlines(True)): | 177 for lineno, l in enumerate(diff.splitlines(True)): |
179 lineno = "%d.%d" % (blockno, lineno + 1) | 178 lineno = "%d.%d" % (blockno, lineno + 1) |
180 if l.startswith('+'): | 179 if l.startswith('+'): |
181 ltype = "difflineplus" | 180 ltype = "difflineplus" |
182 elif l.startswith('-'): | 181 elif l.startswith('-'): |
201 node2 = ctx.node() | 200 node2 = ctx.node() |
202 | 201 |
203 block = [] | 202 block = [] |
204 for chunk in patch.diff(repo, node1, node2, m, opts=diffopts): | 203 for chunk in patch.diff(repo, node1, node2, m, opts=diffopts): |
205 if chunk.startswith('diff') and block: | 204 if chunk.startswith('diff') and block: |
206 yield tmpl('diffblock', parity=parity.next(), | 205 blockno = blockcount.next() |
207 lines=prettyprintlines(''.join(block))) | 206 yield tmpl('diffblock', parity=parity.next(), blockno=blockno, |
207 lines=prettyprintlines(''.join(block), blockno)) | |
208 block = [] | 208 block = [] |
209 if chunk.startswith('diff') and style != 'raw': | 209 if chunk.startswith('diff') and style != 'raw': |
210 chunk = ''.join(chunk.splitlines(True)[1:]) | 210 chunk = ''.join(chunk.splitlines(True)[1:]) |
211 block.append(chunk) | 211 block.append(chunk) |
212 yield tmpl('diffblock', parity=parity.next(), | 212 blockno = blockcount.next() |
213 lines=prettyprintlines(''.join(block))) | 213 yield tmpl('diffblock', parity=parity.next(), blockno=blockno, |
214 lines=prettyprintlines(''.join(block), blockno)) | |
214 | 215 |
215 def diffstatgen(ctx): | 216 def diffstatgen(ctx): |
216 '''Generator function that provides the diffstat data.''' | 217 '''Generator function that provides the diffstat data.''' |
217 | 218 |
218 stats = patch.diffstatdata(util.iterlines(ctx.diff())) | 219 stats = patch.diffstatdata(util.iterlines(ctx.diff())) |