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

login
register
mail settings
Submitter Boris Feld
Date Feb. 6, 2018, 1:21 p.m.
Message ID <c4015bae897ca99b1293.1517923290@FB>
Download mbox | patch
Permalink /patch/27360/
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 1517848487 -3600
#      Mon Feb 05 17:34:47 2018 +0100
# Node ID c4015bae897ca99b12933bf74a176fa6a349681b
# Parent  da0b895c385747d820294509d102d633419f8036
# EXP-Topic revlog-fp
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c4015bae897c
revlog: use context manager for data file lifetime in checkinlinesize

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
@@ -1859,12 +1859,9 @@  class revlog(object):
             fp.flush()
             fp.close()
 
-        df = self._datafp('w')
-        try:
+        with self._datafp('w') as df:
             for r in self:
                 df.write(self._getsegmentforrevs(r, r)[1])
-        finally:
-            df.close()
 
         fp = self._indexfp('w')
         self.version &= ~FLAG_INLINE_DATA