Mercurial > hg
comparison mercurial/cext/revlog.c @ 38911:2aa4f06c1e91
index: make "nt_*" functions work on an initialized nodetree
I want to be able to reuse these functions with another nodetree
instance later (for disambiguating node prefix within a revset). That
other nodetree instance won't want to be fully populated from the
index, so this commit moves that part to the callers.
Differential Revision: https://phab.mercurial-scm.org/D4107
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 18 Jul 2018 17:37:06 -0700 |
parents | 0db50770f388 |
children | d1bc0e7c862b |
comparison
equal
deleted
inserted
replaced
38910:245c58952298 | 38911:2aa4f06c1e91 |
---|---|
1238 } | 1238 } |
1239 | 1239 |
1240 static int nt_partialmatch(indexObject *self, const char *node, | 1240 static int nt_partialmatch(indexObject *self, const char *node, |
1241 Py_ssize_t nodelen) | 1241 Py_ssize_t nodelen) |
1242 { | 1242 { |
1243 if (nt_init(self) == -1) | |
1244 return -3; | |
1245 if (nt_populate(self) == -1) | |
1246 return -3; | |
1247 | |
1248 return nt_find(self, node, nodelen, 1); | 1243 return nt_find(self, node, nodelen, 1); |
1249 } | 1244 } |
1250 | 1245 |
1251 /* | 1246 /* |
1252 * Find the length of the shortest unique prefix of node. | 1247 * Find the length of the shortest unique prefix of node. |
1258 * rest: length of shortest prefix | 1253 * rest: length of shortest prefix |
1259 */ | 1254 */ |
1260 static int nt_shortest(indexObject *self, const char *node) | 1255 static int nt_shortest(indexObject *self, const char *node) |
1261 { | 1256 { |
1262 int level, off; | 1257 int level, off; |
1263 | |
1264 if (nt_init(self) == -1) | |
1265 return -3; | |
1266 if (nt_populate(self) == -1) | |
1267 return -3; | |
1268 | 1258 |
1269 for (level = off = 0; level < 40; level++) { | 1259 for (level = off = 0; level < 40; level++) { |
1270 int k, v; | 1260 int k, v; |
1271 nodetree *n = &self->nt[off]; | 1261 nodetree *n = &self->nt[off]; |
1272 k = nt_level(node, level); | 1262 k = nt_level(node, level); |
1325 /* input contains non-hex characters */ | 1315 /* input contains non-hex characters */ |
1326 PyErr_Clear(); | 1316 PyErr_Clear(); |
1327 Py_RETURN_NONE; | 1317 Py_RETURN_NONE; |
1328 } | 1318 } |
1329 | 1319 |
1320 if (nt_init(self) == -1) | |
1321 return NULL; | |
1322 if (nt_populate(self) == -1) | |
1323 return NULL; | |
1330 rev = nt_partialmatch(self, node, nodelen); | 1324 rev = nt_partialmatch(self, node, nodelen); |
1331 | 1325 |
1332 switch (rev) { | 1326 switch (rev) { |
1333 case -4: | 1327 case -4: |
1334 raise_revlog_error(); | 1328 raise_revlog_error(); |
1335 case -3: | |
1336 return NULL; | 1329 return NULL; |
1337 case -2: | 1330 case -2: |
1338 Py_RETURN_NONE; | 1331 Py_RETURN_NONE; |
1339 case -1: | 1332 case -1: |
1340 return PyBytes_FromStringAndSize(nullid, 20); | 1333 return PyBytes_FromStringAndSize(nullid, 20); |
1357 return NULL; | 1350 return NULL; |
1358 if (node_check(val, &node) == -1) | 1351 if (node_check(val, &node) == -1) |
1359 return NULL; | 1352 return NULL; |
1360 | 1353 |
1361 self->ntlookups++; | 1354 self->ntlookups++; |
1355 if (nt_init(self) == -1) | |
1356 return NULL; | |
1357 if (nt_populate(self) == -1) | |
1358 return NULL; | |
1362 length = nt_shortest(self, node); | 1359 length = nt_shortest(self, node); |
1363 if (length == -3) | 1360 if (length == -3) |
1364 return NULL; | 1361 return NULL; |
1365 if (length == -2) { | 1362 if (length == -2) { |
1366 raise_revlog_error(); | 1363 raise_revlog_error(); |