# HG changeset patch # User Yuya Nishihara # Date 2018-08-05 07:27:09 # Node ID 5b1d406b39f15a3c3fe1718c8201300043a617e1 # Parent 83f8f7b9fa60064a83fcbecff80da5c8393a6639 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. diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -323,11 +323,8 @@ def showfilecopies(context, mapping): 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 @@ def showfilecopiesswitch(context, mappin 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): diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py --- a/mercurial/templateutil.py +++ b/mercurial/templateutil.py @@ -570,6 +570,21 @@ def compatlist(context, mapping, name, d 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 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 @@ -769,6 +769,24 @@ Test files list: 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'