changeset 41085:a6556b09bf83

revlog: add a native implementation of issnapshot This will be used in the next changesets
author Boris Feld <boris.feld@octobus.net>
date Mon, 17 Dec 2018 10:57:13 +0100
parents 84491ae0b3f0
children a28833d79aca
files mercurial/cext/revlog.c
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Mon Dec 17 10:51:36 2018 +0100
+++ b/mercurial/cext/revlog.c	Mon Dec 17 10:57:13 2018 +0100
@@ -995,6 +995,40 @@
 	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;