changeset 38884:f9fc59ea3135

index: create function for deleting node from nodetree A node is marked deleted by nt_insert(self, node, -1), but "-1" could mean so many things (notably nullrev), so let's hide it in a function. The function could possibly also remove nodes from the tree in the future (it currently only marks them deleted). Differential Revision: https://phab.mercurial-scm.org/D4004
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 20 Jul 2018 23:24:14 -0700
parents 119d14f41cb2
children f738c502e43b
files mercurial/cext/revlog.c
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Fri Jul 20 09:58:09 2018 -0700
+++ b/mercurial/cext/revlog.c	Fri Jul 20 23:24:14 2018 -0700
@@ -1093,6 +1093,12 @@
 	return -1;
 }
 
+static int nt_delete_node(indexObject *self, const char *node)
+{
+	/* rev==-1 happens to get encoded as 0, which is interpreted as not set */
+	return nt_insert(self, node, -1);
+}
+
 static int nt_init(indexObject *self)
 {
 	if (self->nt == NULL) {
@@ -1792,7 +1798,7 @@
 		PyObject *tuple = PyList_GET_ITEM(self->added, i);
 		PyObject *node = PyTuple_GET_ITEM(tuple, 7);
 
-		nt_insert(self, PyBytes_AS_STRING(node), -1);
+		nt_delete_node(self, PyBytes_AS_STRING(node));
 	}
 
 	if (start == 0)
@@ -1851,7 +1857,7 @@
 				if (node == NULL)
 					return -1;
 
-				nt_insert(self, node, -1);
+				nt_delete_node(self, node);
 			}
 			if (self->added)
 				nt_invalidate_added(self, 0);
@@ -1903,7 +1909,7 @@
 		return -1;
 
 	if (value == NULL)
-		return self->nt ? nt_insert(self, node, -1) : 0;
+		return self->nt ? nt_delete_node(self, node) : 0;
 	rev = PyInt_AsLong(value);
 	if (rev > INT_MAX || rev < 0) {
 		if (!PyErr_Occurred())