changeset 42312:2b77183ac477

bookmarks: use vfs.tryread() instead of reimplementing it Differential Revision: https://phab.mercurial-scm.org/D6383
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 15 May 2019 10:19:36 -0700
parents ec5bd3ab26bf
children 81ece800576a
files mercurial/bookmarks.py
diffstat 1 files changed, 6 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Wed May 15 10:13:29 2019 -0700
+++ b/mercurial/bookmarks.py	Wed May 15 10:19:36 2019 -0700
@@ -297,28 +297,12 @@
     itself as we commit. This function returns the name of that bookmark.
     It is stored in .hg/bookmarks.current
     """
-    try:
-        file = repo.vfs('bookmarks.current')
-    except IOError as inst:
-        if inst.errno != errno.ENOENT:
-            raise
-        return None
-    try:
-        # 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 marks:
-            mark = None
-    except IOError as inst:
-        if inst.errno != errno.ENOENT:
-            raise
-        return None
-    finally:
-        file.close()
+    # No readline() in osutil.posixfile, reading everything is
+    # cheap.
+    content = repo.vfs.tryread('bookmarks.current')
+    mark = encoding.tolocal((content.splitlines() or [''])[0])
+    if mark == '' or mark not in marks:
+        mark = None
     return mark
 
 def activate(repo, mark):