# HG changeset patch # User Martin von Zweigbergk # Date 2019-04-18 20:35:02 # Node ID 0c72eddb4be5f07a57dce98ea2b6c107017a71ed # Parent 0c0a22f5b0b5d40301009181142ed88c92c15b61 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 diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -290,11 +290,6 @@ def _getfilestatusmap(context, mapping, 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 @@ def showfilecopiesswitch(context, mappin @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): diff --git a/relnotes/next b/relnotes/next --- a/relnotes/next +++ b/relnotes/next @@ -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. diff --git a/tests/test-convert-bzr-merges.t b/tests/test-convert-bzr-merges.t --- a/tests/test-convert-bzr-merges.t +++ b/tests/test-convert-bzr-merges.t @@ -59,7 +59,7 @@ move should be recorded in the fixup mer $ 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 @@ there. It's not recorded as a move in r $ 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: [] / / diff --git a/tests/test-convert-bzr.t b/tests/test-convert-bzr.t --- a/tests/test-convert-bzr.t +++ b/tests/test-convert-bzr.t @@ -147,7 +147,7 @@ merge 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] | | 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 @@ Test files lists on merge commit: $ 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