comparison mercurial/templatekw.py @ 42405:0c72eddb4be5

templatekw: make {file_*} compare to both merge parents (issue4292) This redefines the {file_adds}, {file_dels}, {file_mods} template keywords by getting the lists from the recently introduced context methods instead of getting them from status compared to p1. As mentioned before, these are better defined on merge commits. The total number of files from the three lists now always add up to the number of files in {files}. I timed this command: hg log -r 4.0::5.0 -T '{rev}\n {file_mods}\n {file_adds}\n {file_dels}\n' It went from 7.6s to 5.6s with this patch. So it's actually faster than before. Note that the "files:" field in the bazaar test log output was using "{file_mods}" (not "{files}" as one might think based on the label). Differential Revision: https://phab.mercurial-scm.org/D6369
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 18 Apr 2019 13:35:02 -0700
parents b47e9712000b
children dc5bd66a8270
comparison
equal deleted inserted replaced
42404:0c0a22f5b0b5 42405:0c72eddb4be5
288 revcache['filestatusmap'] = statmap = {} 288 revcache['filestatusmap'] = statmap = {}
289 for char, files in zip(pycompat.iterbytestr('MAR!?IC'), stat): 289 for char, files in zip(pycompat.iterbytestr('MAR!?IC'), stat):
290 statmap.update((f, char) for f in files) 290 statmap.update((f, char) for f in files)
291 return revcache['filestatusmap'] # {path: statchar} 291 return revcache['filestatusmap'] # {path: statchar}
292 292
293 def _showfilesbystat(context, mapping, name, index):
294 stat = _getfilestatus(context, mapping)
295 files = stat[index]
296 return templateutil.compatfileslist(context, mapping, name, files)
297
298 @templatekeyword('file_copies', 293 @templatekeyword('file_copies',
299 requires={'repo', 'ctx', 'cache', 'revcache'}) 294 requires={'repo', 'ctx', 'cache', 'revcache'})
300 def showfilecopies(context, mapping): 295 def showfilecopies(context, mapping):
301 """List of strings. Files copied in this changeset with 296 """List of strings. Files copied in this changeset with
302 their sources. 297 their sources.
330 copies) 325 copies)
331 326
332 @templatekeyword('file_adds', requires={'ctx', 'revcache'}) 327 @templatekeyword('file_adds', requires={'ctx', 'revcache'})
333 def showfileadds(context, mapping): 328 def showfileadds(context, mapping):
334 """List of strings. Files added by this changeset.""" 329 """List of strings. Files added by this changeset."""
335 return _showfilesbystat(context, mapping, 'file_add', 1) 330 ctx = context.resource(mapping, 'ctx')
331 return templateutil.compatfileslist(context, mapping, 'file_add',
332 ctx.filesadded())
336 333
337 @templatekeyword('file_dels', requires={'ctx', 'revcache'}) 334 @templatekeyword('file_dels', requires={'ctx', 'revcache'})
338 def showfiledels(context, mapping): 335 def showfiledels(context, mapping):
339 """List of strings. Files removed by this changeset.""" 336 """List of strings. Files removed by this changeset."""
340 return _showfilesbystat(context, mapping, 'file_del', 2) 337 ctx = context.resource(mapping, 'ctx')
338 return templateutil.compatfileslist(context, mapping, 'file_del',
339 ctx.filesremoved())
341 340
342 @templatekeyword('file_mods', requires={'ctx', 'revcache'}) 341 @templatekeyword('file_mods', requires={'ctx', 'revcache'})
343 def showfilemods(context, mapping): 342 def showfilemods(context, mapping):
344 """List of strings. Files modified by this changeset.""" 343 """List of strings. Files modified by this changeset."""
345 return _showfilesbystat(context, mapping, 'file_mod', 0) 344 ctx = context.resource(mapping, 'ctx')
345 return templateutil.compatfileslist(context, mapping, 'file_mod',
346 ctx.filesmodified())
346 347
347 @templatekeyword('files', requires={'ctx'}) 348 @templatekeyword('files', requires={'ctx'})
348 def showfiles(context, mapping): 349 def showfiles(context, mapping):
349 """List of strings. All files modified, added, or removed by this 350 """List of strings. All files modified, added, or removed by this
350 changeset. 351 changeset.