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

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 4, 2015, 4:01 a.m.
Message ID <6975c755a8b35c88062b.1423022472@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7655/
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 1421945635 28800
#      Thu Jan 22 08:53:55 2015 -0800
# Node ID 6975c755a8b35c88062bd2ea29b1cc11fa9e67b7
# Parent  c6828c4acf92b415ee722371d781b28870f17e7e
obsolete: add native version of addprecursors()

Patch

diff -r c6828c4acf92 -r 6975c755a8b3 mercurial/obsolete.py
--- a/mercurial/obsolete.py	Wed Jan 21 22:44:20 2015 -0800
+++ b/mercurial/obsolete.py	Thu Jan 22 08:53:55 2015 -0800
@@ -617,6 +617,11 @@ 
 
     @util.nogc
     def _addprecursors(self, markers):
+        native = getattr(parsers, 'addprecursors', None)
+        if native:
+            native(markers, self._precursors)
+            return
+
         for mark in markers:
             for suc in mark[1]:
                 self._precursors.setdefault(suc, set()).add(mark)
diff -r c6828c4acf92 -r 6975c755a8b3 mercurial/parsers.c
--- a/mercurial/parsers.c	Wed Jan 21 22:44:20 2015 -0800
+++ b/mercurial/parsers.c	Thu Jan 22 08:53:55 2015 -0800
@@ -2334,6 +2334,43 @@ 
 	return Py_None;
 }
 
+static PyObject *addprecursors(PyObject *self, PyObject *args) {
+	PyObject *markers;
+	PyObject *precursors;
+	PyObject *iterator;
+	PyObject *marker;
+
+	if (!PyArg_ParseTuple(args, "OO", &markers, &precursors)) {
+		return NULL;
+	}
+
+	iterator = PyObject_GetIter(markers);
+	if (!iterator) {
+		return NULL;
+	}
+	while ((marker = PyIter_Next(iterator))) {
+		PyObject *successors = PyTuple_GetItem(marker, 1);
+		PyObject *successoriterator = PyObject_GetIter(successors);
+		PyObject *successor;
+
+		if (!successoriterator) {
+			return NULL;
+		}
+		while ((successor = PyIter_Next(successoriterator))) {
+			PyObject *set = setdefaultemptyset(precursors, successor);
+			if (!set) {
+				return NULL;
+			}
+			PySet_Add(set, marker);
+			Py_DECREF(successor);
+		}
+		Py_DECREF(successoriterator);
+		Py_DECREF(marker);
+	}
+	Py_DECREF(iterator);
+	return Py_None;
+}
+
 static char parsers_doc[] = "Efficient content parsing.";
 
 PyObject *encodedir(PyObject *self, PyObject *args);
@@ -2353,6 +2390,8 @@ 
 			"parse v1 obsolete markers\n"},
 	{"addsuccessors", addsuccessors, METH_VARARGS,
 			"updates successors from markers\n"},
+	{"addprecursors", addprecursors, METH_VARARGS,
+			"updates precursors from markers\n"},
 	{NULL, NULL}
 };