Patchwork D6382: bookmarks: use context manager when writing files

login
register
mail settings
Submitter phabricator
Date May 16, 2019, 11:58 a.m.
Message ID <65126430c8d2dfee803755b929836842@localhost.localdomain>
Download mbox | patch
Permalink /patch/40081/
State Not Applicable
Headers show

Comments

phabricator - May 16, 2019, 11:58 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG042c27f35885: bookmarks: use context manager when writing files (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6382?vs=15126&id=15133

REVISION DETAIL
  https://phab.mercurial-scm.org/D6382

AFFECTED FILES
  mercurial/bookmarks.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -204,27 +204,18 @@ 
             rbm._writeactive()
 
         with repo.wlock():
-            file_ = repo.vfs('bookmarks', 'w', atomictemp=True,
-                             checkambig=True)
-            try:
-                self._write(file_)
-            except: # re-raises
-                file_.discard()
-                raise
-            finally:
-                file_.close()
+            with repo.vfs('bookmarks', 'w', atomictemp=True,
+                          checkambig=True) as f:
+                self._write(f)
 
     def _writeactive(self):
         if self._aclean:
             return
         with self._repo.wlock():
             if self._active is not None:
-                f = self._repo.vfs('bookmarks.current', 'w', atomictemp=True,
-                                   checkambig=True)
-                try:
+                with self._repo.vfs('bookmarks.current', 'w', atomictemp=True,
+                                   checkambig=True) as f:
                     f.write(encoding.fromlocal(self._active))
-                finally:
-                    f.close()
             else:
                 self._repo.vfs.tryunlink('bookmarks.current')
         self._aclean = True