# HG changeset patch # User Yuya Nishihara # Date 1515817396 -32400 # Node ID c751b9fdbc40263c28b380388e3c24d1ffb6ae74 # Parent c780e0649e4152180e892418f9879b82e51542c3 share: use context manager or utility function to write file diff -r c780e0649e41 -r c751b9fdbc40 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.