hgext/phabricator.py
changeset 43186 f742fabad507
parent 43185 75e7628b488f
child 43187 453079605242
equal deleted inserted replaced
43185:75e7628b488f 43186:f742fabad507
    56     context,
    56     context,
    57     encoding,
    57     encoding,
    58     error,
    58     error,
    59     exthelper,
    59     exthelper,
    60     httpconnection as httpconnectionmod,
    60     httpconnection as httpconnectionmod,
       
    61     match,
    61     mdiff,
    62     mdiff,
    62     obsutil,
    63     obsutil,
    63     parser,
    64     parser,
    64     patch,
    65     patch,
    65     phases,
    66     phases,
   544 
   545 
   545     def addchange(self, change):
   546     def addchange(self, change):
   546         if not isinstance(change, phabchange):
   547         if not isinstance(change, phabchange):
   547             raise error.Abort(b'phabdiff.addchange only takes phabchanges')
   548             raise error.Abort(b'phabdiff.addchange only takes phabchanges')
   548         self.changes[change.currentPath] = change
   549         self.changes[change.currentPath] = change
       
   550 
       
   551 
       
   552 def maketext(pchange, ctx, fname):
       
   553     """populate the phabchange for a text file"""
       
   554     repo = ctx.repo()
       
   555     fmatcher = match.exact([fname])
       
   556     diffopts = mdiff.diffopts(git=True, context=32767)
       
   557     _pfctx, _fctx, header, fhunks = next(
       
   558         patch.diffhunks(repo, ctx.p1(), ctx, fmatcher, opts=diffopts)
       
   559     )
       
   560 
       
   561     for fhunk in fhunks:
       
   562         (oldOffset, oldLength, newOffset, newLength), lines = fhunk
       
   563         corpus = b''.join(lines[1:])
       
   564         shunk = list(header)
       
   565         shunk.extend(lines)
       
   566         _mf, _mt, addLines, delLines, _hb = patch.diffstatsum(
       
   567             patch.diffstatdata(util.iterlines(shunk))
       
   568         )
       
   569         pchange.addhunk(
       
   570             phabhunk(
       
   571                 oldOffset,
       
   572                 oldLength,
       
   573                 newOffset,
       
   574                 newLength,
       
   575                 corpus,
       
   576                 addLines,
       
   577                 delLines,
       
   578             )
       
   579         )
   549 
   580 
   550 
   581 
   551 def creatediff(ctx):
   582 def creatediff(ctx):
   552     """create a Differential Diff"""
   583     """create a Differential Diff"""
   553     repo = ctx.repo()
   584     repo = ctx.repo()