comparison mercurial/templatekw.py @ 36596:b5d39a09656a

templatekw: switch latesttags template keywords to new API
author Yuya Nishihara <yuya@tcha.org>
date Sun, 25 Feb 2018 19:23:06 +0900
parents 2da414105809
children d57f383516f6
comparison
equal deleted inserted replaced
36595:2da414105809 36596:b5d39a09656a
238 yield one(last, tag=lastname) 238 yield one(last, tag=lastname)
239 endname = 'end_' + plural 239 endname = 'end_' + plural
240 if endname in templ: 240 if endname in templ:
241 yield templ(endname, **strmapping) 241 yield templ(endname, **strmapping)
242 242
243 def getlatesttags(repo, ctx, cache, pattern=None): 243 def getlatesttags(context, mapping, pattern=None):
244 '''return date, distance and name for the latest tag of rev''' 244 '''return date, distance and name for the latest tag of rev'''
245 repo = context.resource(mapping, 'repo')
246 ctx = context.resource(mapping, 'ctx')
247 cache = context.resource(mapping, 'cache')
245 248
246 cachename = 'latesttags' 249 cachename = 'latesttags'
247 if pattern is not None: 250 if pattern is not None:
248 cachename += '-' + pattern 251 cachename += '-' + pattern
249 match = util.stringmatcher(pattern)[2] 252 match = util.stringmatcher(pattern)[2]
587 def showindex(context, mapping): 590 def showindex(context, mapping):
588 """Integer. The current iteration of the loop. (0 indexed)""" 591 """Integer. The current iteration of the loop. (0 indexed)"""
589 # just hosts documentation; should be overridden by template mapping 592 # just hosts documentation; should be overridden by template mapping
590 raise error.Abort(_("can't use index in this context")) 593 raise error.Abort(_("can't use index in this context"))
591 594
592 @templatekeyword('latesttag') 595 @templatekeyword('latesttag', requires={'repo', 'ctx', 'cache', 'templ'})
593 def showlatesttag(**args): 596 def showlatesttag(context, mapping):
594 """List of strings. The global tags on the most recent globally 597 """List of strings. The global tags on the most recent globally
595 tagged ancestor of this changeset. If no such tags exist, the list 598 tagged ancestor of this changeset. If no such tags exist, the list
596 consists of the single string "null". 599 consists of the single string "null".
597 """ 600 """
598 return showlatesttags(None, **args) 601 return showlatesttags(context, mapping, None)
599 602
600 def showlatesttags(pattern, **args): 603 def showlatesttags(context, mapping, pattern):
601 """helper method for the latesttag keyword and function""" 604 """helper method for the latesttag keyword and function"""
602 args = pycompat.byteskwargs(args) 605 latesttags = getlatesttags(context, mapping, pattern)
603 repo, ctx = args['repo'], args['ctx']
604 cache = args['cache']
605 latesttags = getlatesttags(repo, ctx, cache, pattern)
606 606
607 # latesttag[0] is an implementation detail for sorting csets on different 607 # latesttag[0] is an implementation detail for sorting csets on different
608 # branches in a stable manner- it is the date the tagged cset was created, 608 # branches in a stable manner- it is the date the tagged cset was created,
609 # not the date the tag was created. Therefore it isn't made visible here. 609 # not the date the tag was created. Therefore it isn't made visible here.
610 makemap = lambda v: { 610 makemap = lambda v: {
613 'latesttag': v, # BC with {latesttag % '{latesttag}'} 613 'latesttag': v, # BC with {latesttag % '{latesttag}'}
614 'tag': v 614 'tag': v
615 } 615 }
616 616
617 tags = latesttags[2] 617 tags = latesttags[2]
618 f = _showlist('latesttag', tags, args['templ'], args, separator=':') 618 templ = context.resource(mapping, 'templ')
619 f = _showlist('latesttag', tags, templ, mapping, separator=':')
619 return _hybrid(f, tags, makemap, pycompat.identity) 620 return _hybrid(f, tags, makemap, pycompat.identity)
620 621
621 @templatekeyword('latesttagdistance') 622 @templatekeyword('latesttagdistance', requires={'repo', 'ctx', 'cache'})
622 def showlatesttagdistance(repo, ctx, templ, cache, **args): 623 def showlatesttagdistance(context, mapping):
623 """Integer. Longest path to the latest tag.""" 624 """Integer. Longest path to the latest tag."""
624 return getlatesttags(repo, ctx, cache)[1] 625 return getlatesttags(context, mapping)[1]
625 626
626 @templatekeyword('changessincelatesttag') 627 @templatekeyword('changessincelatesttag', requires={'repo', 'ctx', 'cache'})
627 def showchangessincelatesttag(repo, ctx, templ, cache, **args): 628 def showchangessincelatesttag(context, mapping):
628 """Integer. All ancestors not in the latest tag.""" 629 """Integer. All ancestors not in the latest tag."""
629 latesttag = getlatesttags(repo, ctx, cache)[2][0] 630 mapping = mapping.copy()
630 631 mapping['tag'] = getlatesttags(context, mapping)[2][0]
631 return _showchangessincetag(repo, ctx, tag=latesttag, **args) 632 return _showchangessincetag(context, mapping)
632 633
633 def _showchangessincetag(repo, ctx, **args): 634 def _showchangessincetag(context, mapping):
635 repo = context.resource(mapping, 'repo')
636 ctx = context.resource(mapping, 'ctx')
634 offset = 0 637 offset = 0
635 revs = [ctx.rev()] 638 revs = [ctx.rev()]
636 tag = args[r'tag'] 639 tag = context.symbol(mapping, 'tag')
637 640
638 # The only() revset doesn't currently support wdir() 641 # The only() revset doesn't currently support wdir()
639 if ctx.rev() is None: 642 if ctx.rev() is None:
640 offset = 1 643 offset = 1
641 revs = [p.rev() for p in ctx.parents()] 644 revs = [p.rev() for p in ctx.parents()]
642 645
643 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset 646 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
647
648 # teach templater latesttags.changes is switched to (context, mapping) API
649 _showchangessincetag._requires = {'repo', 'ctx'}
644 650
645 @templatekeyword('manifest') 651 @templatekeyword('manifest')
646 def showmanifest(**args): 652 def showmanifest(**args):
647 repo, ctx, templ = args[r'repo'], args[r'ctx'], args[r'templ'] 653 repo, ctx, templ = args[r'repo'], args[r'ctx'], args[r'templ']
648 mnode = ctx.manifestnode() 654 mnode = ctx.manifestnode()