Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/webutil.py @ 31666:aaebc80c9f1d
hgweb: add a 'linerange' parameter to webutil.diffs()
This is used to filter out hunks based on their range (with respect to 'node2'
for patch.diffhunks() call, i.e. 'ctx' for webutil.diffs()).
This is the simplest way to filter diff hunks, here done on server side. Later
on, it might be interesting to perform this filtering on client side and
expose a "toggle" action to alternate between full and filtered diff.
author | Denis Laxalde <denis.laxalde@logilab.fr> |
---|---|
date | Mon, 13 Mar 2017 15:15:49 +0100 |
parents | 5e6d44511317 |
children | cbe0bea82c79 |
comparison
equal
deleted
inserted
replaced
31665:5e6d44511317 | 31666:aaebc80c9f1d |
---|---|
432 for f in files[:max]: | 432 for f in files[:max]: |
433 yield tmpl('filedifflink', node=hex(node), file=f) | 433 yield tmpl('filedifflink', node=hex(node), file=f) |
434 if len(files) > max: | 434 if len(files) > max: |
435 yield tmpl('fileellipses') | 435 yield tmpl('fileellipses') |
436 | 436 |
437 def diffs(web, tmpl, ctx, basectx, files, style): | 437 def diffs(web, tmpl, ctx, basectx, files, style, linerange=None): |
438 | 438 |
439 def prettyprintlines(lines, blockno): | 439 def prettyprintlines(lines, blockno): |
440 for lineno, l in enumerate(lines, 1): | 440 for lineno, l in enumerate(lines, 1): |
441 difflineno = "%d.%d" % (blockno, lineno) | 441 difflineno = "%d.%d" % (blockno, lineno) |
442 if l.startswith('+'): | 442 if l.startswith('+'): |
468 for blockno, (header, hunks) in enumerate(diffhunks, 1): | 468 for blockno, (header, hunks) in enumerate(diffhunks, 1): |
469 if style != 'raw': | 469 if style != 'raw': |
470 header = header[1:] | 470 header = header[1:] |
471 lines = [h + '\n' for h in header] | 471 lines = [h + '\n' for h in header] |
472 for hunkrange, hunklines in hunks: | 472 for hunkrange, hunklines in hunks: |
473 if linerange is not None and hunkrange is not None: | |
474 s1, l1, s2, l2 = hunkrange | |
475 lb, ub = linerange | |
476 if not (lb <= s2 < ub or lb < s2 + l2 <= ub): | |
477 continue | |
473 lines.extend(hunklines) | 478 lines.extend(hunklines) |
474 if lines: | 479 if lines: |
475 yield tmpl('diffblock', parity=next(parity), blockno=blockno, | 480 yield tmpl('diffblock', parity=next(parity), blockno=blockno, |
476 lines=prettyprintlines(lines, blockno)) | 481 lines=prettyprintlines(lines, blockno)) |
477 | 482 |