[PATCH 2 of 4 v2] diff: also yield file context objects in patch.trydiff()

Denis Laxalde denis at laxalde.org
Fri Oct 6 15:01:26 EDT 2017


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1507231208 -7200
#      Thu Oct 05 21:20:08 2017 +0200
# Node ID 2727029988a085830fb9eac444d7b37b7d8b98ed
# Parent  947254876fc535ab622a8eff43b88fe88df90924
# EXP-Topic followlines-cli/v2
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.

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -478,7 +478,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
@@ -2316,10 +2316,11 @@ def diff(repo, node1=None, node2=None, m
 
     copy, if not empty, should contain mappings {dst at y: src at x} of copy
     information.'''
-    for header, 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, header, 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 header and (text or len(header) > 1):
             yield '\n'.join(header) + '\n'
@@ -2684,7 +2685,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


More information about the Mercurial-devel mailing list