Patchwork D4005: index: store nullrev as -1 in nodetree

login
register
mail settings
Submitter phabricator
Date Aug. 4, 2018, 3:41 a.m.
Message ID <19ea9ebf992e5afeaaa510025dc06bff@localhost.localdomain>
Download mbox | patch
Permalink /patch/33211/
State Not Applicable
Headers show

Comments

phabricator - Aug. 4, 2018, 3:41 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf738c502e43b: index: store nullrev as -1 in nodetree (authored by martinvonz, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D4005?vs=9789&id=9880#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4005?vs=9789&id=9880

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

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
@@ -32,7 +32,7 @@ 
  * A base-16 trie for fast node->rev mapping.
  *
  * Positive value is index of the next node in the trie
- * Negative value is a leaf: -(rev + 1)
+ * Negative value is a leaf: -(rev + 2)
  * Zero is empty
  */
 typedef struct {
@@ -231,7 +231,7 @@ 
 	Py_ssize_t length = index_length(self);
 	const char *data;
 
-	if (pos == length - 1 || pos == INT_MAX)
+	if (pos == length - 1 || pos == -1)
 		return nullid;
 
 	if (pos >= length)
@@ -1008,7 +1008,7 @@ 
 			const char *n;
 			Py_ssize_t i;
 
-			v = -(v + 1);
+			v = -(v + 2);
 			n = index_node(self, v);
 			if (n == NULL)
 				return -2;
@@ -1060,17 +1060,17 @@ 
 		v = n->children[k];
 
 		if (v == 0) {
-			n->children[k] = -rev - 1;
+			n->children[k] = -rev - 2;
 			return 0;
 		}
 		if (v < 0) {
-			const char *oldnode = index_node_existing(self, -(v + 1));
+			const char *oldnode = index_node_existing(self, -(v + 2));
 			int noff;
 
 			if (oldnode == NULL)
 				return -1;
 			if (!memcmp(oldnode, node, 20)) {
-				n->children[k] = -rev - 1;
+				n->children[k] = -rev - 2;
 				return 0;
 			}
 			noff = nt_new(self);
@@ -1095,8 +1095,8 @@ 
 
 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);
+	/* rev==-2 happens to get encoded as 0, which is interpreted as not set */
+	return nt_insert(self, node, -2);
 }
 
 static int nt_init(indexObject *self)
@@ -1118,7 +1118,7 @@ 
 		self->ntrev = (int)index_length(self) - 1;
 		self->ntlookups = 1;
 		self->ntmisses = 0;
-		if (nt_insert(self, nullid, INT_MAX) == -1) {
+		if (nt_insert(self, nullid, -1) == -1) {
 			free(self->nt);
 			self->nt = NULL;
 			return -1;
@@ -1290,7 +1290,7 @@ 
 		v = n->children[k];
 		if (v < 0) {
 			const char *n;
-			v = -(v + 1);
+			v = -(v + 2);
 			n = index_node_existing(self, v);
 			if (n == NULL)
 				return -3;