D6369: templatekw: get file_{adds, mods, dels} directly from context (issue4292)

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sat May 11 07:18:49 UTC 2019


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This redefines the template keywords by getting the lists from the
  recently introduced context methods instead of getting them from
  status compared to p1. A 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.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/templatekw.py
  tests/test-template-keywords.t

CHANGE DETAILS

diff --git a/tests/test-template-keywords.t b/tests/test-template-keywords.t
--- a/tests/test-template-keywords.t
+++ b/tests/test-template-keywords.t
@@ -809,9 +809,9 @@
   $ hg log -l1 -T '{files}\n'
   a fourth
   $ hg log -l1 -T '{file_mods}\n'
-  third
+  
   $ hg log -l1 -T '{file_adds}\n'
-  b fifth
+  
   $ hg log -l1 -T '{file_dels}\n'
   a fourth
 
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -290,15 +290,12 @@
             statmap.update((f, char) for f in files)
     return revcache['filestatusmap']  # {path: statchar}
 
-def _showfilesbystat(context, mapping, name, index):
-    stat = _getfilestatus(context, mapping)
-    files = stat[index]
-    return templateutil.compatfileslist(context, mapping, name, files)
-
 @templatekeyword('file_adds', requires={'ctx', 'revcache'})
 def showfileadds(context, mapping):
     """List of strings. Files added by this changeset."""
-    return _showfilesbystat(context, mapping, 'file_add', 1)
+    ctx = context.resource(mapping, 'ctx')
+    return templateutil.compatfileslist(context, mapping, 'file_add',
+                                        ctx.added())
 
 @templatekeyword('file_copies',
                  requires={'repo', 'ctx', 'cache', 'revcache'})
@@ -337,12 +334,16 @@
 @templatekeyword('file_dels', requires={'ctx', 'revcache'})
 def showfiledels(context, mapping):
     """List of strings. Files removed by this changeset."""
-    return _showfilesbystat(context, mapping, 'file_del', 2)
+    ctx = context.resource(mapping, 'ctx')
+    return templateutil.compatfileslist(context, mapping, 'file_del',
+                                        ctx.removed())
 
 @templatekeyword('file_mods', requires={'ctx', 'revcache'})
 def showfilemods(context, mapping):
     """List of strings. Files modified by this changeset."""
-    return _showfilesbystat(context, mapping, 'file_mod', 0)
+    ctx = context.resource(mapping, 'ctx')
+    return templateutil.compatfileslist(context, mapping, 'file_mod',
+                                        ctx.modified())
 
 @templatekeyword('files', requires={'ctx'})
 def showfiles(context, mapping):



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list