cmdutil: make getgraphlogrevs limit-aware
authorSiddharth Agarwal <sid0@fb.com>
Fri, 28 Dec 2012 16:25:12 -0800
changeset 18172 e6c5e0092469
parent 18171 9d350f2d9458
child 18173 9916d104c485
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%).
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Fri Dec 28 16:25:00 2012 -0800
+++ b/mercurial/cmdutil.py	Fri Dec 28 16:25:12 2012 -0800
@@ -1401,6 +1401,7 @@
     """
     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 @@
         # --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 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