[PATCH 5 of 7 V3] hgweb: add a 'linerange' parameter to webutil.diffs()

Denis Laxalde denis at laxalde.org
Wed Mar 22 06:37:30 EDT 2017


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1489414549 -3600
#      Mon Mar 13 15:15:49 2017 +0100
# Node ID 18d413236b1670c476584c4a6d6e103639ae7996
# Parent  1fb2e7f3ed38dc79379cccb04133e745fd5825fa
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 18d413236b16
# EXP-Topic linerange-log/hgweb-filelog
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.

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -434,7 +434,7 @@ def listfilediffs(tmpl, files, node, max
     if len(files) > max:
         yield tmpl('fileellipses')
 
-def diffs(repo, tmpl, ctx, basectx, files, style):
+def diffs(repo, tmpl, ctx, basectx, files, style, linerange=None):
 
     def prettyprintlines(lines, blockno):
         for lineno, l in enumerate(lines, 1):
@@ -468,6 +468,11 @@ def diffs(repo, tmpl, ctx, basectx, file
             header = header[1:]
         lines = [h + '\n' for h in header]
         for hunkrange, hunklines in hunks:
+            if linerange is not None and hunkrange is not None:
+                s1, l1, s2, l2 = hunkrange
+                lb, ub = linerange
+                if not (lb <= s2 < ub or lb < s2 + l2 <= ub):
+                    continue
             lines.extend(hunklines)
         if lines:
             yield tmpl('diffblock', blockno=blockno,


More information about the Mercurial-devel mailing list