Patchwork [2,of,6] ancestor: return early from _lazyancestorsiter() when reached to stoprev

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 11, 2018, 11:02 p.m.
Message ID <dd6a0955ec0081c6133c.1536706927@mimosa>
Download mbox | patch
Permalink /patch/34504/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 11, 2018, 11:02 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1536583579 -32400
#      Mon Sep 10 21:46:19 2018 +0900
# Node ID dd6a0955ec0081c6133ce8cf42d38914a8e305ab
# Parent  2989618d644ce4694a3288f8f20107f446703f66
ancestor: return early from _lazyancestorsiter() when reached to stoprev

There's no need to empty the heap.

Patch

diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py
--- a/mercurial/ancestor.py
+++ b/mercurial/ancestor.py
@@ -281,12 +281,13 @@  def _lazyancestorsiter(parentrevs, initr
 
     while visit:
         current = -nextitem(visit)
-        if current >= stoprev:
-            yield current
-            for parent in parentrevs(current):
-                if parent not in seen:
-                    schedule(visit, -parent)
-                    see(parent)
+        if current < stoprev:
+            break
+        yield current
+        for parent in parentrevs(current):
+            if parent not in seen:
+                schedule(visit, -parent)
+                see(parent)
 
 class lazyancestors(object):
     def __init__(self, pfunc, revs, stoprev=0, inclusive=False):