##// END OF EJS Templates
templatekw: alias {file} of files list to {path}...
Yuya Nishihara -
r39403:83f8f7b9 default
parent child Browse files
Show More
@@ -140,7 +140,7 def files(context, mapping, args):
140 ctx = context.resource(mapping, 'ctx')
140 ctx = context.resource(mapping, 'ctx')
141 m = ctx.match([raw])
141 m = ctx.match([raw])
142 files = list(ctx.matches(m))
142 files = list(ctx.matches(m))
143 return templateutil.compatlist(context, mapping, "file", files)
143 return templateutil.compatfileslist(context, mapping, "file", files)
144
144
145 @templatefunc('fill(text[, width[, initialident[, hangindent]]])')
145 @templatefunc('fill(text[, width[, initialident[, hangindent]]])')
146 def fill(context, mapping, args):
146 def fill(context, mapping, args):
@@ -297,7 +297,7 def _showfilesbystat(context, mapping, n
297 if 'files' not in revcache:
297 if 'files' not in revcache:
298 revcache['files'] = ctx.p1().status(ctx)[:3]
298 revcache['files'] = ctx.p1().status(ctx)[:3]
299 files = revcache['files'][index]
299 files = revcache['files'][index]
300 return compatlist(context, mapping, name, files, element='file')
300 return templateutil.compatfileslist(context, mapping, name, files)
301
301
302 @templatekeyword('file_adds', requires={'ctx', 'revcache'})
302 @templatekeyword('file_adds', requires={'ctx', 'revcache'})
303 def showfileadds(context, mapping):
303 def showfileadds(context, mapping):
@@ -359,7 +359,7 def showfiles(context, mapping):
359 changeset.
359 changeset.
360 """
360 """
361 ctx = context.resource(mapping, 'ctx')
361 ctx = context.resource(mapping, 'ctx')
362 return compatlist(context, mapping, 'file', ctx.files())
362 return templateutil.compatfileslist(context, mapping, 'file', ctx.files())
363
363
364 @templatekeyword('graphnode', requires={'repo', 'ctx'})
364 @templatekeyword('graphnode', requires={'repo', 'ctx'})
365 def showgraphnode(context, mapping):
365 def showgraphnode(context, mapping):
@@ -570,6 +570,17 def compatlist(context, mapping, name, d
570 f = _showcompatlist(context, mapping, name, data, plural, separator)
570 f = _showcompatlist(context, mapping, name, data, plural, separator)
571 return hybridlist(data, name=element or name, fmt=fmt, gen=f)
571 return hybridlist(data, name=element or name, fmt=fmt, gen=f)
572
572
573 def compatfileslist(context, mapping, name, files):
574 """Wrap list of file names to support old-style list template and field
575 names
576
577 This exists for backward compatibility. Use hybridlist for new template
578 keywords.
579 """
580 f = _showcompatlist(context, mapping, name, files)
581 return hybrid(f, files, lambda x: {'file': x, 'path': x},
582 pycompat.identity)
583
573 def _showcompatlist(context, mapping, name, values, plural=None, separator=' '):
584 def _showcompatlist(context, mapping, name, values, plural=None, separator=' '):
574 """Return a generator that renders old-style list template
585 """Return a generator that renders old-style list template
575
586
@@ -1198,6 +1198,12 Test files function
1198
1198
1199 0
1199 0
1200
1200
1201
1202 $ hg log -l1 -T "{files('aa') % '{file}\n'}"
1203 aa
1204 $ hg log -l1 -T "{files('aa') % '{path}\n'}"
1205 aa
1206
1201 $ hg rm a
1207 $ hg rm a
1202 $ hg log -r "wdir()" -T "{rev}\n{join(files('*'), '\n')}\n"
1208 $ hg log -r "wdir()" -T "{rev}\n{join(files('*'), '\n')}\n"
1203 2147483647
1209 2147483647
@@ -745,6 +745,30 Add a commit that does all possible modi
745 $ hg rm a
745 $ hg rm a
746 $ hg ci -m "Modify, add, remove, rename"
746 $ hg ci -m "Modify, add, remove, rename"
747
747
748 Test files list:
749
750 $ hg log -l1 -T '{join(file_mods, " ")}\n'
751 third
752 $ hg log -l1 -T '{file_mods % "{file}\n"}'
753 third
754 $ hg log -l1 -T '{file_mods % "{path}\n"}'
755 third
756
757 $ hg log -l1 -T '{join(files, " ")}\n'
758 a b fifth fourth third
759 $ hg log -l1 -T '{files % "{file}\n"}'
760 a
761 b
762 fifth
763 fourth
764 third
765 $ hg log -l1 -T '{files % "{path}\n"}'
766 a
767 b
768 fifth
769 fourth
770 third
771
748 Test index keyword:
772 Test index keyword:
749
773
750 $ hg log -l 2 -T '{index + 10}{files % " {index}:{file}"}\n'
774 $ hg log -l 2 -T '{index + 10}{files % " {index}:{file}"}\n'
General Comments 0
You need to be logged in to leave comments. Login now