diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
index b54727f825118b79ee5ca0a367c0c02bdbd7c3f2_bWVyY3VyaWFsL2NleHQvcmV2bG9nLmM=..c6939b353ebd2b5b6fe383bd009a5315d52717c6_bWVyY3VyaWFsL2NleHQvcmV2bG9nLmM= 100644
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -261,6 +261,9 @@
 
 static inline int index_get_length(indexObject *self, Py_ssize_t rev)
 {
+	if (rev == nullrev) {
+		return 0;
+	}
 	if (rev >= self->length) {
 		PyObject *tuple;
 		PyObject *pylong;