hbisect: use tryreadlines to load state
authorBryan O'Sullivan <bos@serpentine.com>
Sun, 27 Dec 2015 23:55:54 +0900
changeset 27525 cba62f996780
parent 27524 f5b6b4e574c1
child 27526 11f2e496bdc9
hbisect: use tryreadlines to load state This closes the file handle after reading, which stops PyPy from leaking open file handles and thus failing test-bisect3.t.
mercurial/hbisect.py
--- a/mercurial/hbisect.py	Sun Dec 27 23:55:54 2015 +0900
+++ b/mercurial/hbisect.py	Sun Dec 27 23:55:54 2015 +0900
@@ -11,7 +11,6 @@
 from __future__ import absolute_import
 
 import collections
-import os
 
 from .i18n import _
 from .node import (
@@ -143,13 +142,12 @@
 
 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