Patchwork [5,of,7,V4] hgweb: add a 'linerange' parameter to webutil.diffs()

mail settings
Submitter Denis Laxalde
Date March 24, 2017, 7:57 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/19627/
State Superseded
Headers show


Denis Laxalde - March 24, 2017, 7:57 a.m.
# HG changeset patch
# User Denis Laxalde <>
# Date 1489414549 -3600
#      Mon Mar 13 15:15:49 2017 +0100
# Node ID 30d2823af2d2f38a3bb2adc8e925b61f0b1b1098
# Parent  3981358ae1e7b458e3152230740954f3ccfa4c3c
# Available At
#              hg pull -r 30d2823af2d2
# 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/ b/mercurial/hgweb/
--- a/mercurial/hgweb/
+++ b/mercurial/hgweb/
@@ -434,7 +434,7 @@  def listfilediffs(tmpl, files, node, max
     if len(files) > max:
         yield tmpl('fileellipses')
-def diffs(wep, tmpl, ctx, basectx, files, style):
+def diffs(web, tmpl, ctx, basectx, files, style, linerange=None):
     def prettyprintlines(lines, blockno):
         for lineno, l in enumerate(lines, 1):
@@ -470,6 +470,11 @@  def diffs(wep, tmpl, ctx, basectx, files
             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
         if lines:
             yield tmpl('diffblock', parity=next(parity), blockno=blockno,