Patchwork D7669: ui: use a context manager to handle file streams in edit()

login
register
mail settings
Submitter phabricator
Date Dec. 16, 2019, 6:30 a.m.
Message ID <2575ec42dcbb17f3bf2abb277e076568@localhost.localdomain>
Download mbox | patch
Permalink /patch/43853/
State Not Applicable
Headers show

Comments

phabricator - Dec. 16, 2019, 6:30 a.m.
Closed by commit rHGe5f69e3bb3f6: ui: use a context manager to handle file streams in edit() (authored by mharbison72).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7669?vs=18733&id=18745

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7669/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7669

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1766,9 +1766,8 @@ 
             prefix=b'hg-' + extra[b'prefix'] + b'-', suffix=suffix, dir=rdir
         )
         try:
-            f = os.fdopen(fd, 'wb')
-            f.write(util.tonativeeol(text))
-            f.close()
+            with os.fdopen(fd, 'wb') as f:
+                f.write(util.tonativeeol(text))
 
             environ = {b'HGUSER': user}
             if b'transplant_source' in extra:
@@ -1794,9 +1793,8 @@ 
                 blockedtag=b'editor',
             )
 
-            f = open(name, 'rb')
-            t = util.fromnativeeol(f.read())
-            f.close()
+            with open(name, 'rb') as f:
+                t = util.fromnativeeol(f.read())
         finally:
             os.unlink(name)