D4005: index: store nullrev as -1 in nodetree
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Thu Aug 2 10:52:55 EDT 2018
martinvonz updated this revision to Diff 9789.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D4005?vs=9697&id=9789
REVISION DETAIL
https://phab.mercurial-scm.org/D4005
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
@@ -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)
@@ -1010,7 +1010,7 @@
const char *n;
Py_ssize_t i;
- v = -(v + 1);
+ v = -(v + 2);
n = index_node(self, v);
if (n == NULL)
return -2;
@@ -1062,17 +1062,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);
@@ -1097,8 +1097,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)
@@ -1120,7 +1120,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)
return -1;
}
return 0;
@@ -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;
To: martinvonz, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list