##// END OF EJS Templates
index: don't include nullid in the internal "length" field...
Martin von Zweigbergk -
r39103:52e9bf21 default
parent child Browse files
Show More
@@ -84,8 +84,8 b' struct indexObjectStruct {'
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;
@@ -124,9 +124,8 b' static const char *index_deref(indexObje'
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 {
@@ -175,9 +174,9 b' static PyObject *index_get(indexObject *'
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 }
@@ -241,9 +240,9 b' static const char *index_node(indexObjec'
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 }
@@ -338,7 +337,7 b' static PyObject *index_stats(indexObject'
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");
@@ -802,9 +801,8 b' static inline int index_baserev(indexObj'
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 {
@@ -1827,11 +1825,11 b' static int index_slice_del(indexObject *'
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;
@@ -1843,7 +1841,7 b' static int index_slice_del(indexObject *'
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;
@@ -1856,12 +1854,12 b' static int index_slice_del(indexObject *'
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);
@@ -1974,14 +1972,14 b' static int index_init(indexObject *self,'
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;
General Comments 0
You need to be logged in to leave comments. Login now