[PATCH 01 of 10] largefiles: use a context manager in _getfile

Bryan O'Sullivan bos at serpentine.com
Tue Jan 12 22:50:04 UTC 2016


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1452637662 28800
#      Tue Jan 12 14:27:42 2016 -0800
# Node ID 6919e06dd7cdb16638aa013653a34a951ea2cd4f
# Parent  edd2615ad226c14f6904fc1738c3dc36431db223
largefiles: use a context manager in _getfile

diff --git a/hgext/largefiles/localstore.py b/hgext/largefiles/localstore.py
--- a/hgext/largefiles/localstore.py
+++ b/hgext/largefiles/localstore.py
@@ -39,11 +39,8 @@ class localstore(basestore.basestore):
         if not path:
             raise basestore.StoreError(filename, hash, self.url,
                 _("can't get file locally"))
-        fd = open(path, 'rb')
-        try:
+        with open(path, 'rb') as fd:
             return lfutil.copyandhash(fd, tmpfile)
-        finally:
-            fd.close()
 
     def _verifyfile(self, cctx, cset, contents, standin, verified):
         filename = lfutil.splitstandin(standin)


More information about the Mercurial-devel mailing list