revlog: use context manager for data file lifetime in checksize
authorBoris Feld <boris.feld@octobus.net>
Mon, 05 Feb 2018 17:35:14 +0100
changeset 35972 82afb1a5ed94
parent 35971 0f2c51afafb2
child 35973 4d66993bdcff
revlog: use context manager for data file lifetime in checksize This is clearer, safer and more modern.
mercurial/revlog.py
--- a/mercurial/revlog.py	Mon Feb 05 17:34:57 2018 +0100
+++ b/mercurial/revlog.py	Mon Feb 05 17:35:14 2018 +0100
@@ -2335,10 +2335,9 @@
             expected = max(0, self.end(len(self) - 1))
 
         try:
-            f = self._datafp()
-            f.seek(0, 2)
-            actual = f.tell()
-            f.close()
+            with self._datafp() as f:
+                f.seek(0, 2)
+                actual = f.tell()
             dd = actual - expected
         except IOError as inst:
             if inst.errno != errno.ENOENT: