changeset 35619:c751b9fdbc40

share: use context manager or utility function to write file
author Yuya Nishihara <yuya@tcha.org>
date Sat, 13 Jan 2018 13:23:16 +0900
parents c780e0649e41
children 545967ec33dc
files mercurial/hg.py
diffstat 1 files changed, 4 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Sun Dec 31 02:54:49 2017 -0500
+++ b/mercurial/hg.py	Sat Jan 13 13:23:16 2018 +0900
@@ -307,16 +307,13 @@
     """
     default = defaultpath or sourcerepo.ui.config('paths', 'default')
     if default:
-        fp = destrepo.vfs("hgrc", "w", text=True)
-        fp.write("[paths]\n")
-        fp.write("default = %s\n" % default)
-        fp.close()
+        with destrepo.vfs("hgrc", "w", text=True) as fp:
+            fp.write("[paths]\n")
+            fp.write("default = %s\n" % default)
 
     with destrepo.wlock():
         if bookmarks:
-            fp = destrepo.vfs('shared', 'w')
-            fp.write(sharedbookmarks + '\n')
-            fp.close()
+            destrepo.vfs.write('shared', sharedbookmarks + '\n')
 
 def _postshareupdate(repo, update, checkout=None):
     """Maybe perform a working directory update after a shared repo is created.