mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
subrepo: ensure "close()" execution at the end of "_initrepo()"
Before this patch, "close()" for the file object opened in "_initrepo()" may not be executed, if unexpected exception is raised, because it isn't executed in "finally" clause. This patch ensures "close()" execution at the end of "_initrepo()" by moving it into "finally" clause. This patch puts configuration lines into "lines" array and write them out at once, to narrow the scope of "try"/"finally" for review-ability. This patch doesn't use "vfs.write()", because: - current "vfs.write()" implementation doesn't take "mode" argument to open file in "text" mode - writing hgrc file out in binary mode may break backward compatibility
This commit is contained in:
parent
a9d25c900f
commit
bf65909194
@ -609,12 +609,11 @@ class hgsubrepo(abstractsubrepo):
|
||||
self._repo._subsource = source
|
||||
|
||||
if create:
|
||||
fp = self._repo.opener("hgrc", "w", text=True)
|
||||
fp.write('[paths]\n')
|
||||
lines = ['[paths]\n']
|
||||
|
||||
def addpathconfig(key, value):
|
||||
if value:
|
||||
fp.write('%s = %s\n' % (key, value))
|
||||
lines.append('%s = %s\n' % (key, value))
|
||||
self._repo.ui.setconfig('paths', key, value, 'subrepo')
|
||||
|
||||
defpath = _abssource(self._repo, abort=False)
|
||||
@ -622,6 +621,11 @@ class hgsubrepo(abstractsubrepo):
|
||||
addpathconfig('default', defpath)
|
||||
if defpath != defpushpath:
|
||||
addpathconfig('default-push', defpushpath)
|
||||
|
||||
fp = self._repo.opener("hgrc", "w", text=True)
|
||||
try:
|
||||
fp.write(''.join(lines))
|
||||
finally:
|
||||
fp.close()
|
||||
|
||||
@annotatesubrepoerror
|
||||
|
Loading…
Reference in New Issue
Block a user