[PATCH 3 of 7 V5] sparse-revlog: add a `index_segment_span` function in C
Boris Feld
boris.feld at octobus.net
Thu Nov 22 13:08:05 EST 2018
# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1541785396 -3600
# Fri Nov 09 18:43:16 2018 +0100
# Node ID 4ad3891a07ed83cda837db8d0cbe285ebb377869
# Parent 18864760091a1622d0404e9a87923cf2b1b82082
# EXP-Topic sparse-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
# hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 4ad3891a07ed
sparse-revlog: add a `index_segment_span` function in C
We are about to implement a native version of `slicechunktodensity`. For
clarity, we introduce the helper functions first. This new function provides
an efficient way to retrieve some of the information needed by
`slicechunktodensity`.
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1048,6 +1048,35 @@ bail:
return NULL;
}
+static inline int64_t
+index_segment_span(indexObject *self, Py_ssize_t start_rev, Py_ssize_t end_rev)
+{
+ int64_t start_offset;
+ int64_t end_offset;
+ int end_size;
+ start_offset = index_get_start(self, start_rev);
+ if (start_offset < 0) {
+ return -1;
+ }
+ end_offset = index_get_start(self, end_rev);
+ if (end_offset < 0) {
+ return -1;
+ }
+ end_size = index_get_length(self, end_rev);
+ if (end_size < 0) {
+ return -1;
+ }
+ if (end_offset < start_offset) {
+
+ PyErr_Format(PyExc_ValueError,
+ "corrupted revlog index: inconsistent offset "
+ "between revisions (%lld) and (%lld)",
+ (long long)start_rev, (long long)end_offset);
+ return -1;
+ }
+ return (end_offset - start_offset) + (int64_t)end_size;
+}
+
static inline int nt_level(const char *node, Py_ssize_t level)
{
int v = node[level >> 1];
More information about the Mercurial-devel
mailing list