Patchwork [8,of,8] hbisect: use tryreadlines to load state

login
register
mail settings
Submitter Bryan O'Sullivan
Date Dec. 23, 2015, 6:24 a.m.
Message ID <89a92700bdb96b8f6477.1450851886@bryano-mbp.local>
Download mbox | patch
Permalink /patch/12272/
State Superseded
Headers show

Comments

Bryan O'Sullivan - Dec. 23, 2015, 6:24 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bos@serpentine.com>
# Date 1450851054 28800
#      Tue Dec 22 22:10:54 2015 -0800
# Node ID 89a92700bdb96b8f6477d8bf59e268f7db0a13c1
# Parent  8c45e1eed7390cab1f3aaa4e16ac4a63e2d1703b
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.

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