# HG changeset patch # User Ian Moody # Date 1570370086 -3600 # Node ID f742fabad507aa0c193d4d1b5d8b04a911027076 # Parent 75e7628b488fe00e993bc1b8b4c1a8a81276e369 phabricator: add the maketext function This add the diff data for a text file to a phabchange. Differential Revision: https://phab.mercurial-scm.org/D7045 diff -r 75e7628b488f -r f742fabad507 hgext/phabricator.py --- a/hgext/phabricator.py Sun Oct 06 14:53:03 2019 +0100 +++ b/hgext/phabricator.py Sun Oct 06 14:54:46 2019 +0100 @@ -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()