comparison mercurial/cext/revlog.c @ 38847:f3d394ea17db

index: handle index[-1] as nullid more explicitly I find it more intuitive to check if "pos == -1" than to first add the index length (which includes one extra item for the nullid) and compare that to "length - 1". However, because test-parseindex2.py compares the whole index (up to len(index)-1), we need to also preserve that other check for a little while more. I'll remove it soon. Differential Revision: https://phab.mercurial-scm.org/D4018
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 20 Jul 2018 09:53:54 -0700
parents f738c502e43b
children c0d411ea6639
comparison
equal deleted inserted replaced
38846:f738c502e43b 38847:f3d394ea17db
156 const char *c_node_id; 156 const char *c_node_id;
157 const char *data; 157 const char *data;
158 Py_ssize_t length = index_length(self); 158 Py_ssize_t length = index_length(self);
159 PyObject *entry; 159 PyObject *entry;
160 160
161 if (pos == -1 || pos == length - 1) {
162 Py_INCREF(nullentry);
163 return nullentry;
164 }
165
161 if (pos < 0) 166 if (pos < 0)
162 pos += length; 167 pos += length;
163 168
164 if (pos < 0 || pos >= length) { 169 if (pos < 0 || pos >= length) {
165 PyErr_SetString(PyExc_IndexError, "revlog index out of range"); 170 PyErr_SetString(PyExc_IndexError, "revlog index out of range");
166 return NULL; 171 return NULL;
167 }
168
169 if (pos == length - 1) {
170 Py_INCREF(nullentry);
171 return nullentry;
172 } 172 }
173 173
174 if (pos >= self->length - 1) { 174 if (pos >= self->length - 1) {
175 PyObject *obj; 175 PyObject *obj;
176 obj = PyList_GET_ITEM(self->added, pos - self->length + 1); 176 obj = PyList_GET_ITEM(self->added, pos - self->length + 1);