Submitter | Denis Laxalde |
---|---|
Date | Feb. 22, 2017, 3:10 p.m. |
Message ID | <ddf1b3d89b595aa5b376.1487776200@sh77.tls.logilab.fr> |
Download | mbox | patch |
Permalink | /patch/18713/ |
State | Accepted |
Delegated to: | Yuya Nishihara |
Headers | show |
Comments
On Wed, 22 Feb 2017 16:10:00 +0100, Denis Laxalde wrote: > # HG changeset patch > # User Denis Laxalde <denis.laxalde@logilab.fr> > # Date 1484921270 -3600 > # Fri Jan 20 15:07:50 2017 +0100 > # Node ID ddf1b3d89b595aa5b376bb51a8edf458b8f1b1c8 > # Parent 9090c35a37b14e5e09d0911d4794b65ee9ed35de > # EXP-Topic linerange-log/hgweb-filelog > patch: add filtering by line ranges in diff() > > We add a "lineranges" parameter to patch.diff() that is mapping from filectx > to line range tuple (fromline, toline). This is used in getfilectx inner > function (used in patch.trydiff()) so that the latter returns the line range > associated with the filectx, if any. Then, in patch.trydiff() we pass this > information to mdiff.unidiff() where hunks will be filtered accordingly. > > diff --git a/mercurial/patch.py b/mercurial/patch.py > --- a/mercurial/patch.py > +++ b/mercurial/patch.py > @@ -2214,7 +2214,7 @@ def difffeatureopts(ui, opts=None, untru > return mdiff.diffopts(**buildopts) > > def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, > - losedatafn=None, prefix='', relroot='', copy=None): > + losedatafn=None, prefix='', relroot='', copy=None, lineranges=None): > '''yields diff of changes to files between two nodes, or node and > working directory. This API seems a bit odd, but I have no better idea. Can you update the function document in V2?
Patch
diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -2214,7 +2214,7 @@ def difffeatureopts(ui, opts=None, untru return mdiff.diffopts(**buildopts) def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, - losedatafn=None, prefix='', relroot='', copy=None): + losedatafn=None, prefix='', relroot='', copy=None, lineranges=None): '''yields diff of changes to files between two nodes, or node and working directory. @@ -2256,7 +2256,10 @@ def diff(repo, node1=None, node2=None, m else: order.remove(f) order.append(f) - return fctx + linerange = None + if lineranges is not None: + linerange = lineranges.get(fctx, None) + return fctx, linerange return getfilectx getfilectx = lrugetfilectx() @@ -2480,12 +2483,16 @@ def trydiff(repo, revs, ctx1, ctx2, modi content2 = None flag1 = None flag2 = None + linerange1 = None + linerange2 = None if f1: - content1 = getfilectx(f1, ctx1).data() + fctx1, linerange1 = getfilectx(f1, ctx1) + content1 = fctx1.data() if opts.git or losedatafn: flag1 = ctx1.flags(f1) if f2: - content2 = getfilectx(f2, ctx2).data() + fctx2, linerange2 = getfilectx(f2, ctx2) + content2 = fctx2.data() if opts.git or losedatafn: flag2 = ctx2.flags(f2) binary = False @@ -2549,7 +2556,8 @@ def trydiff(repo, revs, ctx1, ctx2, modi text = mdiff.unidiff(content1, date1, content2, date2, - path1, path2, opts=opts) + path1, path2, opts=opts, + rangea=linerange1, rangeb=linerange2) if header and (text or len(header) > 1): yield '\n'.join(header) + '\n' if text: