index: make "nt_*" functions work on an initialized nodetree
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 18 Jul 2018 17:37:06 -0700
changeset 38950 2aa4f06c1e91
parent 38949 245c58952298
child 38951 d1bc0e7c862b
index: make "nt_*" functions work on an initialized nodetree I want to be able to reuse these functions with another nodetree instance later (for disambiguating node prefix within a revset). That other nodetree instance won't want to be fully populated from the index, so this commit moves that part to the callers. Differential Revision: https://phab.mercurial-scm.org/D4107
mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c	Fri Aug 03 14:03:31 2018 -0700
+++ b/mercurial/cext/revlog.c	Wed Jul 18 17:37:06 2018 -0700
@@ -1240,11 +1240,6 @@
 static int nt_partialmatch(indexObject *self, const char *node,
 			   Py_ssize_t nodelen)
 {
-	if (nt_init(self) == -1)
-		return -3;
-	if (nt_populate(self) == -1)
-		return -3;
-
 	return nt_find(self, node, nodelen, 1);
 }
 
@@ -1261,11 +1256,6 @@
 {
 	int level, off;
 
-	if (nt_init(self) == -1)
-		return -3;
-	if (nt_populate(self) == -1)
-		return -3;
-
 	for (level = off = 0; level < 40; level++) {
 		int k, v;
 		nodetree *n = &self->nt[off];
@@ -1327,12 +1317,15 @@
 		Py_RETURN_NONE;
 	}
 
+	if (nt_init(self) == -1)
+		return NULL;
+	if (nt_populate(self) == -1)
+		return NULL;
 	rev = nt_partialmatch(self, node, nodelen);
 
 	switch (rev) {
 	case -4:
 		raise_revlog_error();
-	case -3:
 		return NULL;
 	case -2:
 		Py_RETURN_NONE;
@@ -1359,6 +1352,10 @@
 		return NULL;
 
 	self->ntlookups++;
+	if (nt_init(self) == -1)
+		return NULL;
+	if (nt_populate(self) == -1)
+		return NULL;
 	length = nt_shortest(self, node);
 	if (length == -3)
 		return NULL;