Change absorb to use a formatter to generate its output. This allows the use
of templates to customize the output.
Details
- Reviewers
indygreg - Group Reviewers
hg-reviewers - Commits
- rHGdcda50856843: absorb: use a formatter to generate output
Diff Detail
- Repository
- rHG Mercurial
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Event Timeline
+ 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": ...},