D7626: config: close file even if we fail to read it
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Mon Dec 16 18:34:19 EST 2019
martinvonz updated this revision to Diff 18778.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D7626?vs=18656&id=18778
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D7626/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D7626
AFFECTED FILES
mercurial/ui.py
CHANGE DETAILS
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -434,16 +434,16 @@
return
raise
- cfg = config.config()
- trusted = sections or trust or self._trusted(fp, filename)
+ with fp:
+ cfg = config.config()
+ trusted = sections or trust or self._trusted(fp, filename)
- try:
- cfg.read(filename, fp, sections=sections, remap=remap)
- fp.close()
- except error.ParseError as inst:
- if trusted:
- raise
- self.warn(_(b"ignored: %s\n") % stringutil.forcebytestr(inst))
+ try:
+ cfg.read(filename, fp, sections=sections, remap=remap)
+ except error.ParseError as inst:
+ if trusted:
+ raise
+ self.warn(_(b'ignored: %s\n') % stringutil.forcebytestr(inst))
if self.plain():
for k in (
To: martinvonz, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list