bookmarks: make _readactive safe when readlines raises ENOENT
authorAugie Fackler <augie@google.com>
Tue, 01 Dec 2015 13:08:05 -0500
changeset 27685 9fbae70faf65
parent 27684 e9857fbfd072
child 27686 df142b77b4c2
bookmarks: make _readactive safe when readlines raises ENOENT When reading over static http, the file isn't actually opened until the readlines() call, so we have to check for ENOENT IOErrors here too. This is necessary so that we can use the bmstore everywhere for managing the active bookmark, which will be true in the next change.
mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Thu Dec 17 21:24:08 2015 -0500
+++ b/mercurial/bookmarks.py	Tue Dec 01 13:08:05 2015 -0500
@@ -165,10 +165,19 @@
             raise
         return None
     try:
-        # No readline() in osutil.posixfile, reading everything is cheap
+        # No readline() in osutil.posixfile, reading everything is
+        # cheap.
+        # Note that it's possible for readlines() here to raise
+        # IOError, since we might be reading the active mark over
+        # static-http which only tries to load the file when we try
+        # to read from it.
         mark = encoding.tolocal((file.readlines() or [''])[0])
         if mark == '' or mark not in repo._bookmarks:
             mark = None
+    except IOError as inst:
+        if inst.errno != errno.ENOENT:
+            raise
+        return None
     finally:
         file.close()
     return mark