[PATCH 1 of 2 bmstore] bookmarks: make _readactive safe when readlines raises ENOENT

Augie Fackler raf at durin42.com
Tue Jan 5 16:16:51 UTC 2016


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1448993285 18000
#      Tue Dec 01 13:08:05 2015 -0500
# Node ID 2347e29b209dfb2b64a9c2f57f8ecacf9bf9af3a
# Parent  0bc71f45d3623b231cc3975b48feccce79d1231e
# EXP-Topic bmstore
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.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -165,10 +165,19 @@ def readactive(repo):
             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


More information about the Mercurial-devel mailing list