[PATCH 4 of 4] cmdutil: make getgraphlogrevs limit-aware

Siddharth Agarwal sid0 at fb.com
Fri Dec 28 18:56:40 CST 2012


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1356740712 28800
# Node ID c28add2711b42059ed0ad51e6fd4bf30274ff8d7
# Parent  25e3eb405558033979899284c156231783935ae9
cmdutil: make getgraphlogrevs limit-aware

For a repository with over 400,000 changesets, this speeds up graphlog with a
small limit by around 0.05 seconds (~50%).

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1401,6 +1401,7 @@ def getgraphlogrevs(repo, pats, opts):
     """
     if not len(repo):
         return [], None, None
+    limit = loglimit(opts)
     # Default --rev value depends on --follow but --follow behaviour
     # depends on revisions resolved from --rev...
     follow = opts.get('follow') or opts.get('follow_first')
@@ -1435,7 +1436,22 @@ def getgraphlogrevs(repo, pats, opts):
         # --hidden is still experimental and not worth a dedicated revset
         # yet. Fortunately, filtering revision number is fast.
         hiddenrevs = repo.hiddenrevs
-        revs = [r for r in revs if r not in hiddenrevs]
+        nrevs = []
+        taken = 0
+        if limit is not None:
+            for i in xrange(len(revs)):
+                if taken >= limit:
+                    break
+                r = revs[i]
+                if r not in hiddenrevs:
+                    nrevs.append(r)
+                    taken += 1
+            revs = nrevs
+        else:
+            revs = [r for r in revs if r not in hiddenrevs]
+    elif limit is not None:
+        revs = revs[:limit]
+
     return revs, expr, filematcher
 
 def displaygraph(ui, dag, displayer, showparents, edgefn, getrenamed=None,
@@ -1470,9 +1486,6 @@ def displaygraph(ui, dag, displayer, sho
 def graphlog(ui, repo, *pats, **opts):
     # Parameters are identical to log command ones
     revs, expr, filematcher = getgraphlogrevs(repo, pats, opts)
-    limit = loglimit(opts)
-    if limit is not None:
-        revs = revs[:limit]
     revdag = graphmod.dagwalker(repo, revs)
 
     getrenamed = None


More information about the Mercurial-devel mailing list