[PATCH 5 of 6 RFC] parsers: add radixlinkget method

Jun Wu quark at fb.com
Sun May 21 21:31:12 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1495408070 25200
#      Sun May 21 16:07:50 2017 -0700
# Node ID 6916f2eede1507237cffdb62db1baff8ded04ea5
# Parent  23ea47ebaf6e9f0d711b90d7677cf4628c8761c6
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 6916f2eede15
parsers: add radixlinkget method

This is the Python bridge to the pure C code.

diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -13,4 +13,5 @@
 #include <string.h>
 
+#include "radixlink.h"
 #include "util.h"
 #include "bitmanipulation.h"
@@ -934,4 +935,45 @@ bail:
 }
 
+static PyObject *radixlinkget(PyObject *self, PyObject *args) {
+	radixlink_buffer_t index, link;
+	const uint8_t *key;
+	int indexlen, linklen, keylen;
+	uint32_t loffset, value;
+	PyObject *pyvalues = NULL;
+
+	if (!PyArg_ParseTuple(args, "t#t#t#", &(index.buf), &indexlen,
+			      &(link.buf), &linklen, &key, &keylen)) {
+		return NULL;
+	}
+	index.size = indexlen;
+	link.size = linklen;
+
+	if (radixlink_index_find(&index, key, keylen, &loffset) != 0)
+		return NULL;
+
+	pyvalues = PyList_New(0);
+	if (!pyvalues)
+		return NULL;
+
+	while (loffset) {
+		PyObject *pyvalue;
+		int r;
+		if (radixlink_link_read(&link, &value, &loffset) != 0)
+			return NULL;
+		pyvalue = PyInt_FromLong(value);
+		if (!pyvalue)
+			goto bail;
+
+		r = PyList_Append(pyvalues, pyvalue);
+		Py_DECREF(pyvalue);
+		if (r == -1)
+			return NULL;
+	}
+	return pyvalues;
+bail:
+	Py_DECREF(pyvalues);
+	return NULL;
+}
+
 static char parsers_doc[] = "Efficient content parsing.";
 
@@ -963,4 +1005,6 @@ static PyMethodDef methods[] = {
 	 "like fm1readmarkers, but return [(offset, marker)] instead of "
 	 "[marker]\n"},
+	{"radixlinkget", radixlinkget, METH_VARARGS,
+	 "(indexdata, linkdata, key) -> [values]. Read radixlink values.\n"},
 	{NULL, NULL}
 };
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -640,4 +640,5 @@ extmodules = [
                                          'mercurial/cext/parsers.c',
                                          'mercurial/cext/pathencode.c',
+                                         'mercurial/cext/radixlink.c',
                                          'mercurial/cext/revlog.c'],
               include_dirs=common_include_dirs,


More information about the Mercurial-devel mailing list