comparison mercurial/cext/revlog.c @ 40703:d5b300ec2e89

sparse-revlog: add a `index_get_start` function in C We are about to implement a native version of `slicechunktodensity`. For clarity, we introduce the helper functions first. This new function provides an efficient way to retrieve some of the information needed by `slicechunktodensity`.
author Boris Feld <boris.feld@octobus.net>
date Tue, 20 Nov 2018 14:49:18 +0000
parents fa33196088c4
children 7da3729d4b45
comparison
equal deleted inserted replaced
40702:4240a1da4188 40703:d5b300ec2e89
181 if (ps[0] > maxrev || ps[1] > maxrev) { 181 if (ps[0] > maxrev || ps[1] > maxrev) {
182 PyErr_SetString(PyExc_ValueError, "parent out of range"); 182 PyErr_SetString(PyExc_ValueError, "parent out of range");
183 return -1; 183 return -1;
184 } 184 }
185 return 0; 185 return 0;
186 }
187
188 static inline int64_t index_get_start(indexObject *self, Py_ssize_t rev)
189 {
190 uint64_t offset;
191 if (rev >= self->length) {
192 PyObject *tuple;
193 PyObject *pylong;
194 PY_LONG_LONG tmp;
195 tuple = PyList_GET_ITEM(self->added, rev - self->length);
196 pylong = PyTuple_GET_ITEM(tuple, 0);
197 tmp = PyLong_AsLongLong(pylong);
198 if (tmp == -1 && PyErr_Occurred()) {
199 return -1;
200 }
201 if (tmp < 0) {
202 PyErr_Format(PyExc_OverflowError,
203 "revlog entry size out of bound (%lld)",
204 (long long)tmp);
205 return -1;
206 }
207 offset = (uint64_t)tmp;
208 } else {
209 const char *data = index_deref(self, rev);
210 offset = getbe32(data + 4);
211 if (rev == 0) {
212 /* mask out version number for the first entry */
213 offset &= 0xFFFF;
214 } else {
215 uint32_t offset_high = getbe32(data);
216 offset |= ((uint64_t)offset_high) << 32;
217 }
218 }
219 return (int64_t)(offset >> 16);
186 } 220 }
187 221
188 /* 222 /*
189 * RevlogNG format (all in big endian, data may be inlined): 223 * RevlogNG format (all in big endian, data may be inlined):
190 * 6 bytes: offset 224 * 6 bytes: offset