Mercurial > hg
comparison mercurial/cext/revlog.c @ 39068:52e9bf215f96
index: don't include nullid in the internal "length" field
This is a follow-up to 781b2720d2ac (index: don't include nullid in
len(), 2018-07-20). I intentionally didn't update the "index stats",
so it will also not include the space for nullid after this patch.
Differential Revision: https://phab.mercurial-scm.org/D4162
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 08 Aug 2018 21:52:39 -0700 |
parents | c1de67691d5b |
children | 4c4825db29e1 |
comparison
equal
deleted
inserted
replaced
39067:daedb70fd467 | 39068:52e9bf215f96 |
---|---|
82 }; | 82 }; |
83 | 83 |
84 static Py_ssize_t index_length(const indexObject *self) | 84 static Py_ssize_t index_length(const indexObject *self) |
85 { | 85 { |
86 if (self->added == NULL) | 86 if (self->added == NULL) |
87 return self->length - 1; | 87 return self->length; |
88 return self->length + PyList_GET_SIZE(self->added) - 1; | 88 return self->length + PyList_GET_SIZE(self->added); |
89 } | 89 } |
90 | 90 |
91 static PyObject *nullentry; | 91 static PyObject *nullentry; |
92 static const char nullid[20]; | 92 static const char nullid[20]; |
93 | 93 |
122 } | 122 } |
123 | 123 |
124 static inline int index_get_parents(indexObject *self, Py_ssize_t rev, | 124 static inline int index_get_parents(indexObject *self, Py_ssize_t rev, |
125 int *ps, int maxrev) | 125 int *ps, int maxrev) |
126 { | 126 { |
127 if (rev >= self->length - 1) { | 127 if (rev >= self->length) { |
128 PyObject *tuple = PyList_GET_ITEM(self->added, | 128 PyObject *tuple = PyList_GET_ITEM(self->added, rev - self->length); |
129 rev - self->length + 1); | |
130 ps[0] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 5)); | 129 ps[0] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 5)); |
131 ps[1] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 6)); | 130 ps[1] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 6)); |
132 } else { | 131 } else { |
133 const char *data = index_deref(self, rev); | 132 const char *data = index_deref(self, rev); |
134 ps[0] = getbe32(data + 24); | 133 ps[0] = getbe32(data + 24); |
173 if (pos < 0 || pos >= length) { | 172 if (pos < 0 || pos >= length) { |
174 PyErr_SetString(PyExc_IndexError, "revlog index out of range"); | 173 PyErr_SetString(PyExc_IndexError, "revlog index out of range"); |
175 return NULL; | 174 return NULL; |
176 } | 175 } |
177 | 176 |
178 if (pos >= self->length - 1) { | 177 if (pos >= self->length) { |
179 PyObject *obj; | 178 PyObject *obj; |
180 obj = PyList_GET_ITEM(self->added, pos - self->length + 1); | 179 obj = PyList_GET_ITEM(self->added, pos - self->length); |
181 Py_INCREF(obj); | 180 Py_INCREF(obj); |
182 return obj; | 181 return obj; |
183 } | 182 } |
184 | 183 |
185 if (self->cache) { | 184 if (self->cache) { |
239 return nullid; | 238 return nullid; |
240 | 239 |
241 if (pos >= length) | 240 if (pos >= length) |
242 return NULL; | 241 return NULL; |
243 | 242 |
244 if (pos >= self->length - 1) { | 243 if (pos >= self->length) { |
245 PyObject *tuple, *str; | 244 PyObject *tuple, *str; |
246 tuple = PyList_GET_ITEM(self->added, pos - self->length + 1); | 245 tuple = PyList_GET_ITEM(self->added, pos - self->length); |
247 str = PyTuple_GetItem(tuple, 7); | 246 str = PyTuple_GetItem(tuple, 7); |
248 return str ? PyBytes_AS_STRING(str) : NULL; | 247 return str ? PyBytes_AS_STRING(str) : NULL; |
249 } | 248 } |
250 | 249 |
251 data = index_deref(self, pos); | 250 data = index_deref(self, pos); |
336 if (PyDict_SetItemString(obj, "index entries added", t) == -1) | 335 if (PyDict_SetItemString(obj, "index entries added", t) == -1) |
337 goto bail; | 336 goto bail; |
338 Py_DECREF(t); | 337 Py_DECREF(t); |
339 } | 338 } |
340 | 339 |
341 if (self->raw_length != self->length - 1) | 340 if (self->raw_length != self->length) |
342 istat(raw_length, "revs on disk"); | 341 istat(raw_length, "revs on disk"); |
343 istat(length, "revs in memory"); | 342 istat(length, "revs in memory"); |
344 istat(ntlookups, "node trie lookups"); | 343 istat(ntlookups, "node trie lookups"); |
345 istat(ntmisses, "node trie misses"); | 344 istat(ntmisses, "node trie misses"); |
346 istat(ntrev, "node trie last rev scanned"); | 345 istat(ntrev, "node trie last rev scanned"); |
800 */ | 799 */ |
801 static inline int index_baserev(indexObject *self, int rev) | 800 static inline int index_baserev(indexObject *self, int rev) |
802 { | 801 { |
803 const char *data; | 802 const char *data; |
804 | 803 |
805 if (rev >= self->length - 1) { | 804 if (rev >= self->length) { |
806 PyObject *tuple = PyList_GET_ITEM(self->added, | 805 PyObject *tuple = PyList_GET_ITEM(self->added, rev - self->length); |
807 rev - self->length + 1); | |
808 return (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 3)); | 806 return (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 3)); |
809 } | 807 } |
810 else { | 808 else { |
811 data = index_deref(self, rev); | 809 data = index_deref(self, rev); |
812 if (data == NULL) { | 810 if (data == NULL) { |
1825 PyErr_SetString(PyExc_IndexError, | 1823 PyErr_SetString(PyExc_IndexError, |
1826 "revlog index deletion indices are invalid"); | 1824 "revlog index deletion indices are invalid"); |
1827 return -1; | 1825 return -1; |
1828 } | 1826 } |
1829 | 1827 |
1830 if (start < self->length - 1) { | 1828 if (start < self->length) { |
1831 if (self->nt) { | 1829 if (self->nt) { |
1832 Py_ssize_t i; | 1830 Py_ssize_t i; |
1833 | 1831 |
1834 for (i = start + 1; i < self->length - 1; i++) { | 1832 for (i = start + 1; i < self->length; i++) { |
1835 const char *node = index_node_existing(self, i); | 1833 const char *node = index_node_existing(self, i); |
1836 if (node == NULL) | 1834 if (node == NULL) |
1837 return -1; | 1835 return -1; |
1838 | 1836 |
1839 nt_delete_node(self->nt, node); | 1837 nt_delete_node(self->nt, node); |
1841 if (self->added) | 1839 if (self->added) |
1842 index_invalidate_added(self, 0); | 1840 index_invalidate_added(self, 0); |
1843 if (self->ntrev > start) | 1841 if (self->ntrev > start) |
1844 self->ntrev = (int)start; | 1842 self->ntrev = (int)start; |
1845 } | 1843 } |
1846 self->length = start + 1; | 1844 self->length = start; |
1847 if (start < self->raw_length) { | 1845 if (start < self->raw_length) { |
1848 if (self->cache) { | 1846 if (self->cache) { |
1849 Py_ssize_t i; | 1847 Py_ssize_t i; |
1850 for (i = start; i < self->raw_length; i++) | 1848 for (i = start; i < self->raw_length; i++) |
1851 Py_CLEAR(self->cache[i]); | 1849 Py_CLEAR(self->cache[i]); |
1854 } | 1852 } |
1855 goto done; | 1853 goto done; |
1856 } | 1854 } |
1857 | 1855 |
1858 if (self->nt) { | 1856 if (self->nt) { |
1859 index_invalidate_added(self, start - self->length + 1); | 1857 index_invalidate_added(self, start - self->length); |
1860 if (self->ntrev > start) | 1858 if (self->ntrev > start) |
1861 self->ntrev = (int)start; | 1859 self->ntrev = (int)start; |
1862 } | 1860 } |
1863 if (self->added) | 1861 if (self->added) |
1864 ret = PyList_SetSlice(self->added, start - self->length + 1, | 1862 ret = PyList_SetSlice(self->added, start - self->length, |
1865 PyList_GET_SIZE(self->added), NULL); | 1863 PyList_GET_SIZE(self->added), NULL); |
1866 done: | 1864 done: |
1867 Py_CLEAR(self->headrevs); | 1865 Py_CLEAR(self->headrevs); |
1868 return ret; | 1866 return ret; |
1869 } | 1867 } |
1972 if (self->inlined) { | 1970 if (self->inlined) { |
1973 Py_ssize_t len = inline_scan(self, NULL); | 1971 Py_ssize_t len = inline_scan(self, NULL); |
1974 if (len == -1) | 1972 if (len == -1) |
1975 goto bail; | 1973 goto bail; |
1976 self->raw_length = len; | 1974 self->raw_length = len; |
1977 self->length = len + 1; | 1975 self->length = len; |
1978 } else { | 1976 } else { |
1979 if (size % v1_hdrsize) { | 1977 if (size % v1_hdrsize) { |
1980 PyErr_SetString(PyExc_ValueError, "corrupt index file"); | 1978 PyErr_SetString(PyExc_ValueError, "corrupt index file"); |
1981 goto bail; | 1979 goto bail; |
1982 } | 1980 } |
1983 self->raw_length = size / v1_hdrsize; | 1981 self->raw_length = size / v1_hdrsize; |
1984 self->length = self->raw_length + 1; | 1982 self->length = self->raw_length; |
1985 } | 1983 } |
1986 | 1984 |
1987 return 0; | 1985 return 0; |
1988 bail: | 1986 bail: |
1989 return -1; | 1987 return -1; |