comparison mercurial/cext/revlog.c @ 40861:b12700dd261f

revlog: add public CPython function to get parent revisions Since this is a public function, it validates the input revision, and supports nullrev. index_get_parents_checked() will be replaced by this function.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 02 Dec 2018 22:10:37 +0900
parents 18a8def6e1b5
children 54a60968f0aa
comparison
equal deleted inserted replaced
40860:18a8def6e1b5 40861:b12700dd261f
190 if (ps[0] < -1 || ps[0] > maxrev || ps[1] < -1 || ps[1] > maxrev) { 190 if (ps[0] < -1 || ps[0] > maxrev || ps[1] < -1 || ps[1] > maxrev) {
191 PyErr_SetString(PyExc_ValueError, "parent out of range"); 191 PyErr_SetString(PyExc_ValueError, "parent out of range");
192 return -1; 192 return -1;
193 } 193 }
194 return 0; 194 return 0;
195 }
196
197 /*
198 * Get parents of the given rev.
199 *
200 * If the specified rev is out of range, IndexError will be raised. If the
201 * revlog entry is corrupted, ValueError may be raised.
202 *
203 * Returns 0 on success or -1 on failure.
204 */
205 int HgRevlogIndex_GetParents(PyObject *op, int rev, int *ps)
206 {
207 int tiprev;
208 if (!op || !HgRevlogIndex_Check(op) || !ps) {
209 PyErr_BadInternalCall();
210 return -1;
211 }
212 tiprev = (int)index_length((indexObject *)op) - 1;
213 if (rev < -1 || rev > tiprev) {
214 PyErr_Format(PyExc_IndexError, "rev out of range: %d", rev);
215 return -1;
216 } else if (rev == -1) {
217 ps[0] = ps[1] = -1;
218 return 0;
219 } else {
220 return index_get_parents((indexObject *)op, rev, ps, tiprev);
221 }
195 } 222 }
196 223
197 static inline int64_t index_get_start(indexObject *self, Py_ssize_t rev) 224 static inline int64_t index_get_start(indexObject *self, Py_ssize_t rev)
198 { 225 {
199 uint64_t offset; 226 uint64_t offset;