[PATCH 2 of 3] pathencode: make lowerencode() callable from Python
Adrian Buehlmann
adrian at cadifra.com
Fri Oct 5 04:41:27 CDT 2012
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1349429542 -7200
# Node ID a6e1ed39d74a79bfb3a6e0e04120c551ea3c06eb
# Parent e6a3e95d852d7187268be2bad92c5d9ec5840bae
pathencode: make lowerencode() callable from Python
diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1507,6 +1507,7 @@
static char parsers_doc[] = "Efficient content parsing.";
PyObject *encodedir(PyObject *self, PyObject *args);
+PyObject *lowerencode(PyObject *self, PyObject *args);
PyObject *pathencode(PyObject *self, PyObject *args);
static PyMethodDef methods[] = {
@@ -1515,6 +1516,7 @@
{"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"},
{"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"},
{"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"},
+ {"lowerencode", lowerencode, METH_VARARGS, "lowerencode a path\n"},
{"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"},
{NULL, NULL}
};
diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -201,6 +201,33 @@
return destlen;
}
+PyObject *lowerencode(PyObject *self, PyObject *args)
+{
+ Py_ssize_t len, newlen;
+ PyObject *pathobj, *newobj;
+ char *path;
+
+ if (!PyArg_ParseTuple(args, "O:lowerencode", &pathobj))
+ return NULL;
+
+ if (PyString_AsStringAndSize(pathobj, &path, &len) == -1) {
+ PyErr_SetString(PyExc_TypeError, "expected a string");
+ return NULL;
+ }
+
+ newlen = len ? _lowerencode(NULL, 0, path, len + 1) : 1;
+
+ newobj = PyString_FromStringAndSize(NULL, newlen);
+
+ if (newobj) {
+ PyString_GET_SIZE(newobj)--;
+ _lowerencode(PyString_AS_STRING(newobj), newlen, path,
+ len + 1);
+ }
+
+ return newobj;
+}
+
static Py_ssize_t _encode(const uint32_t twobytes[8], const uint32_t onebyte[8],
char *dest, Py_ssize_t destlen, size_t destsize,
const char *src, Py_ssize_t len,
More information about the Mercurial-devel
mailing list