comparison mercurial/hg.py @ 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 72b91f905065
children 545967ec33dc
comparison
equal deleted inserted replaced
35618:c780e0649e41 35619:c751b9fdbc40
305 Extensions can wrap this function and write additional entries to 305 Extensions can wrap this function and write additional entries to
306 destrepo/.hg/shared to indicate additional pieces of data to be shared. 306 destrepo/.hg/shared to indicate additional pieces of data to be shared.
307 """ 307 """
308 default = defaultpath or sourcerepo.ui.config('paths', 'default') 308 default = defaultpath or sourcerepo.ui.config('paths', 'default')
309 if default: 309 if default:
310 fp = destrepo.vfs("hgrc", "w", text=True) 310 with destrepo.vfs("hgrc", "w", text=True) as fp:
311 fp.write("[paths]\n") 311 fp.write("[paths]\n")
312 fp.write("default = %s\n" % default) 312 fp.write("default = %s\n" % default)
313 fp.close()
314 313
315 with destrepo.wlock(): 314 with destrepo.wlock():
316 if bookmarks: 315 if bookmarks:
317 fp = destrepo.vfs('shared', 'w') 316 destrepo.vfs.write('shared', sharedbookmarks + '\n')
318 fp.write(sharedbookmarks + '\n')
319 fp.close()
320 317
321 def _postshareupdate(repo, update, checkout=None): 318 def _postshareupdate(repo, update, checkout=None):
322 """Maybe perform a working directory update after a shared repo is created. 319 """Maybe perform a working directory update after a shared repo is created.
323 320
324 ``update`` can be a boolean or a revision to update to. 321 ``update`` can be a boolean or a revision to update to.