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

login
register
mail settings
Submitter Augie Fackler
Date Jan. 5, 2016, 4:16 p.m.
Message ID <2347e29b209dfb2b64a9.1452010611@imladris.local>
Download mbox | patch
Permalink /patch/12537/
State Accepted
Headers show

Comments

Augie Fackler - Jan. 5, 2016, 4:16 p.m.
# HG changeset patch
# User Augie Fackler <augie@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.
Yuya Nishihara - Jan. 9, 2016, 2:58 a.m.
On Tue, 05 Jan 2016 11:16:51 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@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

Makes sense. I've pushed the first patch to the clowncopter, thanks.

Patch

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