From patchwork Tue Dec 17 12:56:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D7626: config: close file even if we fail to read it From: phabricator X-Patchwork-Id: 43917 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Tue, 17 Dec 2019 12:56:22 +0000 Closed by commit rHGc41ed5d4f770: config: close file even if we fail to read it (authored by martinvonz). This revision was automatically updated to reflect the committed changes. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7626?vs=18778&id=18805 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 To: martinvonz, #hg-reviewers, pulkit Cc: mercurial-devel 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 (