clfilter: remove usage of `range` in favor of iteration over changelog
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 20 Sep 2012 19:01:53 +0200
changeset 17675 8575f4a2126e
parent 17674 e69274f8d444
child 17676 f87683a1b02a
clfilter: remove usage of `range` in favor of iteration over changelog If we want to apply filtering at changelog level, we need to iterate over it. See previous changeset description for details.
mercurial/cmdutil.py
mercurial/localrepo.py
mercurial/revset.py
mercurial/scmutil.py
--- a/mercurial/cmdutil.py	Mon Sep 03 14:19:45 2012 +0200
+++ b/mercurial/cmdutil.py	Thu Sep 20 19:01:53 2012 +0200
@@ -1394,7 +1394,8 @@
         if follow and len(repo) > 0:
             revs = scmutil.revrange(repo, ['.:0'])
         else:
-            revs = range(len(repo) - 1, -1, -1)
+            revs = list(repo.changelog)
+            revs.reverse()
     if not revs:
         return iter([]), None, None
     expr, filematcher = _makegraphlogrevset(repo, pats, opts, revs)
--- a/mercurial/localrepo.py	Mon Sep 03 14:19:45 2012 +0200
+++ b/mercurial/localrepo.py	Thu Sep 20 19:01:53 2012 +0200
@@ -363,14 +363,13 @@
         return len(self.changelog)
 
     def __iter__(self):
-        for i in xrange(len(self)):
-            yield i
+        return iter(self.changelog)
 
     def revs(self, expr, *args):
         '''Return a list of revisions matching the given revset'''
         expr = revset.formatspec(expr, *args)
         m = revset.match(None, expr)
-        return [r for r in m(self, range(len(self)))]
+        return [r for r in m(self, list(self))]
 
     def set(self, expr, *args):
         '''
@@ -603,7 +602,7 @@
         # TODO: rename this function?
         tiprev = len(self) - 1
         if lrev != tiprev:
-            ctxgen = (self[r] for r in xrange(lrev + 1, tiprev + 1))
+            ctxgen = (self[r] for r in self.changelog.revs(lrev + 1, tiprev))
             self._updatebranchcache(partial, ctxgen)
             self._writebranchcache(partial, self.changelog.tip(), tiprev)
 
--- a/mercurial/revset.py	Mon Sep 03 14:19:45 2012 +0200
+++ b/mercurial/revset.py	Thu Sep 20 19:01:53 2012 +0200
@@ -215,11 +215,11 @@
 def rangeset(repo, subset, x, y):
     m = getset(repo, subset, x)
     if not m:
-        m = getset(repo, range(len(repo)), x)
+        m = getset(repo, list(repo), x)
 
     n = getset(repo, subset, y)
     if not n:
-        n = getset(repo, range(len(repo)), y)
+        n = getset(repo, list(repo), y)
 
     if not m or not n:
         return []
@@ -234,7 +234,7 @@
 
 def dagrange(repo, subset, x, y):
     if subset:
-        r = range(len(repo))
+        r = list(repo)
         xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
         s = set(subset)
         return [r for r in xs if r in s]
@@ -277,7 +277,7 @@
     """
     # i18n: "ancestor" is a keyword
     l = getargs(x, 2, 2, _("ancestor requires two arguments"))
-    r = range(len(repo))
+    r = list(repo)
     a = getset(repo, r, l[0])
     b = getset(repo, r, l[1])
     if len(a) != 1 or len(b) != 1:
@@ -288,7 +288,7 @@
     return [r for r in an if r in subset]
 
 def _ancestors(repo, subset, x, followfirst=False):
-    args = getset(repo, range(len(repo)), x)
+    args = getset(repo, list(repo), x)
     if not args:
         return []
     s = set(_revancestors(repo, args, followfirst)) | set(args)
@@ -415,7 +415,7 @@
         else:
             return [r for r in subset if matcher(repo[r].branch())]
 
-    s = getset(repo, range(len(repo)), x)
+    s = getset(repo, list(repo), x)
     b = set()
     for r in s:
         b.add(repo[r].branch())
@@ -466,7 +466,7 @@
     """``children(set)``
     Child changesets of changesets in set.
     """
-    s = set(getset(repo, range(len(repo)), x))
+    s = set(getset(repo, list(repo), x))
     cs = _children(repo, subset, s)
     return [r for r in subset if r in cs]
 
@@ -547,7 +547,7 @@
     return l
 
 def _descendants(repo, subset, x, followfirst=False):
-    args = getset(repo, range(len(repo)), x)
+    args = getset(repo, list(repo), x)
     if not args:
         return []
     s = set(_revdescendants(repo, args, followfirst)) | set(args)
@@ -571,9 +571,9 @@
     is the same as passing all().
     """
     if x is not None:
-        args = set(getset(repo, range(len(repo)), x))
+        args = set(getset(repo, list(repo), x))
     else:
-        args = set(getall(repo, range(len(repo)), x))
+        args = set(getall(repo, list(repo), x))
 
     dests = set()
 
@@ -877,7 +877,7 @@
         # i18n: "limit" is a keyword
         raise error.ParseError(_("limit expects a number"))
     ss = set(subset)
-    os = getset(repo, range(len(repo)), l[0])[:lim]
+    os = getset(repo, list(repo), l[0])[:lim]
     return [r for r in os if r in ss]
 
 def last(repo, subset, x):
@@ -895,14 +895,14 @@
         # i18n: "last" is a keyword
         raise error.ParseError(_("last expects a number"))
     ss = set(subset)
-    os = getset(repo, range(len(repo)), l[0])[-lim:]
+    os = getset(repo, list(repo), l[0])[-lim:]
     return [r for r in os if r in ss]
 
 def maxrev(repo, subset, x):
     """``max(set)``
     Changeset with highest revision number in set.
     """
-    os = getset(repo, range(len(repo)), x)
+    os = getset(repo, list(repo), x)
     if os:
         m = max(os)
         if m in subset:
@@ -922,7 +922,7 @@
     """``min(set)``
     Changeset with lowest revision number in set.
     """
-    os = getset(repo, range(len(repo)), x)
+    os = getset(repo, list(repo), x)
     if os:
         m = min(os)
         if m in subset:
@@ -972,9 +972,9 @@
     for the first operation is selected.
     """
     if x is not None:
-        args = set(getset(repo, range(len(repo)), x))
+        args = set(getset(repo, list(repo), x))
     else:
-        args = set(getall(repo, range(len(repo)), x))
+        args = set(getall(repo, list(repo), x))
 
     def _firstsrc(rev):
         src = _getrevsource(repo, rev)
@@ -1024,7 +1024,7 @@
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, range(len(repo)), x):
+    for r in getset(repo, list(repo), x):
         ps.add(cl.parentrevs(r)[0])
     return [r for r in subset if r in ps]
 
@@ -1042,7 +1042,7 @@
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, range(len(repo)), x):
+    for r in getset(repo, list(repo), x):
         ps.add(cl.parentrevs(r)[1])
     return [r for r in subset if r in ps]
 
@@ -1056,7 +1056,7 @@
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, range(len(repo)), x):
+    for r in getset(repo, list(repo), x):
         ps.update(cl.parentrevs(r))
     return [r for r in subset if r in ps]
 
--- a/mercurial/scmutil.py	Mon Sep 03 14:19:45 2012 +0200
+++ b/mercurial/scmutil.py	Thu Sep 20 19:01:53 2012 +0200
@@ -631,7 +631,7 @@
 
         # fall through to new-style queries if old-style fails
         m = revset.match(repo.ui, spec)
-        dl = [r for r in m(repo, xrange(len(repo))) if r not in seen]
+        dl = [r for r in m(repo, list(repo)) if r not in seen]
         l.extend(dl)
         seen.update(dl)