changeset 36006:61326dd7cb8d

revlog: move datafile opening in a method Having file operation centralized into a single spot help to factor common logic out. It is also the first step to simplify file handling during batch operation (eg: revlog cloning). However, that part does not seems to be a hotspot yet.
author Boris Feld <boris.feld@octobus.net>
date Mon, 05 Feb 2018 17:03:56 +0100
parents 8140ce44dec4
children 91b3b11565e5
files mercurial/revlog.py
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Tue Feb 06 12:25:11 2018 +0100
+++ b/mercurial/revlog.py	Mon Feb 05 17:03:56 2018 +0100
@@ -682,6 +682,10 @@
     def _compressor(self):
         return util.compengines[self._compengine].revlogcompressor()
 
+    def _datafp(self, mode='r'):
+        """file object for the revlog's data file"""
+        return self.opener(self.datafile, mode=mode)
+
     def tip(self):
         return self.node(len(self.index) - 2)
     def __contains__(self, rev):
@@ -1496,7 +1500,7 @@
             if self._inline:
                 df = self.opener(self.indexfile)
             else:
-                df = self.opener(self.datafile)
+                df = self._datafp()
             closehandle = True
 
         # Cache data both forward and backward around the requested
@@ -1847,7 +1851,7 @@
             fp.flush()
             fp.close()
 
-        df = self.opener(self.datafile, 'w')
+        df = self._datafp('w')
         try:
             for r in self:
                 df.write(self._getsegmentforrevs(r, r)[1])
@@ -1923,7 +1927,7 @@
         """
         dfh = None
         if not self._inline:
-            dfh = self.opener(self.datafile, "a+")
+            dfh = self._datafp("a+")
         ifh = self.opener(self.indexfile, "a+", checkambig=self._checkambig)
         try:
             return self._addrevision(node, rawtext, transaction, link, p1, p2,
@@ -2161,7 +2165,7 @@
         else:
             transaction.add(self.indexfile, isize, r)
             transaction.add(self.datafile, end)
-            dfh = self.opener(self.datafile, "a+")
+            dfh = self._datafp("a+")
         def flush():
             if dfh:
                 dfh.flush()
@@ -2224,7 +2228,7 @@
                     # addrevision switched from inline to conventional
                     # reopen the index
                     ifh.close()
-                    dfh = self.opener(self.datafile, "a+")
+                    dfh = self._datafp("a+")
                     ifh = self.opener(self.indexfile, "a+",
                                       checkambig=self._checkambig)
         finally:
@@ -2328,7 +2332,7 @@
             expected = max(0, self.end(len(self) - 1))
 
         try:
-            f = self.opener(self.datafile)
+            f = self._datafp()
             f.seek(0, 2)
             actual = f.tell()
             f.close()