[PATCH 5 of 6] cmdutil: extract latest tags closures in templatekw
Patrick Mézard
pmezard at gmail.com
Tue Dec 1 02:28:51 CST 2009
Le 30/11/2009 23:34, Patrick Mezard a écrit :
> # HG changeset patch
> # User Patrick Mezard <pmezard at gmail.com>
> # Date 1259616498 -3600
> # Node ID c892c6cc06cbdab1354e0af2312d74eb7061ab52
> # Parent 9651033b608af8b664eba0962a0fc943235f373b
> cmdutil: extract latest tags closures in templatekw
[...]
> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
> --- a/mercurial/templatekw.py
> +++ b/mercurial/templatekw.py
> @@ -75,6 +75,39 @@
> ctx.node())[:3]
> return cache['files']
>
> +def getlatesttags(repo, ctx, cache):
> + '''return date, distance and name for the latest tag of rev'''
> +
> + if 'latesttags' not in cache:
> + # Cache mapping from rev to a tuple with tag date, tag
> + # distance and tag name
> + cache['latesttags'] = {-1: (0, 0, 'null')}
> + latesttags = cache['latesttags']
This one is buggy, "cache" is reset on every new changeset while we want the latesttags cache to live through the whole display run. I will probably introduce another "revcache" object. I hope this won't make the template map too messy.
> + rev = ctx.rev()
> + todo = [rev]
> + while todo:
> + rev = todo.pop()
> + if rev in latesttags:
> + continue
> + ctx = repo[rev]
> + tags = [t for t in ctx.tags() if repo.tagtype(t) == 'global']
> + if tags:
> + latesttags[rev] = ctx.date()[0], 0, ':'.join(sorted(tags))
> + continue
> + try:
> + # The tuples are laid out so the right one can be found by
> + # comparison.
> + pdate, pdist, ptag = max(
> + latesttags[p.rev()] for p in ctx.parents())
> + except KeyError:
> + # Cache miss - recurse
> + todo.append(rev)
> + todo.extend(p.rev() for p in ctx.parents())
> + continue
> + latesttags[rev] = pdate, pdist + 1, ptag
> + return latesttags[rev]
> +
> def showauthor(repo, ctx, templ, **args):
> return ctx.user()
--
Patrick Mézard
More information about the Mercurial-devel
mailing list