##// END OF EJS Templates
templatekw: just pass underlying value (or key) to joinfmt() function...
Yuya Nishihara -
r34329:dd28b1f5 default
parent child Browse files
Show More
@@ -48,10 +48,10 b' class _hybrid(object):'
48 return self._defaultgen()
48 return self._defaultgen()
49 def _defaultgen(self):
49 def _defaultgen(self):
50 """Generator to stringify this as {join(self, ' ')}"""
50 """Generator to stringify this as {join(self, ' ')}"""
51 for i, d in enumerate(self.itermaps()):
51 for i, x in enumerate(self._values):
52 if i > 0:
52 if i > 0:
53 yield ' '
53 yield ' '
54 yield self.joinfmt(d)
54 yield self.joinfmt(x)
55 def itermaps(self):
55 def itermaps(self):
56 makemap = self._makemap
56 makemap = self._makemap
57 for x in self._values:
57 for x in self._values:
@@ -73,11 +73,11 b' class _hybrid(object):'
73 def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None):
73 def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None):
74 """Wrap data to support both dict-like and string-like operations"""
74 """Wrap data to support both dict-like and string-like operations"""
75 return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
75 return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
76 lambda d: fmt % (d[key], d[value]))
76 lambda k: fmt % (k, data[k]))
77
77
78 def hybridlist(data, name, fmt='%s', gen=None):
78 def hybridlist(data, name, fmt='%s', gen=None):
79 """Wrap data to support both list-like and string-like operations"""
79 """Wrap data to support both list-like and string-like operations"""
80 return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name])
80 return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % x)
81
81
82 def unwraphybrid(thing):
82 def unwraphybrid(thing):
83 """Return an object which can be stringified possibly by using a legacy
83 """Return an object which can be stringified possibly by using a legacy
@@ -315,7 +315,7 b' def showbookmarks(**args):'
315 active = repo._activebookmark
315 active = repo._activebookmark
316 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
316 makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
317 f = _showlist('bookmark', bookmarks, args)
317 f = _showlist('bookmark', bookmarks, args)
318 return _hybrid(f, bookmarks, makemap, lambda x: x['bookmark'])
318 return _hybrid(f, bookmarks, makemap, pycompat.identity)
319
319
320 @templatekeyword('children')
320 @templatekeyword('children')
321 def showchildren(**args):
321 def showchildren(**args):
@@ -384,7 +384,7 b' def showextras(**args):'
384 c = [makemap(k) for k in extras]
384 c = [makemap(k) for k in extras]
385 f = _showlist('extra', c, args, plural='extras')
385 f = _showlist('extra', c, args, plural='extras')
386 return _hybrid(f, extras, makemap,
386 return _hybrid(f, extras, makemap,
387 lambda x: '%s=%s' % (x['key'], util.escapestr(x['value'])))
387 lambda k: '%s=%s' % (k, util.escapestr(extras[k])))
388
388
389 @templatekeyword('file_adds')
389 @templatekeyword('file_adds')
390 def showfileadds(**args):
390 def showfileadds(**args):
@@ -510,7 +510,7 b' def showlatesttags(pattern, **args):'
510
510
511 tags = latesttags[2]
511 tags = latesttags[2]
512 f = _showlist('latesttag', tags, args, separator=':')
512 f = _showlist('latesttag', tags, args, separator=':')
513 return _hybrid(f, tags, makemap, lambda x: x['latesttag'])
513 return _hybrid(f, tags, makemap, pycompat.identity)
514
514
515 @templatekeyword('latesttagdistance')
515 @templatekeyword('latesttagdistance')
516 def showlatesttagdistance(repo, ctx, templ, cache, **args):
516 def showlatesttagdistance(repo, ctx, templ, cache, **args):
@@ -584,7 +584,7 b' def shownamespaces(**args):'
584 'colorname': colornames[ns],
584 'colorname': colornames[ns],
585 }
585 }
586
586
587 return _hybrid(f, namespaces, makemap, lambda x: x['namespace'])
587 return _hybrid(f, namespaces, makemap, pycompat.identity)
588
588
589 @templatekeyword('node')
589 @templatekeyword('node')
590 def shownode(repo, ctx, templ, **args):
590 def shownode(repo, ctx, templ, **args):
@@ -618,7 +618,7 b' def showpeerpaths(repo, **args):'
618 # no hybriddict() since d['path'] can't be formatted as a string. perhaps
618 # no hybriddict() since d['path'] can't be formatted as a string. perhaps
619 # hybriddict() should call templatefilters.stringify(d[value]).
619 # hybriddict() should call templatefilters.stringify(d[value]).
620 return _hybrid(None, paths, lambda k: {'name': k, 'path': paths[k]},
620 return _hybrid(None, paths, lambda k: {'name': k, 'path': paths[k]},
621 lambda d: '%s=%s' % (d['name'], d['path']['url']))
621 lambda k: '%s=%s' % (k, paths[k]['url']))
622
622
623 @templatekeyword("predecessors")
623 @templatekeyword("predecessors")
624 def showpredecessors(repo, ctx, **args):
624 def showpredecessors(repo, ctx, **args):
@@ -629,7 +629,7 b' def showpredecessors(repo, ctx, **args):'
629
629
630 return _hybrid(None, predecessors,
630 return _hybrid(None, predecessors,
631 lambda x: {'ctx': repo[x], 'revcache': {}},
631 lambda x: {'ctx': repo[x], 'revcache': {}},
632 lambda d: scmutil.formatchangeid(d['ctx']))
632 lambda x: scmutil.formatchangeid(repo[x]))
633
633
634 @templatekeyword("successorssets")
634 @templatekeyword("successorssets")
635 def showsuccessorssets(repo, ctx, **args):
635 def showsuccessorssets(repo, ctx, **args):
@@ -647,7 +647,7 b' def showsuccessorssets(repo, ctx, **args'
647 data = []
647 data = []
648 for ss in ssets:
648 for ss in ssets:
649 h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}},
649 h = _hybrid(None, ss, lambda x: {'ctx': repo[x], 'revcache': {}},
650 lambda d: scmutil.formatchangeid(d['ctx']))
650 lambda x: scmutil.formatchangeid(repo[x]))
651 data.append(h)
651 data.append(h)
652
652
653 # Format the successorssets
653 # Format the successorssets
@@ -661,7 +661,7 b' def showsuccessorssets(repo, ctx, **args'
661 yield "; ".join(render(d) for d in data)
661 yield "; ".join(render(d) for d in data)
662
662
663 return _hybrid(gen(data), data, lambda x: {'successorset': x},
663 return _hybrid(gen(data), data, lambda x: {'successorset': x},
664 lambda d: d["successorset"])
664 pycompat.identity)
665
665
666 @templatekeyword("succsandmarkers")
666 @templatekeyword("succsandmarkers")
667 def showsuccsandmarkers(repo, ctx, **args):
667 def showsuccsandmarkers(repo, ctx, **args):
@@ -687,7 +687,7 b' def showsuccsandmarkers(repo, ctx, **arg'
687 successors = [hex(n) for n in successors]
687 successors = [hex(n) for n in successors]
688 successors = _hybrid(None, successors,
688 successors = _hybrid(None, successors,
689 lambda x: {'ctx': repo[x], 'revcache': {}},
689 lambda x: {'ctx': repo[x], 'revcache': {}},
690 lambda d: scmutil.formatchangeid(d['ctx']))
690 lambda x: scmutil.formatchangeid(repo[x]))
691
691
692 # Format markers
692 # Format markers
693 finalmarkers = []
693 finalmarkers = []
@@ -703,7 +703,7 b' def showsuccsandmarkers(repo, ctx, **arg'
703 data.append({'successors': successors, 'markers': finalmarkers})
703 data.append({'successors': successors, 'markers': finalmarkers})
704
704
705 f = _showlist('succsandmarkers', data, args)
705 f = _showlist('succsandmarkers', data, args)
706 return _hybrid(f, data, lambda x: x, lambda d: d)
706 return _hybrid(f, data, lambda x: x, pycompat.identity)
707
707
708 @templatekeyword('p1rev')
708 @templatekeyword('p1rev')
709 def showp1rev(repo, ctx, templ, **args):
709 def showp1rev(repo, ctx, templ, **args):
@@ -748,7 +748,7 b' def showparents(**args):'
748 for p in pctxs]
748 for p in pctxs]
749 f = _showlist('parent', parents, args)
749 f = _showlist('parent', parents, args)
750 return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}},
750 return _hybrid(f, prevs, lambda x: {'ctx': repo[int(x)], 'revcache': {}},
751 lambda d: scmutil.formatchangeid(d['ctx']))
751 lambda x: scmutil.formatchangeid(repo[int(x)]))
752
752
753 @templatekeyword('phase')
753 @templatekeyword('phase')
754 def showphase(repo, ctx, templ, **args):
754 def showphase(repo, ctx, templ, **args):
@@ -775,7 +775,7 b' def showrevslist(name, revs, **args):'
775 f = _showlist(name, revs, args)
775 f = _showlist(name, revs, args)
776 return _hybrid(f, revs,
776 return _hybrid(f, revs,
777 lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}},
777 lambda x: {name: x, 'ctx': repo[int(x)], 'revcache': {}},
778 lambda d: d[name])
778 pycompat.identity)
779
779
780 @templatekeyword('subrepos')
780 @templatekeyword('subrepos')
781 def showsubrepos(**args):
781 def showsubrepos(**args):
@@ -768,10 +768,7 b' def join(context, mapping, args):'
768 # TODO: perhaps this should be evalfuncarg(), but it can't because hgweb
768 # TODO: perhaps this should be evalfuncarg(), but it can't because hgweb
769 # abuses generator as a keyword that returns a list of dicts.
769 # abuses generator as a keyword that returns a list of dicts.
770 joinset = evalrawexp(context, mapping, args[0])
770 joinset = evalrawexp(context, mapping, args[0])
771 if util.safehasattr(joinset, 'itermaps'):
771 joinfmt = getattr(joinset, 'joinfmt', pycompat.identity)
772 jf = joinset.joinfmt
773 joinset = [jf(x) for x in joinset.itermaps()]
774
775 joiner = " "
772 joiner = " "
776 if len(args) > 1:
773 if len(args) > 1:
777 joiner = evalstring(context, mapping, args[1])
774 joiner = evalstring(context, mapping, args[1])
@@ -782,7 +779,7 b' def join(context, mapping, args):'
782 first = False
779 first = False
783 else:
780 else:
784 yield joiner
781 yield joiner
785 yield x
782 yield joinfmt(x)
786
783
787 @templatefunc('label(label, expr)')
784 @templatefunc('label(label, expr)')
788 def label(context, mapping, args):
785 def label(context, mapping, args):
General Comments 0
You need to be logged in to leave comments. Login now