Patchwork [5,of,6,v2] bookmarks: make _readactive safe when readlines raises ENOENT

login
register
mail settings
Submitter Augie Fackler
Date Dec. 2, 2015, 4:58 p.m.
Message ID <6f3aa7041edf0ab6a4c8.1449075524@imladris.local>
Download mbox | patch
Permalink /patch/11754/
State Superseded
Commit 9fbae70faf650e9f37ff73cd59718943f296e83c
Headers show

Comments

Augie Fackler - Dec. 2, 2015, 4:58 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1448993285 18000
#      Tue Dec 01 13:08:05 2015 -0500
# Node ID 6f3aa7041edf0ab6a4c891ebbf566b4c94523847
# Parent  4600ce9ad6ec0bd96c34d28b7c61ebe4926f5c2e
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.
Pierre-Yves David - Dec. 2, 2015, 6:56 p.m.
On 12/02/2015 08:58 AM, 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 6f3aa7041edf0ab6a4c891ebbf566b4c94523847
> # Parent  4600ce9ad6ec0bd96c34d28b7c61ebe4926f5c2e
> 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.

Urg, I'm pretty sure this is breaking other stuff.
Can you at least document the reason on this hack inline?
(should we fix this at the httprepo level?)
Augie Fackler - Dec. 2, 2015, 7:21 p.m.
> On Dec 2, 2015, at 1:56 PM, Pierre-Yves David <pierre-yves.david@ens-lyon.org> wrote:
> 
> 
> 
> On 12/02/2015 08:58 AM, 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 6f3aa7041edf0ab6a4c891ebbf566b4c94523847
>> # Parent  4600ce9ad6ec0bd96c34d28b7c61ebe4926f5c2e
>> 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.
> 
> Urg, I'm pretty sure this is breaking other stuff.

You mean this failure mode of files accessed over static-http is breaking other things? Seems likely.,

> Can you at least document the reason on this hack inline?

Can do.

> (should we fix this at the httprepo level?)

There’s not really a good way to do that since we sometimes open files without immediately reading them.

> 
> --
> Pierre-Yves David

Patch

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