Patchwork [11,of,13] revlog: use context manager for data file lifetime in checksize

login
register
mail settings
Submitter Boris Feld
Date Feb. 6, 2018, 1:21 p.m.
Message ID <9073bbc68cb1ccc5685c.1517923292@FB>
Download mbox | patch
Permalink /patch/27362/
State New
Headers show

Comments

Boris Feld - Feb. 6, 2018, 1:21 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1517848514 -3600
#      Mon Feb 05 17:35:14 2018 +0100
# Node ID 9073bbc68cb1ccc5685c78dbe837f31406324028
# Parent  1a212682563740e031380befc949167e73b476bd
# EXP-Topic revlog-fp
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 9073bbc68cb1
revlog: use context manager for data file lifetime in checksize

This is clearer, safer and more modern.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2335,10 +2335,9 @@  class revlog(object):
             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: