comparison mercurial/templatekw.py @ 38584:4bc96c755c17

templatekw: obtain ui directly from the template context
author Yuya Nishihara <yuya@tcha.org>
date Fri, 06 Jul 2018 21:29:05 +0900
parents 64f15e22f4f8
children b62000a28812
comparison
equal deleted inserted replaced
38583:7f4bf8110150 38584:4bc96c755c17
256 elif isinstance(s, encoding.safelocalstr): 256 elif isinstance(s, encoding.safelocalstr):
257 return encoding.safelocalstr(s.strip()) 257 return encoding.safelocalstr(s.strip())
258 else: 258 else:
259 return s.strip() 259 return s.strip()
260 260
261 @templatekeyword('diffstat', requires={'ctx'}) 261 @templatekeyword('diffstat', requires={'ui', 'ctx'})
262 def showdiffstat(context, mapping): 262 def showdiffstat(context, mapping):
263 """String. Statistics of changes with the following format: 263 """String. Statistics of changes with the following format:
264 "modified files: +added/-removed lines" 264 "modified files: +added/-removed lines"
265 """ 265 """
266 ctx = context.resource(mapping, 'ctx') 266 ui = context.resource(mapping, 'ui')
267 diffopts = diffutil.diffopts(ctx._repo.ui, {'noprefix': False}) 267 ctx = context.resource(mapping, 'ctx')
268 diffopts = diffutil.diffopts(ui, {'noprefix': False})
268 diff = ctx.diff(opts=diffopts) 269 diff = ctx.diff(opts=diffopts)
269 stats = patch.diffstatdata(util.iterlines(diff)) 270 stats = patch.diffstatdata(util.iterlines(diff))
270 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats) 271 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
271 return '%d: +%d/-%d' % (len(stats), adds, removes) 272 return '%d: +%d/-%d' % (len(stats), adds, removes)
272 273