Mercurial > hg
changeset 10061:9e2ab10728a2
Make {file_copies} usable as a --template key
Before this, to display file copies in templates, you had to write something
like {file_copies%filecopy}. For some reason, the {file_copy} subtemplate was
used by default but not defined by default in changeset_templater, while styles
were already using it. Here we define {file_copy} in changeset_templater, and
change the templater to handle formatting strings like {file_copies%filecopy}
with already expanded keys (in this case {file_copies}), for backward
compatibility.
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 13 Dec 2009 18:06:24 +0100 |
parents | f780b1098efc |
children | c204431b039e |
files | mercurial/cmdutil.py mercurial/help/templates.txt mercurial/templater.py tests/test-command-template tests/test-command-template.out tests/test-git-import tests/test-log tests/test-log.out tests/test-mq |
diffstat | 9 files changed, 87 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sun Dec 13 18:06:24 2009 +0100 +++ b/mercurial/cmdutil.py Sun Dec 13 18:06:24 2009 +0100 @@ -757,12 +757,16 @@ def __init__(self, ui, repo, patch, diffopts, mapfile, buffered): changeset_printer.__init__(self, ui, repo, patch, diffopts, buffered) formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) + defaulttempl = { + 'parent': '{rev}:{node|formatnode} ', + 'manifest': '{rev}:{node|formatnode}', + 'file_copy': '{name} ({source})', + 'extra': '{key}={value|stringescape}' + } + # filecopy is preserved for compatibility reasons + defaulttempl['filecopy'] = defaulttempl['file_copy'] self.t = templater.templater(mapfile, {'formatnode': formatnode}, - cache={ - 'parent': '{rev}:{node|formatnode} ', - 'manifest': '{rev}:{node|formatnode}', - 'filecopy': '{name} ({source})', - 'extra': '{key}={value|stringescape}'}) + cache=defaulttempl) self.cache = {} def use_template(self, t):
--- a/mercurial/help/templates.txt Sun Dec 13 18:06:24 2009 +0100 +++ b/mercurial/help/templates.txt Sun Dec 13 18:06:24 2009 +0100 @@ -34,6 +34,10 @@ :files: List of strings. All files modified, added, or removed by this changeset. :file_adds: List of strings. Files added by this changeset. +:file_copies: List of strings. Files copied in this changeset with + their sources. +:file_copies_switch: List of strings. Like "file_copies" but displayed + only if the --copied switch is set. :file_mods: List of strings. Files modified by this changeset. :file_dels: List of strings. Files removed by this changeset. :node: String. The changeset identification hash, as a
--- a/mercurial/templater.py Sun Dec 13 18:06:24 2009 +0100 +++ b/mercurial/templater.py Sun Dec 13 18:06:24 2009 +0100 @@ -77,8 +77,14 @@ raise SyntaxError(_("error expanding '%s%%%s'") % (key, format)) lm = map.copy() for i in v: - lm.update(i) - yield self.process(format, lm) + if isinstance(i, dict): + lm.update(i) + yield self.process(format, lm) + else: + # v is not an iterable of dicts, this happen when 'key' + # has been fully expanded already and format is useless. + # If so, return the expanded value. + yield i def _filter(self, expr, get, map): if expr not in self.cache:
--- a/tests/test-command-template Sun Dec 13 18:06:24 2009 +0100 +++ b/tests/test-command-template Sun Dec 13 18:06:24 2009 +0100 @@ -94,7 +94,7 @@ echo "# keys work" for key in author branches date desc file_adds file_dels file_mods \ - 'file_copies%filecopy' 'file_copies_switch%filecopy' files \ + file_copies file_copies_switch files \ manifest node parents rev tags diffstat extras; do for mode in '' --verbose --debug; do hg log $mode --template "$key$mode: {$key}\n"
--- a/tests/test-command-template.out Sun Dec 13 18:06:24 2009 +0100 +++ b/tests/test-command-template.out Sun Dec 13 18:06:24 2009 +0100 @@ -380,60 +380,60 @@ file_mods--debug: file_mods--debug: file_mods--debug: -file_copies%filecopy: fourth (second) -file_copies%filecopy: -file_copies%filecopy: -file_copies%filecopy: -file_copies%filecopy: -file_copies%filecopy: -file_copies%filecopy: -file_copies%filecopy: -file_copies%filecopy: -file_copies%filecopy--verbose: fourth (second) -file_copies%filecopy--verbose: -file_copies%filecopy--verbose: -file_copies%filecopy--verbose: -file_copies%filecopy--verbose: -file_copies%filecopy--verbose: -file_copies%filecopy--verbose: -file_copies%filecopy--verbose: -file_copies%filecopy--verbose: -file_copies%filecopy--debug: fourth (second) -file_copies%filecopy--debug: -file_copies%filecopy--debug: -file_copies%filecopy--debug: -file_copies%filecopy--debug: -file_copies%filecopy--debug: -file_copies%filecopy--debug: -file_copies%filecopy--debug: -file_copies%filecopy--debug: -file_copies_switch%filecopy: -file_copies_switch%filecopy: -file_copies_switch%filecopy: -file_copies_switch%filecopy: -file_copies_switch%filecopy: -file_copies_switch%filecopy: -file_copies_switch%filecopy: -file_copies_switch%filecopy: -file_copies_switch%filecopy: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--verbose: -file_copies_switch%filecopy--debug: -file_copies_switch%filecopy--debug: -file_copies_switch%filecopy--debug: -file_copies_switch%filecopy--debug: -file_copies_switch%filecopy--debug: -file_copies_switch%filecopy--debug: -file_copies_switch%filecopy--debug: -file_copies_switch%filecopy--debug: -file_copies_switch%filecopy--debug: +file_copies: fourth (second) +file_copies: +file_copies: +file_copies: +file_copies: +file_copies: +file_copies: +file_copies: +file_copies: +file_copies--verbose: fourth (second) +file_copies--verbose: +file_copies--verbose: +file_copies--verbose: +file_copies--verbose: +file_copies--verbose: +file_copies--verbose: +file_copies--verbose: +file_copies--verbose: +file_copies--debug: fourth (second) +file_copies--debug: +file_copies--debug: +file_copies--debug: +file_copies--debug: +file_copies--debug: +file_copies--debug: +file_copies--debug: +file_copies--debug: +file_copies_switch: +file_copies_switch: +file_copies_switch: +file_copies_switch: +file_copies_switch: +file_copies_switch: +file_copies_switch: +file_copies_switch: +file_copies_switch: +file_copies_switch--verbose: +file_copies_switch--verbose: +file_copies_switch--verbose: +file_copies_switch--verbose: +file_copies_switch--verbose: +file_copies_switch--verbose: +file_copies_switch--verbose: +file_copies_switch--verbose: +file_copies_switch--verbose: +file_copies_switch--debug: +file_copies_switch--debug: +file_copies_switch--debug: +file_copies_switch--debug: +file_copies_switch--debug: +file_copies_switch--debug: +file_copies_switch--debug: +file_copies_switch--debug: +file_copies_switch--debug: files: fourth second third files: second files:
--- a/tests/test-git-import Sun Dec 13 18:06:24 2009 +0100 +++ b/tests/test-git-import Sun Dec 13 18:06:24 2009 +0100 @@ -141,7 +141,7 @@ rename from rename2 rename to rename3-2 EOF -hg log -vr. --template '{rev} {files} / {file_copies%filecopy}\n' +hg log -vr. --template '{rev} {files} / {file_copies}\n' hg locate rename2 rename3 rename3-2 hg cat rename3
--- a/tests/test-log Sun Dec 13 18:06:24 2009 +0100 +++ b/tests/test-log Sun Dec 13 18:06:24 2009 +0100 @@ -32,23 +32,23 @@ hg log -vf e echo '% log copies with --copies' -hg log -vC --template '{rev} {file_copies%filecopy}\n' -echo '% log copies switch without --copies' +hg log -vC --template '{rev} {file_copies}\n' +echo '% log copies switch without --copies, with old filecopy template' hg log -v --template '{rev} {file_copies_switch%filecopy}\n' echo '% log copies switch with --copies' -hg log -vC --template '{rev} {file_copies_switch%filecopy}\n' +hg log -vC --template '{rev} {file_copies_switch}\n' echo % log copies, non-linear manifest hg up -C 3 hg mv dir/b e echo foo > foo hg ci -Ame2 -d '6 0' -hg log -v --template '{rev} {file_copies%filecopy}\n' -r 5 +hg log -v --template '{rev} {file_copies}\n' -r 5 echo % log copies, execute bit set chmod +x e hg ci -me3 -d '7 0' -hg log -v --template '{rev} {file_copies%filecopy}\n' -r 6 +hg log -v --template '{rev} {file_copies}\n' -r 6 echo '% log -p d' hg log -pv d
--- a/tests/test-log.out Sun Dec 13 18:06:24 2009 +0100 +++ b/tests/test-log.out Sun Dec 13 18:06:24 2009 +0100 @@ -82,7 +82,7 @@ 2 dir/b (b) 1 b (a) 0 -% log copies switch without --copies +% log copies switch without --copies, with old filecopy template 4 3 2
--- a/tests/test-mq Sun Dec 13 18:06:24 2009 +0100 +++ b/tests/test-mq Sun Dec 13 18:06:24 2009 +0100 @@ -387,10 +387,10 @@ hg up -C 1 hg qrefresh --git 2>&1 | grep -v 'saving bundle' cat .hg/patches/bar -hg log -v --template '{rev} {file_copies%filecopy}\n' -r . +hg log -v --template '{rev} {file_copies}\n' -r . hg qrefresh --git cat .hg/patches/bar -hg log -v --template '{rev} {file_copies%filecopy}\n' -r . +hg log -v --template '{rev} {file_copies}\n' -r . hg qrefresh grep 'diff --git' .hg/patches/bar @@ -403,12 +403,12 @@ hg mv baz bleh hg qrefresh --git 2>&1 | grep -v 'saving bundle' cat .hg/patches/bar -hg log -v --template '{rev} {file_copies%filecopy}\n' -r . +hg log -v --template '{rev} {file_copies}\n' -r . hg mv quux fred hg mv bleh barney hg qrefresh --git cat .hg/patches/bar -hg log -v --template '{rev} {file_copies%filecopy}\n' -r . +hg log -v --template '{rev} {file_copies}\n' -r . echo % refresh omitting an added file hg qnew baz