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

login
register
mail settings
Submitter phabricator
Date Aug. 7, 2018, 1:12 p.m.
Message ID <2d5a02007878e6cdf17236230ee2dbbd@localhost.localdomain>
Download mbox | patch
Permalink /patch/33399/
State Not Applicable
Headers show

Comments

phabricator - Aug. 7, 2018, 1:12 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2b89e20c450c: index: move all &quot;nt_*&quot; functions to one place (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

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

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

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




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

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1114,6 +1114,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) {
@@ -1266,58 +1318,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;