# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1431910838 25200
#      Sun May 17 18:00:38 2015 -0700
# Node ID 3553163bb736be75e68465c9c50f310954bf055a
# Parent  81a395447b345dd8dd7cd002e99e66c8eaa18d53
revset: use 'next()' to detect end of iteration in 'last'

The 'next()' built-in can return a default value, allow to get rid of the
confusing try/except code flow.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1172,12 +1172,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 maxrev(repo, subset, x):