# HG changeset patch # User Pierre-Yves David # Date 2015-05-18 00:54:58 # Node ID 91c49621b2b80c8e145514c67e2dfc163ddb4da6 # Parent 24140873ca4c57ec9db6c715b2018de73547b6f9 _revancestors: use 'next' to remove the verbose try except clauses The 'next()' built-in can return a default value, making the final iteration case simpler and clearer. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -28,21 +28,18 @@ def _revancestors(repo, revs, followfirs revs.sort(reverse=True) irevs = iter(revs) h = [] - try: - inputrev = irevs.next() + + inputrev = next(irevs, None) + if inputrev is not None: heapq.heappush(h, -inputrev) - except StopIteration: - return seen = set() while h: current = -heapq.heappop(h) if current == inputrev: - try: - inputrev = irevs.next() + inputrev = next(irevs, None) + if inputrev is not None: heapq.heappush(h, -inputrev) - except StopIteration: - pass if current not in seen: seen.add(current) yield current