Show More
@@ -240,8 +240,11 b' def _showlist(name, values, templ, mappi' | |||
|
240 | 240 | if endname in templ: |
|
241 | 241 | yield templ(endname, **strmapping) |
|
242 | 242 | |
|
243 |
def getlatesttags( |
|
|
243 | def getlatesttags(context, mapping, pattern=None): | |
|
244 | 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 | 249 | cachename = 'latesttags' |
|
247 | 250 | if pattern is not None: |
@@ -589,20 +592,17 b' def showindex(context, mapping):' | |||
|
589 | 592 | # just hosts documentation; should be overridden by template mapping |
|
590 | 593 | raise error.Abort(_("can't use index in this context")) |
|
591 | 594 | |
|
592 | @templatekeyword('latesttag') | |
|
593 |
def showlatesttag( |
|
|
595 | @templatekeyword('latesttag', requires={'repo', 'ctx', 'cache', 'templ'}) | |
|
596 | def showlatesttag(context, mapping): | |
|
594 | 597 | """List of strings. The global tags on the most recent globally |
|
595 | 598 | tagged ancestor of this changeset. If no such tags exist, the list |
|
596 | 599 | consists of the single string "null". |
|
597 | 600 | """ |
|
598 |
return showlatesttags( |
|
|
601 | return showlatesttags(context, mapping, None) | |
|
599 | 602 | |
|
600 |
def showlatesttags( |
|
|
603 | def showlatesttags(context, mapping, pattern): | |
|
601 | 604 | """helper method for the latesttag keyword and function""" |
|
602 | args = pycompat.byteskwargs(args) | |
|
603 | repo, ctx = args['repo'], args['ctx'] | |
|
604 | cache = args['cache'] | |
|
605 | latesttags = getlatesttags(repo, ctx, cache, pattern) | |
|
605 | latesttags = getlatesttags(context, mapping, pattern) | |
|
606 | 606 | |
|
607 | 607 | # latesttag[0] is an implementation detail for sorting csets on different |
|
608 | 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 | 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 | 620 | return _hybrid(f, tags, makemap, pycompat.identity) |
|
620 | 621 | |
|
621 | @templatekeyword('latesttagdistance') | |
|
622 |
def showlatesttagdistance( |
|
|
622 | @templatekeyword('latesttagdistance', requires={'repo', 'ctx', 'cache'}) | |
|
623 | def showlatesttagdistance(context, mapping): | |
|
623 | 624 | """Integer. Longest path to the latest tag.""" |
|
624 |
return getlatesttags( |
|
|
625 | return getlatesttags(context, mapping)[1] | |
|
625 | 626 | |
|
626 | @templatekeyword('changessincelatesttag') | |
|
627 |
def showchangessincelatesttag( |
|
|
627 | @templatekeyword('changessincelatesttag', requires={'repo', 'ctx', 'cache'}) | |
|
628 | def showchangessincelatesttag(context, mapping): | |
|
628 | 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) | |
|
632 | ||
|
633 | def _showchangessincetag(repo, ctx, **args): | |
|
634 | def _showchangessincetag(context, mapping): | |
|
635 | repo = context.resource(mapping, 'repo') | |
|
636 | ctx = context.resource(mapping, 'ctx') | |
|
634 | 637 | offset = 0 |
|
635 | 638 | revs = [ctx.rev()] |
|
636 | tag = args[r'tag'] | |
|
639 | tag = context.symbol(mapping, 'tag') | |
|
637 | 640 | |
|
638 | 641 | # The only() revset doesn't currently support wdir() |
|
639 | 642 | if ctx.rev() is None: |
@@ -642,6 +645,9 b' def _showchangessincetag(repo, ctx, **ar' | |||
|
642 | 645 | |
|
643 | 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 | 651 | @templatekeyword('manifest') |
|
646 | 652 | def showmanifest(**args): |
|
647 | 653 | repo, ctx, templ = args[r'repo'], args[r'ctx'], args[r'templ'] |
@@ -942,11 +942,7 b' def latesttag(context, mapping, args):' | |||
|
942 | 942 | pattern = None |
|
943 | 943 | if len(args) == 1: |
|
944 | 944 | pattern = evalstring(context, mapping, args[0]) |
|
945 | ||
|
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)) | |
|
945 | return templatekw.showlatesttags(context, mapping, pattern) | |
|
950 | 946 | |
|
951 | 947 | @templatefunc('localdate(date[, tz])') |
|
952 | 948 | def localdate(context, mapping, args): |
General Comments 0
You need to be logged in to leave comments.
Login now