changeset 25144:81a395447b34

revset: use 'next()' to detect end of iteration in 'limit' The 'next()' built-in can return a default value, allow to get rid of the confusing try/except code flow.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sun, 17 May 2015 17:58:39 -0700
parents 91c49621b2b8
children 3553163bb736
files mercurial/revset.py
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sun May 17 17:54:58 2015 -0700
+++ b/mercurial/revset.py	Sun May 17 17:58:39 2015 -0700
@@ -1145,12 +1145,11 @@
     result = []
     it = iter(os)
     for x in xrange(lim):
-        try:
-            y = it.next()
-            if y in ss:
-                result.append(y)
-        except (StopIteration):
+        y = next(it, None)
+        if y is None:
             break
+        elif y in ss:
+            result.append(y)
     return baseset(result)
 
 def last(repo, subset, x):