Patchwork [2,of,4,v4] diff: also yield file context objects in patch.trydiff()

login
register
mail settings
Submitter Denis Laxalde
Date Oct. 17, 2017, 7:36 p.m.
Message ID <c73893dd6cfb5693029f.1508269018@marimba>
Download mbox | patch
Permalink /patch/25134/
State Accepted
Headers show

Comments

Denis Laxalde - Oct. 17, 2017, 7:36 p.m.
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1507231208 -7200
#      Thu Oct 05 21:20:08 2017 +0200
# Node ID c73893dd6cfb5693029f5d9dcf1d537197b40a4a
# Parent  73dcd7f479a2481be007de11b03e834aec334ffd
# EXP-Topic followlines-cli
diff: also yield file context objects in patch.trydiff()

And retrieve them in patch.diffhunks(). We'll use these in forthcoming
changesets to filter diff hunks by line range.
Yuya Nishihara - Oct. 18, 2017, 1:43 p.m.
On Tue, 17 Oct 2017 21:36:58 +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde@logilab.fr>
> # Date 1507231208 -7200
> #      Thu Oct 05 21:20:08 2017 +0200
> # Node ID c73893dd6cfb5693029f5d9dcf1d537197b40a4a
> # Parent  73dcd7f479a2481be007de11b03e834aec334ffd
> # EXP-Topic followlines-cli
> diff: also yield file context objects in patch.trydiff()

Flagged this as API change.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -479,7 +479,7 @@  def diffs(web, tmpl, ctx, basectx, files
     parity = paritygen(web.stripecount)
 
     diffhunks = patch.diffhunks(repo, node1, node2, m, opts=diffopts)
-    for blockno, (header, hunks) in enumerate(diffhunks, 1):
+    for blockno, (fctx1, fctx2, header, hunks) in enumerate(diffhunks, 1):
         if style != 'raw':
             header = header[1:]
         lines = [h + '\n' for h in header]
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2319,10 +2319,11 @@  def diff(repo, node1=None, node2=None, m
 
     copy, if not empty, should contain mappings {dst@y: src@x} of copy
     information.'''
-    for hdr, hunks in diffhunks(repo, node1=node1, node2=node2, match=match,
-                                changes=changes, opts=opts,
-                                losedatafn=losedatafn, prefix=prefix,
-                                relroot=relroot, copy=copy):
+    for fctx1, fctx2, hdr, hunks in diffhunks(
+            repo, node1=node1, node2=node2,
+            match=match, changes=changes, opts=opts,
+            losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy,
+    ):
         text = ''.join(sum((list(hlines) for hrange, hlines in hunks), []))
         if hdr and (text or len(hdr) > 1):
             yield '\n'.join(hdr) + '\n'
@@ -2687,7 +2688,7 @@  def trydiff(repo, revs, ctx1, ctx2, modi
                                             content2, date2,
                                             path1, path2, opts=opts)
             header.extend(uheaders)
-        yield header, hunks
+        yield fctx1, fctx2, header, hunks
 
 def diffstatsum(stats):
     maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False