##// END OF EJS Templates
templatekw: switch latesttags template keywords to new API
Yuya Nishihara -
r36614:b5d39a09 default
parent child Browse files
Show More
@@ -240,8 +240,11 b' def _showlist(name, values, templ, mappi'
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:
@@ -589,20 +592,17 b' def showindex(context, mapping):'
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,
@@ -615,25 +615,28 b' def showlatesttags(pattern, **args):'
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()
631 mapping['tag'] = getlatesttags(context, mapping)[2][0]
632 return _showchangessincetag(context, mapping)
630
633
631 return _showchangessincetag(repo, ctx, tag=latesttag, **args)
634 def _showchangessincetag(context, mapping):
632
635 repo = context.resource(mapping, 'repo')
633 def _showchangessincetag(repo, ctx, **args):
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:
@@ -642,6 +645,9 b' def _showchangessincetag(repo, ctx, **ar'
642
645
643 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
646 return len(repo.revs('only(%ld, %s)', revs, tag)) + offset
644
647
648 # teach templater latesttags.changes is switched to (context, mapping) API
649 _showchangessincetag._requires = {'repo', 'ctx'}
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']
@@ -942,11 +942,7 b' def latesttag(context, mapping, args):'
942 pattern = None
942 pattern = None
943 if len(args) == 1:
943 if len(args) == 1:
944 pattern = evalstring(context, mapping, args[0])
944 pattern = evalstring(context, mapping, args[0])
945
945 return templatekw.showlatesttags(context, mapping, pattern)
946 # TODO: pass (context, mapping) pair to keyword function
947 props = context._resources.copy()
948 props.update(mapping)
949 return templatekw.showlatesttags(pattern, **pycompat.strkwargs(props))
950
946
951 @templatefunc('localdate(date[, tz])')
947 @templatefunc('localdate(date[, tz])')
952 def localdate(context, mapping, args):
948 def localdate(context, mapping, args):
General Comments 0
You need to be logged in to leave comments. Login now