Patchwork [6,of,6] obsolete: add native version of addchildren()

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 4, 2015, 4:01 a.m.
Message ID <e3a4b0c85b179c99b2ce.1423022473@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7650/
State Superseded
Headers show

Comments

Martin von Zweigbergk - Feb. 4, 2015, 4:01 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421945822 28800
#      Thu Jan 22 08:57:02 2015 -0800
# Node ID e3a4b0c85b179c99b2ce73f9b10c01d637e83bcd
# Parent  6975c755a8b35c88062bd2ea29b1cc11fa9e67b7
obsolete: add native version of addchildren()

Patch

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