Patchwork [3,of,7,V5] sparse-revlog: add a `index_segment_span` function in C

login
register
mail settings
Submitter Boris Feld
Date Nov. 22, 2018, 6:08 p.m.
Message ID <4ad3891a07ed83cda837.1542910085@localhost.localdomain>
Download mbox | patch
Permalink /patch/36718/
State Accepted
Headers show

Comments

Boris Feld - Nov. 22, 2018, 6:08 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@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`.
Yuya Nishihara - Nov. 24, 2018, 1:16 a.m.
On Thu, 22 Nov 2018 19:08:05 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@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

> +		PyErr_Format(PyExc_ValueError,
> +		             "corrupted revlog index: inconsistent offset "
> +		             "between revisions (%lld) and (%lld)",
> +		             (long long)start_rev, (long long)end_offset);

s/%lld/%zd/g, and s/end_offset/end_rev/.

The doc says size_t format notations are supported.

https://docs.python.org/2/c-api/string.html#c.PyString_FromFormat

Patch

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];