Patchwork [02,of,10,PyPy] hbisect: use tryreadlines to load state

login
register
mail settings
Submitter Bryan O'Sullivan
Date Dec. 24, 2015, 12:22 a.m.
Message ID <f29d0d69d6ab06db3834.1450916537@bryano-mbp.local>
Download mbox | patch
Permalink /patch/12336/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Bryan O'Sullivan - Dec. 24, 2015, 12:22 a.m.
This closes the file handle after reading, which stops PyPy from
leaking open file handles and thus failing test-bisect3.t.

Patch

diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py
--- a/mercurial/hbisect.py
+++ b/mercurial/hbisect.py
@@ -143,13 +143,12 @@  def bisect(changelog, state):
 
 def load_state(repo):
     state = {'current': [], 'good': [], 'bad': [], 'skip': []}
-    if os.path.exists(repo.join("bisect.state")):
-        for l in repo.vfs("bisect.state"):
-            kind, node = l[:-1].split()
-            node = repo.lookup(node)
-            if kind not in state:
-                raise error.Abort(_("unknown bisect kind %s") % kind)
-            state[kind].append(node)
+    for l in repo.vfs.tryreadlines("bisect.state"):
+        kind, node = l[:-1].split()
+        node = repo.lookup(node)
+        if kind not in state:
+            raise error.Abort(_("unknown bisect kind %s") % kind)
+        state[kind].append(node)
     return state