From patchwork Wed Feb 4 04:01:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6,of,6] obsolete: add native version of addchildren() From: Martin von Zweigbergk X-Patchwork-Id: 7650 Message-Id: To: mercurial-devel@selenic.com Date: Tue, 03 Feb 2015 20:01:13 -0800 # HG changeset patch # User Martin von Zweigbergk # Date 1421945822 28800 # Thu Jan 22 08:57:02 2015 -0800 # Node ID e3a4b0c85b179c99b2ce73f9b10c01d637e83bcd # Parent 6975c755a8b35c88062bd2ea29b1cc11fa9e67b7 obsolete: add native version of addchildren() diff -r 6975c755a8b3 -r e3a4b0c85b17 mercurial/obsolete.py --- a/mercurial/obsolete.py Thu Jan 22 08:53:55 2015 -0800 +++ b/mercurial/obsolete.py Thu Jan 22 08:57:02 2015 -0800 @@ -628,6 +628,11 @@ @util.nogc def _addchildren(self, markers): + native = getattr(parsers, 'addchildren', None) + if native: + native(markers, self._children) + return + for mark in markers: parents = mark[5] if parents is not None: diff -r 6975c755a8b3 -r e3a4b0c85b17 mercurial/parsers.c --- a/mercurial/parsers.c Thu Jan 22 08:53:55 2015 -0800 +++ b/mercurial/parsers.c Thu Jan 22 08:57:02 2015 -0800 @@ -2371,6 +2371,46 @@ return Py_None; } +static PyObject *addchildren(PyObject *self, PyObject *args) { + PyObject *markers; + PyObject *children; + PyObject *iterator; + PyObject *marker; + + if (!PyArg_ParseTuple(args, "OO", &markers, &children)) { + return NULL; + } + + iterator = PyObject_GetIter(markers); + if (!iterator) { + return NULL; + } + while ((marker = PyIter_Next(iterator))) { + PyObject *parents = PyTuple_GetItem(marker, 5); + + if (parents != Py_None) { + PyObject *parentiterator = PyObject_GetIter(parents); + PyObject *parent; + if (!parentiterator) { + return NULL; + } + while ((parent = PyIter_Next(parentiterator))) { + PyObject *set = setdefaultemptyset(children, parent); + if (!set) { + return NULL; + } + PySet_Add(set, marker); + Py_DECREF(parent); + } + Py_DECREF(parentiterator); + } + + Py_DECREF(marker); + } + Py_DECREF(iterator); + return Py_None; +} + static char parsers_doc[] = "Efficient content parsing."; PyObject *encodedir(PyObject *self, PyObject *args); @@ -2392,6 +2432,8 @@ "updates successors from markers\n"}, {"addprecursors", addprecursors, METH_VARARGS, "updates precursors from markers\n"}, + {"addchildren", addchildren, METH_VARARGS, + "updates children from markers\n"}, {NULL, NULL} };