Mercurial > hg
changeset 39368:5b1d406b39f1
templatekw: alias {name} of file copies dict to {path}
For the same reason as the previous patch. We might want some hack to
support {source.path}, {source.rev}, etc., but that's a different issue.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 05 Aug 2018 16:27:09 +0900 |
parents | 83f8f7b9fa60 |
children | 34ba47117164 |
files | mercurial/templatekw.py mercurial/templateutil.py tests/test-template-keywords.t |
diffstat | 3 files changed, 37 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatekw.py Sun Aug 05 16:14:18 2018 +0900 +++ b/mercurial/templatekw.py Sun Aug 05 16:27:09 2018 +0900 @@ -323,11 +323,8 @@ rename = getrenamed(fn, ctx.rev()) if rename: copies.append((fn, rename)) - - copies = util.sortdict(copies) - return compatdict(context, mapping, 'file_copy', copies, - key='name', value='source', fmt='%s (%s)', - plural='file_copies') + return templateutil.compatfilecopiesdict(context, mapping, 'file_copy', + copies) # showfilecopiesswitch() displays file copies only if copy records are # provided before calling the templater, usually with a --copies @@ -338,10 +335,8 @@ only if the --copied switch is set. """ copies = context.resource(mapping, 'revcache').get('copies') or [] - copies = util.sortdict(copies) - return compatdict(context, mapping, 'file_copy', copies, - key='name', value='source', fmt='%s (%s)', - plural='file_copies') + return templateutil.compatfilecopiesdict(context, mapping, 'file_copy', + copies) @templatekeyword('file_dels', requires={'ctx', 'revcache'}) def showfiledels(context, mapping):
--- a/mercurial/templateutil.py Sun Aug 05 16:14:18 2018 +0900 +++ b/mercurial/templateutil.py Sun Aug 05 16:27:09 2018 +0900 @@ -570,6 +570,21 @@ f = _showcompatlist(context, mapping, name, data, plural, separator) return hybridlist(data, name=element or name, fmt=fmt, gen=f) +def compatfilecopiesdict(context, mapping, name, copies): + """Wrap list of (dest, source) file names to support old-style list + template and field names + + This exists for backward compatibility. Use hybriddict for new template + keywords. + """ + # no need to provide {path} to old-style list template + c = [{'name': k, 'source': v} for k, v in copies] + f = _showcompatlist(context, mapping, name, c, plural='file_copies') + copies = util.sortdict(copies) + return hybrid(f, copies, + lambda k: {'name': k, 'path': k, 'source': copies[k]}, + lambda k: '%s (%s)' % (k, copies[k])) + def compatfileslist(context, mapping, name, files): """Wrap list of file names to support old-style list template and field names
--- a/tests/test-template-keywords.t Sun Aug 05 16:14:18 2018 +0900 +++ b/tests/test-template-keywords.t Sun Aug 05 16:27:09 2018 +0900 @@ -769,6 +769,24 @@ fourth third +Test file copies dict: + + $ hg log -r8 -T '{join(file_copies, " ")}\n' + fourth (second) + $ hg log -r8 -T '{file_copies % "{name} <- {source}\n"}' + fourth <- second + $ hg log -r8 -T '{file_copies % "{path} <- {source}\n"}' + fourth <- second + + $ hg log -r8 -T '{join(file_copies_switch, " ")}\n' + + $ hg log -r8 -C -T '{join(file_copies_switch, " ")}\n' + fourth (second) + $ hg log -r8 -C -T '{file_copies_switch % "{name} <- {source}\n"}' + fourth <- second + $ hg log -r8 -C -T '{file_copies_switch % "{path} <- {source}\n"}' + fourth <- second + Test index keyword: $ hg log -l 2 -T '{index + 10}{files % " {index}:{file}"}\n'