Mercurial > hg-stable
changeset 42424: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 | 0c0a22f5b0b5 |
children | f385ba70e4af |
files | mercurial/templatekw.py relnotes/next tests/test-convert-bzr-merges.t tests/test-convert-bzr.t tests/test-template-keywords.t |
diffstat | 5 files changed, 28 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatekw.py Fri May 31 09:25:51 2019 -0700 +++ b/mercurial/templatekw.py Thu Apr 18 13:35:02 2019 -0700 @@ -290,11 +290,6 @@ 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_copies', requires={'repo', 'ctx', 'cache', 'revcache'}) def showfilecopies(context, mapping): @@ -332,17 +327,23 @@ @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.filesadded()) @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.filesremoved()) @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.filesmodified()) @templatekeyword('files', requires={'ctx'}) def showfiles(context, mapping):
--- a/relnotes/next Fri May 31 09:25:51 2019 -0700 +++ b/relnotes/next Thu Apr 18 13:35:02 2019 -0700 @@ -15,6 +15,10 @@ == Bug Fixes == + * issue4292: "hg log and {files} {file_adds} {file_mods} {file_dels} + in template show wrong files on merged revision". See details in + "Backwards Compatibility Changes". + == Backwards Compatibility Changes == @@ -31,6 +35,16 @@ previously replace files *in* the configured directory by subdirectories. +* Template keyword `{file_mods}`, `{file_adds}`, and `{file_dels}` + have changed behavior on merge commits. They used to be relative to + the first parent, but they now consider both parents. `{file_adds}` + shows files that exists in the commit but did not exist in either + parent. `{file_dels}` shows files that do not exist in the commit + but existed in either parent. `{file_mods}` show the remaining + files from `{files}` that were not in the other two + sets. + + == Internal API Changes == * Matchers are no longer iterable. Use `match.files()` instead.
--- a/tests/test-convert-bzr-merges.t Fri May 31 09:25:51 2019 -0700 +++ b/tests/test-convert-bzr-merges.t Thu Apr 18 13:35:02 2019 -0700 @@ -59,7 +59,7 @@ $ glog -R source-hg o 5@source "(octopus merge fixup)" files+: [], files-: [], files: [renamed] |\ - | o 4@source "Merged branches" files+: [file-branch1 file-branch2 renamed], files-: [rename_me], files: [file] + | o 4@source "Merged branches" files+: [file-branch2 renamed], files-: [rename_me], files: [] | |\ o---+ 3@source-branch2 "Added brach2 file" files+: [file-branch2 renamed], files-: [rename_me], files: [] / / @@ -154,7 +154,7 @@ $ glog -R hg2hg @ 5@source "(octopus merge fixup)" files+: [], files-: [], files: [] |\ - | o 4@source "Merged branches" files+: [file-branch1 file-branch2 renamed], files-: [rename_me], files: [file] + | o 4@source "Merged branches" files+: [file-branch2 renamed], files-: [rename_me], files: [] | |\ o---+ 3@source-branch2 "Added brach2 file" files+: [file-branch2 renamed], files-: [rename_me], files: [] / /
--- a/tests/test-convert-bzr.t Fri May 31 09:25:51 2019 -0700 +++ b/tests/test-convert-bzr.t Thu Apr 18 13:35:02 2019 -0700 @@ -147,7 +147,7 @@ 1 Editing b 0 Merged improve branch $ glog -R source-hg - o 3@source "Merged improve branch" files+: [], files-: [], files: [b] + o 3@source "Merged improve branch" files+: [], files-: [], files: [] |\ | o 2@source-improve "Editing b" files+: [], files-: [], files: [b] | |
--- a/tests/test-template-keywords.t Fri May 31 09:25:51 2019 -0700 +++ b/tests/test-template-keywords.t Thu Apr 18 13:35:02 2019 -0700 @@ -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