[Request] [+- ] D8968: phabricator: Pass through diffoptions

sfink (Steve Fink) phabricator at mercurial-scm.org
Fri Aug 28 21:00:28 UTC 2020


sfink created this revision.
sfink added a comment.
Herald added subscribers: mercurial-patches, Kwan.
Herald added a reviewer: hg-reviewers.


  Nothing uses this directly, but it makes it much easier to another extension to call into this code and be able to request different diff options

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8968

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -718,11 +718,12 @@
         )
 
 
-def maketext(pchange, basectx, ctx, fname):
+def maketext(pchange, basectx, ctx, fname, options={}):
     """populate the phabchange for a text file"""
     repo = ctx.repo()
     fmatcher = match.exact([fname])
-    diffopts = mdiff.diffopts(git=True, context=32767)
+    context = options.get(b'context', 32767)
+    diffopts = mdiff.diffopts(git=True, context=context)
     _pfctx, _fctx, header, fhunks = next(
         patch.diffhunks(repo, basectx.p1(), ctx, fmatcher, opts=diffopts)
     )
@@ -884,7 +885,7 @@
         pdiff.addchange(pchange)
 
 
-def addmodified(pdiff, basectx, ctx, modified):
+def addmodified(pdiff, basectx, ctx, modified, diffoptions):
     """add modified files to the phabdiff"""
     for fname in modified:
         fctx = ctx[fname]
@@ -905,12 +906,12 @@
             makebinary(pchange, fctx)
             addoldbinary(pchange, oldfctx, fctx)
         else:
-            maketext(pchange, basectx, ctx, fname)
+            maketext(pchange, basectx, ctx, fname, diffoptions)
 
         pdiff.addchange(pchange)
 
 
-def addadded(pdiff, basectx, ctx, added, removed):
+def addadded(pdiff, basectx, ctx, added, removed, diffoptions):
     """add file adds to the phabdiff, both new files and copies/moves"""
     # Keep track of files that've been recorded as moved/copied, so if there are
     # additional copies we can mark them (moves get removed from removed)
@@ -983,7 +984,7 @@
             if renamed:
                 addoldbinary(pchange, oldfctx, fctx)
         else:
-            maketext(pchange, basectx, ctx, fname)
+            maketext(pchange, basectx, ctx, fname, diffoptions)
 
         pdiff.addchange(pchange)
 
@@ -993,7 +994,7 @@
         pdiff.addchange(movedchange)
 
 
-def creatediff(basectx, ctx):
+def creatediff(basectx, ctx, diffoptions={}):
     """create a Differential Diff"""
     repo = ctx.repo()
     repophid = getrepophid(repo)
@@ -1005,8 +1006,8 @@
     modified, added, removed, _d, _u, _i, _c = basectx.p1().status(ctx)
     # addadded will remove moved files from removed, so addremoved won't get
     # them
-    addadded(pdiff, basectx, ctx, added, removed)
-    addmodified(pdiff, basectx, ctx, modified)
+    addadded(pdiff, basectx, ctx, added, removed, diffoptions)
+    addmodified(pdiff, basectx, ctx, modified, diffoptions)
     addremoved(pdiff, basectx, ctx, removed)
     if repophid:
         pdiff.repositoryPHID = repophid
@@ -1078,6 +1079,7 @@
     olddiff=None,
     actions=None,
     comment=None,
+    diffoptions={},
 ):
     """create or update a Differential Revision
 
@@ -1115,7 +1117,7 @@
 
     transactions = []
     if neednewdiff:
-        diff = creatediff(basectx, ctx)
+        diff = creatediff(basectx, ctx, diffoptions)
         transactions.append({b'type': b'update', b'value': diff[b'phid']})
         if comment:
             transactions.append({b'type': b'comment', b'value': comment})
@@ -1387,6 +1389,7 @@
     if phids:
         actions.append({b'type': b'reviewers.add', b'value': phids})
 
+    diffoptions = {}
     drevids = []  # [int]
     diffmap = {}  # {newnode: diff}
 
@@ -1419,6 +1422,7 @@
                 olddiff,
                 actions,
                 opts.get(b'comment'),
+                diffoptions,
             )
 
             if fold:



To: sfink, #hg-reviewers
Cc: Kwan, mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200828/15b30df9/attachment-0001.html>


More information about the Mercurial-patches mailing list