diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -728,6 +728,9 @@ def summary(web, req, tmpl): archives=web.archivelist("tip"), labels=web.configlist('web', 'labels')) +def formatlinerange(fromline, toline): + return '%d-%d' % (fromline + 1, toline) + @webcommand('filediff') def filediff(web, req, tmpl): """ @@ -760,7 +763,24 @@ def filediff(web, req, tmpl): if 'style' in req.form: style = req.form['style'][0] - diffs = webutil.diffs(web.repo, tmpl, ctx, basectx, [path], parity, style) + lineranges = {} + linerange = webutil.linerange(req) + if linerange is not None: + assert fctx is not None + lineranges = {fctx: linerange} + ancestors = context.blockancestors(fctx, *linerange, followfirst=True) + try: + next(ancestors) # first iteration returns fctx + p, plinerange = next(ancestors) + except StopIteration: + pass + else: + lineranges[p] = plinerange + basectx = p.changectx() + linerange = formatlinerange(*linerange) + + diffs = webutil.diffs(web.repo, tmpl, ctx, basectx, [path], parity, style, + lineranges) if fctx is not None: rename = webutil.renamelink(fctx) ctx = fctx @@ -772,6 +792,7 @@ def filediff(web, req, tmpl): symrev=webutil.symrevorshortnode(req, ctx), rename=rename, diff=diffs, + linerange=linerange, **webutil.commonentry(web.repo, ctx)) diff = webcommand('diff')(filediff) @@ -970,9 +991,6 @@ def filelog(web, req, tmpl): lrange = webutil.linerange(req) - def formatlinerange(fromline, toline): - return '%d-%d' % (fromline + 1, toline) - lessvars = copy.copy(tmpl.defaults['sessionvars']) lessvars['revcount'] = max(revcount / 2, 1) morevars = copy.copy(tmpl.defaults['sessionvars']) diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py --- a/mercurial/hgweb/webutil.py +++ b/mercurial/hgweb/webutil.py @@ -431,7 +431,7 @@ def listfilediffs(tmpl, files, node, max if len(files) > max: yield tmpl('fileellipses') -def diffs(repo, tmpl, ctx, basectx, files, parity, style): +def diffs(repo, tmpl, ctx, basectx, files, parity, style, lineranges=None): def countgen(): start = 1 @@ -467,7 +467,8 @@ def diffs(repo, tmpl, ctx, basectx, file node2 = ctx.node() block = [] - for chunk in patch.diff(repo, node1, node2, m, opts=diffopts): + for chunk in patch.diff(repo, node1, node2, m, opts=diffopts, + lineranges=lineranges): if chunk.startswith('diff') and block: blockno = next(blockcount) yield tmpl('diffblock', parity=next(parity), blockno=blockno, diff --git a/mercurial/templates/gitweb/filediff.tmpl b/mercurial/templates/gitweb/filediff.tmpl --- a/mercurial/templates/gitweb/filediff.tmpl +++ b/mercurial/templates/gitweb/filediff.tmpl @@ -33,7 +33,9 @@ diff |
-
{file|escape}
+
\ +{file|escape}{if(linerange, ' (line range: {linerange} full diff)')}\ +
{branch%filerevbranch} 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 @@ -1094,6 +1094,305 @@ comparison not-modified file + $ cat < c + > 1 + > 2 + > 3 + > 4 + > 5 + > 6 + > EOF + $ hg ci -Amc c + $ cat < c + > 1 + > 2+ + > 3 + > 4 + > 5- + > 6 + > EOF + $ hg ci -m 'update c' c + $ get-with-headers.py localhost:$HGPORT 'diff/tip/c?style=gitweb' + 200 Script output follows + + + + + + + + + + + test: diff c + + + + + + + + + +
c
+ +
+ + + + + + + + + + + +
changeset 746dadddbce95
parent 6 + + 3deb5080745a + +
+ +
+ +
+
+  --- a/c
+  +++ b/c
+  @@ -1,6 +1,6 @@
+   1
+  -2
+  +2+
+   3
+   4
+  -5
+  +5-
+   6
+
+ + + + + + $ get-with-headers.py localhost:$HGPORT 'diff/tip/c?style=gitweb&linerange=1-3' + 200 Script output follows + + + + + + + + + + + test: diff c + + + + + + + + + +
c (line range: 1-3 full diff)
+ + + + + + + + + + + + + +
changeset 746dadddbce95
parent 6 + + 3deb5080745a + +
+ +
+ +
+
+  --- a/c
+  +++ b/c
+  @@ -1,5 +1,5 @@
+   1
+  -2
+  +2+
+   3
+   4
+   5
+
+ + + + + + $ get-with-headers.py localhost:$HGPORT 'diff/tip/c?style=gitweb&linerange=3-6' + 200 Script output follows + + + + + + + + + + + test: diff c + + + + + + + + + +
c (line range: 3-6 full diff)
+ + + + + + + + + + + + + +
changeset 746dadddbce95
parent 6 + + 3deb5080745a + +
+ +
+ +
+
+  --- a/c
+  +++ b/c
+  @@ -2,5 +2,5 @@
+   2
+   3
+   4
+  -5
+  +5-
+   6
+
+ + + + + $ cd .. test import rev as raw-rev