# HG changeset patch
# User Jordi Gutiérrez Hermoso <jord...@octave.org>
# Date 1516242948 18000
#      Wed Jan 17 21:35:48 2018 -0500
# Node ID 701f8a9defdc09bb63f2596e2fc426f2e78da313
# Parent  0e369eca888fc80ee980fe8200c59dc7b0024dae
templatekw: add utility function numrevs

len(repo) calls incur noticeable overhead if called for each revision
a template keyword is evaluated. We obviously can't cache __len__
functions in general because many commands modify the repo size. For
template keywords, however, the repo is read-only so we can benefit
from a cache.

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -852,6 +852,10 @@ def showrev(repo, ctx, templ, **args):
     """Integer. The repository-local changeset revision number."""
     return scmutil.intrev(ctx)
 
+@util.cachefunc
+def numrevs(repo):
+    return len(repo)
+
 def showrevslist(name, revs, **args):
     """helper to generate a list of revisions in which a mapped template will
     be evaluated"""
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to