Patchwork D7045: phabricator: add the maketext function

login
register
mail settings
Submitter phabricator
Date Oct. 10, 2019, 9:52 p.m.
Message ID <differential-rev-PHID-DREV-hpfzh6z6kmytesb25u23-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42201/
State Superseded
Headers show

Comments

phabricator - Oct. 10, 2019, 9:52 p.m.
Kwan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This add the diff data for a text file to a phabchange.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/phabricator.py

CHANGE DETAILS




To: Kwan, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 12, 2019, 1:46 a.m.
This revision is now accepted and ready to land.
indygreg added inline comments.
indygreg accepted this revision.

INLINE COMMENTS

> phabricator.py:557
> +    diffopts = mdiff.diffopts(git=True, context=32767)
> +    _pfctx, _fctx, header, fhunks = next(
> +        patch.diffhunks(repo, ctx.p1(), ctx, fmatcher, opts=diffopts)

The use of a single `next()` is a bit weird. But I suppose it gets the job done since we're expecting at most one file's diff.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7045/new/

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

To: Kwan, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/hgext/phabricator.py b/hgext/phabricator.py
--- a/hgext/phabricator.py
+++ b/hgext/phabricator.py
@@ -58,6 +58,7 @@ 
     error,
     exthelper,
     httpconnection as httpconnectionmod,
+    match,
     mdiff,
     obsutil,
     parser,
@@ -548,6 +549,36 @@ 
         self.changes[change.currentPath] = change
 
 
+def maketext(pchange, ctx, fname):
+    """populate the phabchange for a text file"""
+    repo = ctx.repo()
+    fmatcher = match.exact([fname])
+    diffopts = mdiff.diffopts(git=True, context=32767)
+    _pfctx, _fctx, header, fhunks = next(
+        patch.diffhunks(repo, ctx.p1(), ctx, fmatcher, opts=diffopts)
+    )
+
+    for fhunk in fhunks:
+        (oldOffset, oldLength, newOffset, newLength), lines = fhunk
+        corpus = b''.join(lines[1:])
+        shunk = list(header)
+        shunk.extend(lines)
+        _mf, _mt, addLines, delLines, _hb = patch.diffstatsum(
+            patch.diffstatdata(util.iterlines(shunk))
+        )
+        pchange.addhunk(
+            phabhunk(
+                oldOffset,
+                oldLength,
+                newOffset,
+                newLength,
+                corpus,
+                addLines,
+                delLines,
+            )
+        )
+
+
 def creatediff(ctx):
     """create a Differential Diff"""
     repo = ctx.repo()