Show More
@@ -37,12 +37,13 class _hybrid(object): | |||
|
37 | 37 | - "{files|json}" |
|
38 | 38 | """ |
|
39 | 39 | |
|
40 | def __init__(self, gen, values, makemap, joinfmt): | |
|
40 | def __init__(self, gen, values, makemap, joinfmt, keytype=None): | |
|
41 | 41 | if gen is not None: |
|
42 | 42 | self.gen = gen # generator or function returning generator |
|
43 | 43 | self._values = values |
|
44 | 44 | self._makemap = makemap |
|
45 | 45 | self.joinfmt = joinfmt |
|
46 | self.keytype = keytype # hint for 'x in y' where type(x) is unresolved | |
|
46 | 47 | def gen(self): |
|
47 | 48 | """Default generator to stringify this as {join(self, ' ')}""" |
|
48 | 49 | for i, x in enumerate(self._values): |
@@ -788,15 +789,14 def showparents(**args): | |||
|
788 | 789 | repo = args['repo'] |
|
789 | 790 | ctx = args['ctx'] |
|
790 | 791 | pctxs = scmutil.meaningfulparents(repo, ctx) |
|
791 | # ifcontains() needs a list of str | |
|
792 | prevs = ["%d" % p.rev() for p in pctxs] | |
|
792 | prevs = [p.rev() for p in pctxs] | |
|
793 | 793 | parents = [[('rev', p.rev()), |
|
794 | 794 | ('node', p.hex()), |
|
795 | 795 | ('phase', p.phasestr())] |
|
796 | 796 | for p in pctxs] |
|
797 | 797 | f = _showlist('parent', parents, args) |
|
798 |
return _hybrid(f, prevs, lambda x: {'ctx': repo[ |
|
|
799 |
lambda x: scmutil.formatchangeid(repo[ |
|
|
798 | return _hybrid(f, prevs, lambda x: {'ctx': repo[x], 'revcache': {}}, | |
|
799 | lambda x: scmutil.formatchangeid(repo[x]), keytype=int) | |
|
800 | 800 | |
|
801 | 801 | @templatekeyword('phase') |
|
802 | 802 | def showphase(repo, ctx, templ, **args): |
@@ -818,12 +818,10 def showrevslist(name, revs, **args): | |||
|
818 | 818 | be evaluated""" |
|
819 | 819 | args = pycompat.byteskwargs(args) |
|
820 | 820 | repo = args['ctx'].repo() |
|
821 | # ifcontains() needs a list of str | |
|
822 | revs = ["%d" % r for r in revs] | |
|
823 | f = _showlist(name, revs, args) | |
|
821 | f = _showlist(name, ['%d' % r for r in revs], args) | |
|
824 | 822 | return _hybrid(f, revs, |
|
825 |
lambda x: {name: x, 'ctx': repo[ |
|
|
826 | pycompat.identity) | |
|
823 | lambda x: {name: x, 'ctx': repo[x], 'revcache': {}}, | |
|
824 | pycompat.identity, keytype=int) | |
|
827 | 825 | |
|
828 | 826 | @templatekeyword('subrepos') |
|
829 | 827 | def showsubrepos(**args): |
@@ -333,12 +333,12 def evalboolean(context, mapping, arg): | |||
|
333 | 333 | # empty dict/list should be False as they are expected to be '' |
|
334 | 334 | return bool(stringify(thing)) |
|
335 | 335 | |
|
336 | def evalinteger(context, mapping, arg, err): | |
|
336 | def evalinteger(context, mapping, arg, err=None): | |
|
337 | 337 | v = evalfuncarg(context, mapping, arg) |
|
338 | 338 | try: |
|
339 | 339 | return int(v) |
|
340 | 340 | except (TypeError, ValueError): |
|
341 | raise error.ParseError(err) | |
|
341 | raise error.ParseError(err or _('not an integer')) | |
|
342 | 342 | |
|
343 | 343 | def evalstring(context, mapping, arg): |
|
344 | 344 | return stringify(evalrawexp(context, mapping, arg)) |
@@ -353,6 +353,20 def evalstringliteral(context, mapping, | |||
|
353 | 353 | thing = func(context, mapping, data) |
|
354 | 354 | return stringify(thing) |
|
355 | 355 | |
|
356 | _evalfuncbytype = { | |
|
357 | bool: evalboolean, | |
|
358 | bytes: evalstring, | |
|
359 | int: evalinteger, | |
|
360 | } | |
|
361 | ||
|
362 | def evalastype(context, mapping, arg, typ): | |
|
363 | """Evaluate given argument and coerce its type""" | |
|
364 | try: | |
|
365 | f = _evalfuncbytype[typ] | |
|
366 | except KeyError: | |
|
367 | raise error.ProgrammingError('invalid type specified: %r' % typ) | |
|
368 | return f(context, mapping, arg) | |
|
369 | ||
|
356 | 370 | def runinteger(context, mapping, data): |
|
357 | 371 | return int(data) |
|
358 | 372 | |
@@ -782,8 +796,9 def ifcontains(context, mapping, args): | |||
|
782 | 796 | # i18n: "ifcontains" is a keyword |
|
783 | 797 | raise error.ParseError(_("ifcontains expects three or four arguments")) |
|
784 | 798 | |
|
785 | needle = evalstring(context, mapping, args[0]) | |
|
786 | 799 | haystack = evalfuncarg(context, mapping, args[1]) |
|
800 | needle = evalastype(context, mapping, args[0], | |
|
801 | getattr(haystack, 'keytype', None) or bytes) | |
|
787 | 802 | |
|
788 | 803 | if needle in haystack: |
|
789 | 804 | yield evalrawexp(context, mapping, args[2]) |
@@ -3147,6 +3147,13 Test manifest/get() can be join()-ed as | |||
|
3147 | 3147 | $ hg log -R latesttag -r tip -T '{join(get(extras, "branch"), "")}\n' |
|
3148 | 3148 | default |
|
3149 | 3149 | |
|
3150 | Test min/max of integers | |
|
3151 | ||
|
3152 | $ hg log -R latesttag -l1 -T '{min(revset("9:10"))}\n' | |
|
3153 | 9 | |
|
3154 | $ hg log -R latesttag -l1 -T '{max(revset("9:10"))}\n' | |
|
3155 | 10 | |
|
3156 | ||
|
3150 | 3157 | Test dot operator precedence: |
|
3151 | 3158 | |
|
3152 | 3159 | $ hg debugtemplate -R latesttag -r0 -v '{manifest.node|short}\n' |
General Comments 0
You need to be logged in to leave comments.
Login now