Patchwork [1,of,3] revlog: rename internal functions containing "chunk" to use "segment"

login
register
mail settings
Submitter Gregory Szorc
Date May 6, 2017, 7:19 p.m.
Message ID <837c542b1c13551524c6.1494098384@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/20491/
State Accepted
Headers show

Comments

Gregory Szorc - May 6, 2017, 7:19 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1494097332 25200
#      Sat May 06 12:02:12 2017 -0700
# Node ID 837c542b1c13551524c670ac9c33824aedca2457
# Parent  31f42e683321f225eb9c306f8d4b3a9e8d82a1da
revlog: rename internal functions containing "chunk" to use "segment"

Currently, "chunk" is overloaded in revlog terminology to mean
multiple things. One of them refers to a segment of raw data from
the revlog. This commit renames various methods only used within
revlog.py to have "segment" in their name instead of "chunk."

While I was here, I also made the names more descriptive. e.g.
"_loadchunk()" becomes "_readsegment()" because it actually does
I/O.
Gregory Szorc - May 6, 2017, 7:40 p.m.
On Sat, May 6, 2017 at 12:19 PM, Gregory Szorc <gregory.szorc@gmail.com>
wrote:

> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1494097332 25200
> #      Sat May 06 12:02:12 2017 -0700
> # Node ID 837c542b1c13551524c670ac9c33824aedca2457
> # Parent  31f42e683321f225eb9c306f8d4b3a9e8d82a1da
> revlog: rename internal functions containing "chunk" to use "segment"
>
> Currently, "chunk" is overloaded in revlog terminology to mean
> multiple things. One of them refers to a segment of raw data from
> the revlog. This commit renames various methods only used within
> revlog.py to have "segment" in their name instead of "chunk."
>
> While I was here, I also made the names more descriptive. e.g.
> "_loadchunk()" becomes "_readsegment()" because it actually does
> I/O.
>

In case anyone is wondering, I didn't touch revlog._chunkcache and
revlog._chunkcachesize in this series because I am considering drastic
changes to it and didn't want to cause code churn before doing something
potentially radical (like deleting it). Depending on what I do, I may send
another patch so their names agree with this series.


>
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -1075,7 +1075,7 @@ class revlog(object):
>          p1, p2 = self.parents(node)
>          return hash(text, p1, p2) != node
>
> -    def _addchunk(self, offset, data):
> +    def _cachesegment(self, offset, data):
>          """Add a segment to the revlog cache.
>
>          Accepts an absolute offset and the data that is at that location.
> @@ -1087,7 +1087,7 @@ class revlog(object):
>          else:
>              self._chunkcache = offset, data
>
> -    def _loadchunk(self, offset, length, df=None):
> +    def _readsegment(self, offset, length, df=None):
>          """Load a segment of raw data from the revlog.
>
>          Accepts an absolute offset, length to read, and an optional
> existing
> @@ -1118,12 +1118,12 @@ class revlog(object):
>          d = df.read(reallength)
>          if closehandle:
>              df.close()
> -        self._addchunk(realoffset, d)
> +        self._cachesegment(realoffset, d)
>          if offset != realoffset or reallength != length:
>              return util.buffer(d, offset - realoffset, length)
>          return d
>
> -    def _getchunk(self, offset, length, df=None):
> +    def _getsegment(self, offset, length, df=None):
>          """Obtain a segment of raw data from the revlog.
>
>          Accepts an absolute offset, length of bytes to obtain, and an
> @@ -1145,7 +1145,7 @@ class revlog(object):
>                  return d # avoid a copy
>              return util.buffer(d, cachestart, cacheend - cachestart)
>
> -        return self._loadchunk(offset, length, df=df)
> +        return self._readsegment(offset, length, df=df)
>
>      def _chunkraw(self, startrev, endrev, df=None):
>          """Obtain a segment of raw data corresponding to a range of
> revisions.
> @@ -1179,7 +1179,7 @@ class revlog(object):
>              end += (endrev + 1) * self._io.size
>          length = end - start
>
> -        return start, self._getchunk(start, length, df=df)
> +        return start, self._getsegment(start, length, df=df)
>
>      def _chunk(self, rev, df=None):
>          """Obtain a single decompressed chunk for a revision.
>

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1075,7 +1075,7 @@  class revlog(object):
         p1, p2 = self.parents(node)
         return hash(text, p1, p2) != node
 
-    def _addchunk(self, offset, data):
+    def _cachesegment(self, offset, data):
         """Add a segment to the revlog cache.
 
         Accepts an absolute offset and the data that is at that location.
@@ -1087,7 +1087,7 @@  class revlog(object):
         else:
             self._chunkcache = offset, data
 
-    def _loadchunk(self, offset, length, df=None):
+    def _readsegment(self, offset, length, df=None):
         """Load a segment of raw data from the revlog.
 
         Accepts an absolute offset, length to read, and an optional existing
@@ -1118,12 +1118,12 @@  class revlog(object):
         d = df.read(reallength)
         if closehandle:
             df.close()
-        self._addchunk(realoffset, d)
+        self._cachesegment(realoffset, d)
         if offset != realoffset or reallength != length:
             return util.buffer(d, offset - realoffset, length)
         return d
 
-    def _getchunk(self, offset, length, df=None):
+    def _getsegment(self, offset, length, df=None):
         """Obtain a segment of raw data from the revlog.
 
         Accepts an absolute offset, length of bytes to obtain, and an
@@ -1145,7 +1145,7 @@  class revlog(object):
                 return d # avoid a copy
             return util.buffer(d, cachestart, cacheend - cachestart)
 
-        return self._loadchunk(offset, length, df=df)
+        return self._readsegment(offset, length, df=df)
 
     def _chunkraw(self, startrev, endrev, df=None):
         """Obtain a segment of raw data corresponding to a range of revisions.
@@ -1179,7 +1179,7 @@  class revlog(object):
             end += (endrev + 1) * self._io.size
         length = end - start
 
-        return start, self._getchunk(start, length, df=df)
+        return start, self._getsegment(start, length, df=df)
 
     def _chunk(self, rev, df=None):
         """Obtain a single decompressed chunk for a revision.