[PATCH 2 of 3 to ponder] pathencode: make dotauxencode() callable from Python

Adrian Buehlmann adrian at cadifra.com
Fri Oct 5 15:49:51 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1349469384 -7200
# Node ID 5ad5ecf11d72f5a44100ababfd5a50f1cf112c91
# Parent  9ed1aa45af277af8e47d8e96811f4f210643d8f2
pathencode: make dotauxencode() callable from Python

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1509,6 +1509,7 @@
 PyObject *encodedir(PyObject *self, PyObject *args);
 PyObject *lowerencode(PyObject *self, PyObject *args);
 PyObject *pathencode(PyObject *self, PyObject *args);
+PyObject *dotauxencode(PyObject *self, PyObject *args);
 
 static PyMethodDef methods[] = {
 	{"pack_dirstate", pack_dirstate, METH_VARARGS, "pack a dirstate\n"},
@@ -1518,6 +1519,7 @@
 	{"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"},
+	{"dotauxencode", dotauxencode, METH_VARARGS, "dotauxencode a path\n"},
 	{NULL, NULL}
 };
 
diff --git a/mercurial/pathencode.c b/mercurial/pathencode.c
--- a/mercurial/pathencode.c
+++ b/mercurial/pathencode.c
@@ -593,3 +593,30 @@
 
 	return newobj;
 }
+
+PyObject *dotauxencode(PyObject *self, PyObject *args)
+{
+	Py_ssize_t len, newlen;
+	PyObject *pathobj, *newobj;
+	char *path;
+
+	if (!PyArg_ParseTuple(args, "O:dotauxencode", &pathobj))
+		return NULL;
+
+	if (PyString_AsStringAndSize(pathobj, &path, &len) == -1) {
+		PyErr_SetString(PyExc_TypeError, "expected a string");
+		return NULL;
+	}
+
+	newlen = len ? _dotauxencode(NULL, 0, path, len + 1) : 1;
+
+	newobj = PyString_FromStringAndSize(NULL, newlen);
+
+	if (newobj) {
+		PyString_GET_SIZE(newobj)--;
+		_dotauxencode(PyString_AS_STRING(newobj), newlen, path,
+			      len + 1);
+	}
+
+	return newobj;
+}


More information about the Mercurial-devel mailing list