[PATCH 2 of 2] patches: release the GIL while applying the patch

Boris Feld boris.feld at octobus.net
Tue Feb 6 09:28:03 EST 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1517839431 -3600
#      Mon Feb 05 15:03:51 2018 +0100
# Node ID 345f1c897538cd2b0a5a2fd3952b880206fd9339
# Parent  eee9cca843bc557274945688ea52e16539d45e67
# EXP-Topic parallel-patching
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 345f1c897538
patches: release the GIL while applying the patch

This will allow multiple threads to apply patches at the same time.

diff --git a/mercurial/cext/mpatch.c b/mercurial/cext/mpatch.c
--- a/mercurial/cext/mpatch.c
+++ b/mercurial/cext/mpatch.c
@@ -77,6 +77,7 @@ patches(PyObject *self, PyObject *args)
 	int r = 0;
 	char *out;
 	Py_ssize_t len, outlen, inlen;
+	PyThreadState *_save;
 
 	if (!PyArg_ParseTuple(args, "OO:mpatch", &text, &bins))
 		return NULL;
@@ -110,7 +111,9 @@ patches(PyObject *self, PyObject *args)
 		goto cleanup;
 	}
 	out = PyBytes_AsString(result);
+	_save = PyEval_SaveThread();
 	r = mpatch_apply(out, in, inlen, patch);
+	PyEval_RestoreThread(_save);
 	if (r < 0) {
 		Py_DECREF(result);
 		result = NULL;


More information about the Mercurial-devel mailing list