share: use context manager or utility function to write file
authorYuya Nishihara <yuya@tcha.org>
Sat, 13 Jan 2018 13:23:16 +0900
changeset 35619 c751b9fdbc40
parent 35618 c780e0649e41
child 35620 545967ec33dc
share: use context manager or utility function to write file
mercurial/hg.py
--- 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.