D4116: index: move all "nt_*" functions to one place

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Mon Aug 6 09:25:15 EDT 2018


martinvonz updated this revision to Diff 9981.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4116?vs=9919&id=9981

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

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
@@ -1111,6 +1111,58 @@
 	return 0;
 }
 
+static int nt_partialmatch(nodetree *self, const char *node,
+			   Py_ssize_t nodelen)
+{
+	return nt_find(self, node, nodelen, 1);
+}
+
+/*
+ * Find the length of the shortest unique prefix of node.
+ *
+ * Return values:
+ *
+ *   -3: error (exception set)
+ *   -2: not found (no exception set)
+ * rest: length of shortest prefix
+ */
+static int nt_shortest(nodetree *self, const char *node)
+{
+	int level, off;
+
+	for (level = off = 0; level < 40; level++) {
+		int k, v;
+		nodetreenode *n = &self->nodes[off];
+		k = nt_level(node, level);
+		v = n->children[k];
+		if (v < 0) {
+			const char *n;
+			v = -(v + 2);
+			n = index_node_existing(self->index, v);
+			if (n == NULL)
+				return -3;
+			if (memcmp(node, n, 20) != 0)
+				/*
+				 * Found a unique prefix, but it wasn't for the
+				 * requested node (i.e the requested node does
+				 * not exist).
+				 */
+				return -2;
+			return level + 1;
+		}
+		if (v == 0)
+			return -2;
+		off = v;
+	}
+	/*
+	 * The node was still not unique after 40 hex digits, so this won't
+	 * happen. Also, if we get here, then there's a programming error in
+	 * this file that made us insert a node longer than 40 hex digits.
+	 */
+	PyErr_SetString(PyExc_Exception, "broken node tree");
+	return -3;
+}
+
 static int index_init_nt(indexObject *self)
 {
 	if (self->nt == NULL) {
@@ -1263,58 +1315,6 @@
 	return 0;
 }
 
-static int nt_partialmatch(nodetree *self, const char *node,
-			   Py_ssize_t nodelen)
-{
-	return nt_find(self, node, nodelen, 1);
-}
-
-/*
- * Find the length of the shortest unique prefix of node.
- *
- * Return values:
- *
- *   -3: error (exception set)
- *   -2: not found (no exception set)
- * rest: length of shortest prefix
- */
-static int nt_shortest(nodetree *self, const char *node)
-{
-	int level, off;
-
-	for (level = off = 0; level < 40; level++) {
-		int k, v;
-		nodetreenode *n = &self->nodes[off];
-		k = nt_level(node, level);
-		v = n->children[k];
-		if (v < 0) {
-			const char *n;
-			v = -(v + 2);
-			n = index_node_existing(self->index, v);
-			if (n == NULL)
-				return -3;
-			if (memcmp(node, n, 20) != 0)
-				/*
-				 * Found a unique prefix, but it wasn't for the
-				 * requested node (i.e the requested node does
-				 * not exist).
-				 */
-				return -2;
-			return level + 1;
-		}
-		if (v == 0)
-			return -2;
-		off = v;
-	}
-	/*
-	 * The node was still not unique after 40 hex digits, so this won't
-	 * happen. Also, if we get here, then there's a programming error in
-	 * this file that made us insert a node longer than 40 hex digits.
-	 */
-	PyErr_SetString(PyExc_Exception, "broken node tree");
-	return -3;
-}
-
 static PyObject *index_partialmatch(indexObject *self, PyObject *args)
 {
 	const char *fullnode;



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


More information about the Mercurial-devel mailing list