index: don't allow index[len(index)] to mean nullid
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 20 Jul 2018 14:36:42 -0700
changeset 38852 a3dacabd476b
parent 38851 781b2720d2ac
child 38853 3588e41f796d
index: don't allow index[len(index)] to mean nullid Now everything else has been cleaned up and we can drop support for getting the nullid from the end of the index (from *past* the end actually, since we reduced the length in the previous patch). Differential Revision: https://phab.mercurial-scm.org/D4023
mercurial/cext/revlog.c
mercurial/revlog.py
tests/test-parseindex2.py
--- a/mercurial/cext/revlog.c	Fri Jul 20 08:10:32 2018 -0700
+++ b/mercurial/cext/revlog.c	Fri Jul 20 14:36:42 2018 -0700
@@ -158,12 +158,12 @@
 	Py_ssize_t length = index_length(self) + 1;
 	PyObject *entry;
 
-	if (pos == -1 || pos == length - 1) {
+	if (pos == -1) {
 		Py_INCREF(nullentry);
 		return nullentry;
 	}
 
-	if (pos < 0 || pos >= length) {
+	if (pos < 0 || pos >= length - 1) {
 		PyErr_SetString(PyExc_IndexError, "revlog index out of range");
 		return NULL;
 	}
--- a/mercurial/revlog.py	Fri Jul 20 08:10:32 2018 -0700
+++ b/mercurial/revlog.py	Fri Jul 20 14:36:42 2018 -0700
@@ -792,7 +792,7 @@
 
 class revlogoldindex(list):
     def __getitem__(self, i):
-        if i == -1 or i == len(self):
+        if i == -1:
             return (0, 0, 0, -1, -1, -1, -1, nullid)
         return list.__getitem__(self, i)
 
--- a/tests/test-parseindex2.py	Fri Jul 20 08:10:32 2018 -0700
+++ b/tests/test-parseindex2.py	Fri Jul 20 14:36:42 2018 -0700
@@ -61,9 +61,6 @@
     e[0] = offset_type(0, type)
     index[0] = tuple(e)
 
-    # add the magic null revision at -1
-    index.append((0, 0, 0, -1, -1, -1, -1, nullid))
-
     return index, cache
 
 data_inlined = (