D6292: revbranchcache: use context manager in _writerevs() to write to file

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Sun Apr 21 06:17:51 EDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGececa45c80d8: revbranchcache: use context manager in _writerevs() to write to file (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6292?vs=14872&id=14876

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

AFFECTED FILES
  mercurial/branchmap.py

CHANGE DETAILS

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -652,18 +652,15 @@
 
     def _writerevs(self, repo, start):
         """ write the new revs to revbranchcache """
-        revs = min(len(repo.changelog),
-                   len(self._rbcrevs) // _rbcrecsize)
-        f = repo.cachevfs.open(_rbcrevs, 'ab')
-        if f.tell() != start:
-            repo.ui.debug("truncating cache/%s to %d\n"
-                          % (_rbcrevs, start))
-            f.seek(start)
+        revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize)
+        with repo.cachevfs.open(_rbcrevs, 'ab') as f:
             if f.tell() != start:
-                start = 0
+                repo.ui.debug("truncating cache/%s to %d\n" % (_rbcrevs, start))
                 f.seek(start)
-            f.truncate()
-        end = revs * _rbcrecsize
-        f.write(self._rbcrevs[start:end])
-        f.close()
+                if f.tell() != start:
+                    start = 0
+                    f.seek(start)
+                f.truncate()
+            end = revs * _rbcrecsize
+            f.write(self._rbcrevs[start:end])
         self._rbcrevslen = revs



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


More information about the Mercurial-devel mailing list