Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHG2b89e20c450c: index: move all "nt_*" functions to one place
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/cext/revlog.c (104 lines) |
| Commit | Parents | Author | Summary | Date |
|---|---|---|---|---|
| Martin von Zweigbergk | Jul 19 2018, 2:08 PM |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz |
| self->length = 1; | self->length = 1; | ||||
| if (nt_insert(self, nullid, -1) == -1) { | if (nt_insert(self, nullid, -1) == -1) { | ||||
| free(self->nodes); | free(self->nodes); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| return 0; | 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) | static int index_init_nt(indexObject *self) | ||||
| { | { | ||||
| if (self->nt == NULL) { | if (self->nt == NULL) { | ||||
| if ((size_t)self->raw_length > INT_MAX / sizeof(nodetreenode)) { | if ((size_t)self->raw_length > INT_MAX / sizeof(nodetreenode)) { | ||||
| PyErr_SetString(PyExc_ValueError, "overflow in index_init_nt"); | PyErr_SetString(PyExc_ValueError, "overflow in index_init_nt"); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| self->nt = PyMem_Malloc(sizeof(nodetree)); | self->nt = PyMem_Malloc(sizeof(nodetree)); | ||||
| if (nt_insert(self->nt, n, rev) == -1) | if (nt_insert(self->nt, n, rev) == -1) | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| self->ntrev = -1; | self->ntrev = -1; | ||||
| } | } | ||||
| return 0; | 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) | static PyObject *index_partialmatch(indexObject *self, PyObject *args) | ||||
| { | { | ||||
| const char *fullnode; | const char *fullnode; | ||||
| int nodelen; | int nodelen; | ||||
| char *node; | char *node; | ||||
| int rev, i; | int rev, i; | ||||
| if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &node, &nodelen)) | if (!PyArg_ParseTuple(args, PY23("s#", "y#"), &node, &nodelen)) | ||||