# HG changeset patch # User Pierre-Yves David # Date 2015-05-18 00:58:39 # Node ID 81a395447b345dd8dd7cd002e99e66c8eaa18d53 # Parent 91c49621b2b80c8e145514c67e2dfc163ddb4da6 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. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1145,12 +1145,11 @@ def limit(repo, subset, x): 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):