# HG changeset patch # User Yuya Nishihara # Date 1543756237 -32400 # Node ID b12700dd261f03071d7536c141d965a311615632 # Parent 18a8def6e1b58a642e83f7a47ecaabd6f14d4a33 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. diff -r 18a8def6e1b5 -r b12700dd261f mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c Sun Dec 02 21:41:24 2018 +0900 +++ b/mercurial/cext/revlog.c Sun Dec 02 22:10:37 2018 +0900 @@ -194,6 +194,33 @@ return 0; } +/* + * Get parents of the given rev. + * + * If the specified rev is out of range, IndexError will be raised. If the + * revlog entry is corrupted, ValueError may be raised. + * + * Returns 0 on success or -1 on failure. + */ +int HgRevlogIndex_GetParents(PyObject *op, int rev, int *ps) +{ + int tiprev; + if (!op || !HgRevlogIndex_Check(op) || !ps) { + PyErr_BadInternalCall(); + return -1; + } + tiprev = (int)index_length((indexObject *)op) - 1; + if (rev < -1 || rev > tiprev) { + PyErr_Format(PyExc_IndexError, "rev out of range: %d", rev); + return -1; + } else if (rev == -1) { + ps[0] = ps[1] = -1; + return 0; + } else { + return index_get_parents((indexObject *)op, rev, ps, tiprev); + } +} + static inline int64_t index_get_start(indexObject *self, Py_ssize_t rev) { uint64_t offset; diff -r 18a8def6e1b5 -r b12700dd261f mercurial/cext/revlog.h --- a/mercurial/cext/revlog.h Sun Dec 02 21:41:24 2018 +0900 +++ b/mercurial/cext/revlog.h Sun Dec 02 22:10:37 2018 +0900 @@ -12,4 +12,8 @@ extern PyTypeObject HgRevlogIndex_Type; +#define HgRevlogIndex_Check(op) PyObject_TypeCheck(op, &HgRevlogIndex_Type) + +int HgRevlogIndex_GetParents(PyObject *op, int rev, int *ps); + #endif /* _HG_REVLOG_H_ */