D4997: absorb: use a formatter to generate output

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Sat Oct 13 01:43:49 EDT 2018


yuja added a comment.


  > +        fm.startitem()
  >  +        fm.write('hunk', '        %s\n',
  >  +                 '@@ -%d,%d +%d,%d @@'
  >  +                 % (a1, a2 - a1, b1, b2 - b1), label='diff.hunk')
  >  +        fm.data(path=self.path, linetype='hunk')
  >  +
  >  +        def writeline(idx, diffchar, line, linetype, linelabel):
  >  +            fm.startitem()
  >  +            node = ''
  >  +            if idx:
  >  +                ctx = self.fctxs[idx]
  >  +                fm.context(fctx=ctx)
  >  +                node = ctx.hex()
  >  +            fm.write('node', '%-7.7s ', node, label='absorb.node')
  >  +            fm.write('diffchar ' + linetype, '%s%s\n', diffchar, line,
  >  +                     label=linelabel)
  
  Nit: maybe rename `"diffchar"` to `"change"`? It's called as such in "hg grep".
  https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Dictionary
  
  > +            fm.data(path=self.path, linetype=linetype)
  >  +
  >  +        for i in pycompat.xrange(a1, a2):
  >  +            writeline(aidxs[i - a1], '-', trim(alines[i]), 'deleted',
  >  +                      'diff.deleted')
  >  +        for i in pycompat.xrange(b1, b2):
  >  +            writeline(bidxs[i - b1], '+', trim(blines[i]), 'inserted',
  >  +                      'diff.inserted')
  
  Perhaps, it's better to make deleted/inserted lines nested to preserve the
  original data structure.
  
    {"hunk", ...,
     "deletedlines": [{"line": ...}, ...]
     "insertedlines": ...}
  
  or
  
    {"hunk", ...,
     "lines": [{"line": ..., "deleted": True}, ...]}
  
  instead of
  
    {"hunk", ...},
    {"deleted": ...},
    {"inserted": ...},

REPOSITORY
  rHG Mercurial

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

To: mbthomas, #hg-reviewers, indygreg
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list