##// END OF EJS Templates
revlog: have an explicit "pack_header" method...
marmoute -
r47811:d57386e5 default
parent child Browse files
Show More
@@ -343,18 +343,28 b' static PyObject *index_get(indexObject *'
343 343 }
344 344 }
345 345 /*
346 * Pack header information in binary
347 */
348 static PyObject *index_pack_header(indexObject *self, PyObject *args)
349 {
350 int header;
351 char out[4];
352 if (!PyArg_ParseTuple(args, "I", &header)) {
353 return NULL;
354 }
355 putbe32(header, out);
356 return PyBytes_FromStringAndSize(out, 4);
357 }
358 /*
346 359 * Return the raw binary string representing a revision
347 360 */
348 static PyObject *index_entry_binary(indexObject *self, PyObject *args)
361 static PyObject *index_entry_binary(indexObject *self, PyObject *value)
349 362 {
350 363 long rev;
351 int header;
352 364 const char *data;
353 char entry[v2_hdrsize];
354
355 365 Py_ssize_t length = index_length(self);
356 366
357 if (!PyArg_ParseTuple(args, "lI", &rev, &header)) {
367 if (!pylong_to_long(value, &rev)) {
358 368 return NULL;
359 369 }
360 370 if (rev < 0 || rev >= length) {
@@ -367,10 +377,8 b' static PyObject *index_entry_binary(inde'
367 377 if (data == NULL)
368 378 return NULL;
369 379 if (rev == 0) {
370 /* put the header at the start of the first entry */
371 memcpy(entry, data, self->hdrsize);
372 putbe32(header, entry);
373 return PyBytes_FromStringAndSize(entry, self->hdrsize);
380 /* the header is eating the start of the first entry */
381 return PyBytes_FromStringAndSize(data + 4, self->hdrsize - 4);
374 382 }
375 383 return PyBytes_FromStringAndSize(data, self->hdrsize);
376 384 }
@@ -2891,8 +2899,10 b' static PyMethodDef index_methods[] = {'
2891 2899 {"shortest", (PyCFunction)index_shortest, METH_VARARGS,
2892 2900 "find length of shortest hex nodeid of a binary ID"},
2893 2901 {"stats", (PyCFunction)index_stats, METH_NOARGS, "stats for the index"},
2894 {"entry_binary", (PyCFunction)index_entry_binary, METH_VARARGS,
2902 {"entry_binary", (PyCFunction)index_entry_binary, METH_O,
2895 2903 "return an entry in binary form"},
2904 {"pack_header", (PyCFunction)index_pack_header, METH_VARARGS,
2905 "pack the revlog header information into binary"},
2896 2906 {NULL} /* Sentinel */
2897 2907 };
2898 2908
@@ -127,14 +127,17 b' class BaseIndexObject(object):'
127 127 r = (offset_type(0, gettype(r[0])),) + r[1:]
128 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 136 """return the raw binary string representing a revision"""
132 137 entry = self[rev]
133 138 p = revlog_constants.INDEX_ENTRY_V1.pack(*entry)
134 139 if rev == 0:
135 v_fmt = revlog_constants.INDEX_HEADER
136 v_bin = v_fmt.pack(header)
137 p = v_bin + p[v_fmt.size :]
140 p = p[revlog_constants.INDEX_HEADER.size :]
138 141 return p
139 142
140 143
@@ -286,14 +289,12 b' class Index2Mixin(object):'
286 289 msg = b"cannot rewrite entries outside of this transaction"
287 290 raise KeyError(msg)
288 291
289 def entry_binary(self, rev, header):
292 def entry_binary(self, rev):
290 293 """return the raw binary string representing a revision"""
291 294 entry = self[rev]
292 295 p = revlog_constants.INDEX_ENTRY_V2.pack(*entry)
293 296 if rev == 0:
294 v_fmt = revlog_constants.INDEX_HEADER
295 v_bin = v_fmt.pack(header)
296 p = v_bin + p[v_fmt.size :]
297 p = p[revlog_constants.INDEX_HEADER.size :]
297 298 return p
298 299
299 300
@@ -266,7 +266,7 b' class revlogoldindex(list):'
266 266 return (0, 0, 0, -1, -1, -1, -1, sha1nodeconstants.nullid)
267 267 return list.__getitem__(self, i)
268 268
269 def entry_binary(self, rev, header):
269 def entry_binary(self, rev):
270 270 """return the raw binary string representing a revision"""
271 271 entry = self[rev]
272 272 if gettype(entry[0]):
@@ -284,6 +284,10 b' class revlogoldindex(list):'
284 284 )
285 285 return INDEX_ENTRY_V0.pack(*e2)
286 286
287 def pack_header(self, header):
288 """Pack header information in binary"""
289 return b''
290
287 291
288 292 def parse_index_v0(data, inline):
289 293 s = INDEX_ENTRY_V0.size
@@ -2041,7 +2045,10 b' class revlog(object):'
2041 2045 self.version &= ~FLAG_INLINE_DATA
2042 2046 self._inline = False
2043 2047 for i in self:
2044 e = self.index.entry_binary(i, self.version)
2048 e = self.index.entry_binary(i)
2049 if i == 0:
2050 header = self.index.pack_header(self.version)
2051 e = header + e
2045 2052 fp.write(e)
2046 2053
2047 2054 # the temp file replace the real index when we exit the context
@@ -2363,7 +2370,10 b' class revlog(object):'
2363 2370 e = e[:8]
2364 2371
2365 2372 self.index.append(e)
2366 entry = self.index.entry_binary(curr, self.version)
2373 entry = self.index.entry_binary(curr)
2374 if curr == 0:
2375 header = self.index.pack_header(self.version)
2376 entry = header + entry
2367 2377 self._writeentry(
2368 2378 transaction,
2369 2379 ifh,
@@ -3216,5 +3226,8 b' class revlog(object):'
3216 3226 for i, entry in enumerate(new_entries):
3217 3227 rev = startrev + i
3218 3228 self.index.replace_sidedata_info(rev, entry[8], entry[9])
3219 packed = self.index.entry_binary(rev, self.version)
3229 packed = self.index.entry_binary(rev)
3230 if rev == 0:
3231 header = self.index.pack_header(self.version)
3232 packed = header + packed
3220 3233 fp.write(packed)
@@ -177,6 +177,11 b' py_class!(pub class MixedIndex |py| {'
177 177 self.call_cindex(py, "entry_binary", args, kw)
178 178 }
179 179
180 /// return a binary packed version of the header
181 def pack_header(&self, *args, **kw) -> PyResult<PyObject> {
182 self.call_cindex(py, "pack_header", args, kw)
183 }
184
180 185 /// get an index entry
181 186 def get(&self, *args, **kw) -> PyResult<PyObject> {
182 187 self.call_cindex(py, "get", args, kw)
General Comments 0
You need to be logged in to leave comments. Login now