# HG changeset patch # User Boris Feld # Date 2018-12-17 09:57:13 # Node ID a6556b09bf83a096171885a0a2a9fa17ab835647 # Parent 84491ae0b3f0a82cd3a82c43c324400f4bcb2415 revlog: add a native implementation of issnapshot This will be used in the next changesets diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c +++ b/mercurial/cext/revlog.c @@ -995,6 +995,40 @@ static inline int index_baserev(indexObj return result; } +/** + * Find if a revision is a snapshot or not + * + * Only relevant for sparse-revlog case. + * Callers must ensure that rev is in a valid range. + */ +static int index_issnapshotrev(indexObject *self, Py_ssize_t rev) +{ + int ps[2]; + Py_ssize_t base; + while (rev >= 0) { + base = (Py_ssize_t)index_baserev(self, rev); + if (base == rev) { + base = -1; + } + if (base == -2) { + assert(PyErr_Occurred()); + return -1; + } + if (base == -1) { + return 1; + } + if (index_get_parents(self, rev, ps, (int)rev) < 0) { + assert(PyErr_Occurred()); + return -1; + }; + if (base == ps[0] || base == ps[1]) { + return 0; + } + rev = base; + } + return rev == -1; +} + static PyObject *index_deltachain(indexObject *self, PyObject *args) { int rev, generaldelta;