comparison mercurial/revlog.py @ 32227:1395f843ece4

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 06 May 2017 12:02:12 -0700
parents 0ab7f469d386
children 75e93d95aae6
comparison
equal deleted inserted replaced
32226:bf3af0eced44 32227:1395f843ece4
1073 returns True if text is different than what is stored. 1073 returns True if text is different than what is stored.
1074 """ 1074 """
1075 p1, p2 = self.parents(node) 1075 p1, p2 = self.parents(node)
1076 return hash(text, p1, p2) != node 1076 return hash(text, p1, p2) != node
1077 1077
1078 def _addchunk(self, offset, data): 1078 def _cachesegment(self, offset, data):
1079 """Add a segment to the revlog cache. 1079 """Add a segment to the revlog cache.
1080 1080
1081 Accepts an absolute offset and the data that is at that location. 1081 Accepts an absolute offset and the data that is at that location.
1082 """ 1082 """
1083 o, d = self._chunkcache 1083 o, d = self._chunkcache
1085 if o + len(d) == offset and len(d) + len(data) < _chunksize: 1085 if o + len(d) == offset and len(d) + len(data) < _chunksize:
1086 self._chunkcache = o, d + data 1086 self._chunkcache = o, d + data
1087 else: 1087 else:
1088 self._chunkcache = offset, data 1088 self._chunkcache = offset, data
1089 1089
1090 def _loadchunk(self, offset, length, df=None): 1090 def _readsegment(self, offset, length, df=None):
1091 """Load a segment of raw data from the revlog. 1091 """Load a segment of raw data from the revlog.
1092 1092
1093 Accepts an absolute offset, length to read, and an optional existing 1093 Accepts an absolute offset, length to read, and an optional existing
1094 file handle to read from. 1094 file handle to read from.
1095 1095
1116 - realoffset) 1116 - realoffset)
1117 df.seek(realoffset) 1117 df.seek(realoffset)
1118 d = df.read(reallength) 1118 d = df.read(reallength)
1119 if closehandle: 1119 if closehandle:
1120 df.close() 1120 df.close()
1121 self._addchunk(realoffset, d) 1121 self._cachesegment(realoffset, d)
1122 if offset != realoffset or reallength != length: 1122 if offset != realoffset or reallength != length:
1123 return util.buffer(d, offset - realoffset, length) 1123 return util.buffer(d, offset - realoffset, length)
1124 return d 1124 return d
1125 1125
1126 def _getchunk(self, offset, length, df=None): 1126 def _getsegment(self, offset, length, df=None):
1127 """Obtain a segment of raw data from the revlog. 1127 """Obtain a segment of raw data from the revlog.
1128 1128
1129 Accepts an absolute offset, length of bytes to obtain, and an 1129 Accepts an absolute offset, length of bytes to obtain, and an
1130 optional file handle to the already-opened revlog. If the file 1130 optional file handle to the already-opened revlog. If the file
1131 handle is used, it's original seek position will not be preserved. 1131 handle is used, it's original seek position will not be preserved.
1143 if cachestart >= 0 and cacheend <= l: 1143 if cachestart >= 0 and cacheend <= l:
1144 if cachestart == 0 and cacheend == l: 1144 if cachestart == 0 and cacheend == l:
1145 return d # avoid a copy 1145 return d # avoid a copy
1146 return util.buffer(d, cachestart, cacheend - cachestart) 1146 return util.buffer(d, cachestart, cacheend - cachestart)
1147 1147
1148 return self._loadchunk(offset, length, df=df) 1148 return self._readsegment(offset, length, df=df)
1149 1149
1150 def _chunkraw(self, startrev, endrev, df=None): 1150 def _chunkraw(self, startrev, endrev, df=None):
1151 """Obtain a segment of raw data corresponding to a range of revisions. 1151 """Obtain a segment of raw data corresponding to a range of revisions.
1152 1152
1153 Accepts the start and end revisions and an optional already-open 1153 Accepts the start and end revisions and an optional already-open
1177 if self._inline: 1177 if self._inline:
1178 start += (startrev + 1) * self._io.size 1178 start += (startrev + 1) * self._io.size
1179 end += (endrev + 1) * self._io.size 1179 end += (endrev + 1) * self._io.size
1180 length = end - start 1180 length = end - start
1181 1181
1182 return start, self._getchunk(start, length, df=df) 1182 return start, self._getsegment(start, length, df=df)
1183 1183
1184 def _chunk(self, rev, df=None): 1184 def _chunk(self, rev, df=None):
1185 """Obtain a single decompressed chunk for a revision. 1185 """Obtain a single decompressed chunk for a revision.
1186 1186
1187 Accepts an integer revision and an optional already-open file handle 1187 Accepts an integer revision and an optional already-open file handle