Mercurial > hg
comparison mercurial/pure/parsers.py @ 47037:d57386e5c80e
revlog: have an explicit "pack_header" method
Having to pass the version header when retrieving the binary version of every
single entry is a bit silly. So we extract that special logic in its own method.
This also prepare the move to newer revlog format, not storing the header within
an actual entry…
Differential Revision: https://phab.mercurial-scm.org/D10510
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 01 Apr 2021 11:31:54 +0200 |
parents | 0d8ff1f4ab0c |
children | 223b47235d1c |
comparison
equal
deleted
inserted
replaced
47036:5e64c93d5f94 | 47037:d57386e5c80e |
---|---|
125 r = self.index_format.unpack(data) | 125 r = self.index_format.unpack(data) |
126 if self._lgt and i == 0: | 126 if self._lgt and i == 0: |
127 r = (offset_type(0, gettype(r[0])),) + r[1:] | 127 r = (offset_type(0, gettype(r[0])),) + r[1:] |
128 return r | 128 return r |
129 | 129 |
130 def entry_binary(self, rev, header): | 130 def pack_header(self, header): |
131 """pack header information as binary""" | |
132 v_fmt = revlog_constants.INDEX_HEADER | |
133 return v_fmt.pack(header) | |
134 | |
135 def entry_binary(self, rev): | |
131 """return the raw binary string representing a revision""" | 136 """return the raw binary string representing a revision""" |
132 entry = self[rev] | 137 entry = self[rev] |
133 p = revlog_constants.INDEX_ENTRY_V1.pack(*entry) | 138 p = revlog_constants.INDEX_ENTRY_V1.pack(*entry) |
134 if rev == 0: | 139 if rev == 0: |
135 v_fmt = revlog_constants.INDEX_HEADER | 140 p = p[revlog_constants.INDEX_HEADER.size :] |
136 v_bin = v_fmt.pack(header) | |
137 p = v_bin + p[v_fmt.size :] | |
138 return p | 141 return p |
139 | 142 |
140 | 143 |
141 class IndexObject(BaseIndexObject): | 144 class IndexObject(BaseIndexObject): |
142 def __init__(self, data): | 145 def __init__(self, data): |
284 self._extra[i - self._lgt] = new | 287 self._extra[i - self._lgt] = new |
285 else: | 288 else: |
286 msg = b"cannot rewrite entries outside of this transaction" | 289 msg = b"cannot rewrite entries outside of this transaction" |
287 raise KeyError(msg) | 290 raise KeyError(msg) |
288 | 291 |
289 def entry_binary(self, rev, header): | 292 def entry_binary(self, rev): |
290 """return the raw binary string representing a revision""" | 293 """return the raw binary string representing a revision""" |
291 entry = self[rev] | 294 entry = self[rev] |
292 p = revlog_constants.INDEX_ENTRY_V2.pack(*entry) | 295 p = revlog_constants.INDEX_ENTRY_V2.pack(*entry) |
293 if rev == 0: | 296 if rev == 0: |
294 v_fmt = revlog_constants.INDEX_HEADER | 297 p = p[revlog_constants.INDEX_HEADER.size :] |
295 v_bin = v_fmt.pack(header) | |
296 p = v_bin + p[v_fmt.size :] | |
297 return p | 298 return p |
298 | 299 |
299 | 300 |
300 class IndexObject2(Index2Mixin, IndexObject): | 301 class IndexObject2(Index2Mixin, IndexObject): |
301 pass | 302 pass |