D3497: revlog: extract function for fully populating the radix tree

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue May 8 18:07:18 UTC 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This code is currently used for partialmatch(), but I want to reuse it
  when I implement shortest() in native code.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3497

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1230,25 +1230,31 @@
 	return NULL;
 }
 
+/*
+ * Fully populate the radix tree.
+ */
+static int nt_populate(indexObject *self) {
+	int rev;
+	if (self->ntrev > 0) {
+		for (rev = self->ntrev - 1; rev >= 0; rev--) {
+			const char *n = index_node_existing(self, rev);
+			if (n == NULL)
+				return -1;
+			if (nt_insert(self, n, rev) == -1)
+				return -1;
+		}
+		self->ntrev = rev;
+	}
+	return 0;
+}
+
 static int nt_partialmatch(indexObject *self, const char *node,
 			   Py_ssize_t nodelen)
 {
-	int rev;
-
 	if (nt_init(self) == -1)
 		return -3;
-
-	if (self->ntrev > 0) {
-		/* ensure that the radix tree is fully populated */
-		for (rev = self->ntrev - 1; rev >= 0; rev--) {
-			const char *n = index_node_existing(self, rev);
-			if (n == NULL)
-				return -3;
-			if (nt_insert(self, n, rev) == -1)
-				return -3;
-		}
-		self->ntrev = rev;
-	}
+	if (nt_populate(self) == -1)
+	  return -3;
 
 	return nt_find(self, node, nodelen, 1);
 }



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list