[PATCH 1 of 4] latesttag: make latesttaginfo available as a global function
Gilles Moris
gilles.moris at free.fr
Tue Oct 6 08:18:28 UTC 2009
mercurial/cmdutil.py | 55 +++++++++++++++++++++++++++++--------------------------
1 files changed, 29 insertions(+), 26 deletions(-)
# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1254816828 -7200
# Node ID c900201dd7709e704caac923cab31f423816afcd
# Parent c777835db6a7b00fbcb255f9d467b331bd97b533
latesttag: make latesttaginfo available as a global function
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -734,6 +734,33 @@
return parents
+def latesttaginfo(repo, rev, latesttagcache):
+ '''return date, distance and name for the latest tag of rev
+ function is reentrant and latesttagcache should be initialized with
+ {-1: (0, 0, 'null')}
+ '''
+ todo = [rev]
+ while todo:
+ rev = todo.pop()
+ if rev in latesttagcache:
+ continue
+ ctx = repo[rev]
+ tags = [t for t in ctx.tags() if repo.tagtype(t) == 'global']
+ if tags:
+ latesttagcache[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(
+ latesttagcache[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
+ latesttagcache[rev] = pdate, pdist + 1, ptag
+ return latesttagcache[rev]
+
class changeset_templater(changeset_printer):
'''format changeset information.'''
@@ -765,30 +792,6 @@
return []
return parents
- def _latesttaginfo(self, rev):
- '''return date, distance and name for the latest tag of rev'''
- todo = [rev]
- while todo:
- rev = todo.pop()
- if rev in self._latesttagcache:
- continue
- ctx = self.repo[rev]
- tags = [t for t in ctx.tags() if self.repo.tagtype(t) == 'global']
- if tags:
- self._latesttagcache[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(
- self._latesttagcache[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
- self._latesttagcache[rev] = pdate, pdist + 1, ptag
- return self._latesttagcache[rev]
-
def _show(self, ctx, copies, props):
'''show a single changeset or file revision'''
@@ -907,9 +910,9 @@
return '%s: +%s/-%s' % (files, adds, removes)
def showlatesttag(**args):
- return self._latesttaginfo(ctx.rev())[2]
+ return latesttaginfo(self.repo, ctx.rev(), self._latesttagcache)[2]
def showlatesttagdistance(**args):
- return self._latesttaginfo(ctx.rev())[1]
+ return latesttaginfo(self.repo, ctx.rev(), self._latesttagcache)[1]
defprops = {
'author': ctx.user(),
More information about the Mercurial-devel
mailing list