Mercurial > hg
comparison mercurial/cext/revlog.c @ 37860:a91f31a1e281
revlog: extract function for getting node from known-to-exist rev
Many of the calls to index_node() (which converts a rev to a nodeid)
are done with a rev that's know to exist. If the function fails,
there's something really wrong and we should just abort. This was done
in only one place. This patch starts by extracting that code to a
function that we can reuse in later patches.
Differential Revision: https://phab.mercurial-scm.org/D3456
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 04 May 2018 21:58:43 -0700 |
parents | 92ed344a9e64 |
children | a9d9802d577e |
comparison
equal
deleted
inserted
replaced
37859:66dc9db6ed2c | 37860:a91f31a1e281 |
---|---|
246 | 246 |
247 data = index_deref(self, pos); | 247 data = index_deref(self, pos); |
248 return data ? data + 32 : NULL; | 248 return data ? data + 32 : NULL; |
249 } | 249 } |
250 | 250 |
251 /* | |
252 * Return the 20-byte SHA of the node corresponding to the given rev. The | |
253 * rev is assumed to be existing. If not, an exception is set. | |
254 */ | |
255 static const char *index_node_existing(indexObject *self, Py_ssize_t pos) | |
256 { | |
257 const char *node = index_node(self, pos); | |
258 if (node == NULL) { | |
259 PyErr_Format(PyExc_IndexError, "could not access rev %d", | |
260 (int)pos); | |
261 } | |
262 return node; | |
263 } | |
264 | |
251 static int nt_insert(indexObject *self, const char *node, int rev); | 265 static int nt_insert(indexObject *self, const char *node, int rev); |
252 | 266 |
253 static int node_check(PyObject *obj, char **node, Py_ssize_t *nodelen) | 267 static int node_check(PyObject *obj, char **node, Py_ssize_t *nodelen) |
254 { | 268 { |
255 if (PyBytes_AsStringAndSize(obj, node, nodelen) == -1) | 269 if (PyBytes_AsStringAndSize(obj, node, nodelen) == -1) |
1280 Py_RETURN_NONE; | 1294 Py_RETURN_NONE; |
1281 case -1: | 1295 case -1: |
1282 return PyBytes_FromStringAndSize(nullid, 20); | 1296 return PyBytes_FromStringAndSize(nullid, 20); |
1283 } | 1297 } |
1284 | 1298 |
1285 fullnode = index_node(self, rev); | 1299 fullnode = index_node_existing(self, rev); |
1286 if (fullnode == NULL) { | 1300 if (fullnode == NULL) { |
1287 PyErr_Format(PyExc_IndexError, | |
1288 "could not access rev %d", rev); | |
1289 return NULL; | 1301 return NULL; |
1290 } | 1302 } |
1291 return PyBytes_FromStringAndSize(fullnode, 20); | 1303 return PyBytes_FromStringAndSize(fullnode, 20); |
1292 } | 1304 } |
1293 | 1305 |