changeset 41618:e834f6f6f221

patch: pass in context objects into diffhunks() (API) It's a pretty low-level function and having the contexts in patch.diff() makes future patches easier. Differential Revision: https://phab.mercurial-scm.org/D5891
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 06 Feb 2019 17:27:43 -0800
parents 36ee0d6d64c5
children 035cae1d197f
files mercurial/hgweb/webutil.py mercurial/patch.py
diffstat 2 files changed, 9 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py	Thu Feb 07 21:48:50 2019 +0300
+++ b/mercurial/hgweb/webutil.py	Wed Feb 06 17:27:43 2019 -0800
@@ -570,11 +570,9 @@
         m = match.always(repo.root, repo.getcwd())
 
     diffopts = patch.diffopts(repo.ui, untrusted=True)
-    node1 = basectx.node()
-    node2 = ctx.node()
     parity = paritygen(stripecount)
 
-    diffhunks = patch.diffhunks(repo, node1, node2, m, opts=diffopts)
+    diffhunks = patch.diffhunks(repo, basectx, ctx, m, opts=diffopts)
     for blockno, (fctx1, fctx2, header, hunks) in enumerate(diffhunks, 1):
         if style != 'raw':
             header = header[1:]
--- a/mercurial/patch.py	Thu Feb 07 21:48:50 2019 +0300
+++ b/mercurial/patch.py	Wed Feb 06 17:27:43 2019 -0800
@@ -2268,8 +2268,14 @@
     hunksfilterfn, if not None, should be a function taking a filectx and
     hunks generator that may yield filtered hunks.
     '''
+    if not node1 and not node2:
+        node1 = repo.dirstate.p1()
+
+    ctx1 = repo[node1]
+    ctx2 = repo[node2]
+
     for fctx1, fctx2, hdr, hunks in diffhunks(
-            repo, node1=node1, node2=node2,
+            repo, ctx1=ctx1, ctx2=ctx2,
             match=match, changes=changes, opts=opts,
             losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy,
     ):
@@ -2286,7 +2292,7 @@
         if text:
             yield text
 
-def diffhunks(repo, node1=None, node2=None, match=None, changes=None,
+def diffhunks(repo, ctx1, ctx2, match=None, changes=None,
               opts=None, losedatafn=None, prefix='', relroot='', copy=None):
     """Yield diff of changes to files in the form of (`header`, `hunks`) tuples
     where `header` is a list of diff headers and `hunks` is an iterable of
@@ -2298,9 +2304,6 @@
     if opts is None:
         opts = mdiff.defaultopts
 
-    if not node1 and not node2:
-        node1 = repo.dirstate.p1()
-
     def lrugetfilectx():
         cache = {}
         order = collections.deque()
@@ -2317,9 +2320,6 @@
         return getfilectx
     getfilectx = lrugetfilectx()
 
-    ctx1 = repo[node1]
-    ctx2 = repo[node2]
-
     if relroot:
         relrootmatch = scmutil.match(ctx2, pats=[relroot], default='path')
         match = matchmod.intersectmatchers(match, relrootmatch)