D2179: diffhelpers: allow clang-format oversight

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Mon Feb 12 15:44:23 UTC 2018


durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  One trailing comma!

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2179

AFFECTED FILES
  contrib/clang-format-blacklist
  mercurial/cext/diffhelpers.c

CHANGE DETAILS

diff --git a/mercurial/cext/diffhelpers.c b/mercurial/cext/diffhelpers.c
--- a/mercurial/cext/diffhelpers.c
+++ b/mercurial/cext/diffhelpers.c
@@ -16,42 +16,40 @@
 static char diffhelpers_doc[] = "Efficient diff parsing";
 static PyObject *diffhelpers_Error;
 
-
 /* fixup the last lines of a and b when the patch has no newline at eof */
 static void _fix_newline(PyObject *hunk, PyObject *a, PyObject *b)
 {
 	Py_ssize_t hunksz = PyList_Size(hunk);
-	PyObject *s = PyList_GET_ITEM(hunk, hunksz-1);
+	PyObject *s = PyList_GET_ITEM(hunk, hunksz - 1);
 	char *l = PyBytes_AsString(s);
 	Py_ssize_t alen = PyList_Size(a);
 	Py_ssize_t blen = PyList_Size(b);
 	char c = l[0];
 	PyObject *hline;
 	Py_ssize_t sz = PyBytes_GET_SIZE(s);
 
-	if (sz > 1 && l[sz-2] == '\r')
+	if (sz > 1 && l[sz - 2] == '\r')
 		/* tolerate CRLF in last line */
 		sz -= 1;
 
-	hline = PyBytes_FromStringAndSize(l, sz-1);
+	hline = PyBytes_FromStringAndSize(l, sz - 1);
 	if (!hline) {
 		return;
 	}
 
 	if (c == ' ' || c == '+') {
 		PyObject *rline = PyBytes_FromStringAndSize(l + 1, sz - 2);
-		PyList_SetItem(b, blen-1, rline);
+		PyList_SetItem(b, blen - 1, rline);
 	}
 	if (c == ' ' || c == '-') {
 		Py_INCREF(hline);
-		PyList_SetItem(a, alen-1, hline);
+		PyList_SetItem(a, alen - 1, hline);
 	}
-	PyList_SetItem(hunk, hunksz-1, hline);
+	PyList_SetItem(hunk, hunksz - 1, hline);
 }
 
 /* python callable form of _fix_newline */
-static PyObject *
-fix_newline(PyObject *self, PyObject *args)
+static PyObject *fix_newline(PyObject *self, PyObject *args)
 {
 	PyObject *hunk, *a, *b;
 	if (!PyArg_ParseTuple(args, "OOO", &hunk, &a, &b))
@@ -72,8 +70,7 @@
  * The control char from the hunk is saved when inserting into a, but not b
  * (for performance while deleting files)
  */
-static PyObject *
-addlines(PyObject *self, PyObject *args)
+static PyObject *addlines(PyObject *self, PyObject *args)
 {
 
 	PyObject *fp, *hunk, *a, *b, *x;
@@ -83,16 +80,16 @@
 	Py_ssize_t todoa, todob;
 	char *s, c;
 	PyObject *l;
-	if (!PyArg_ParseTuple(args, addlines_format,
-			      &fp, &hunk, &lena, &lenb, &a, &b))
+	if (!PyArg_ParseTuple(args, addlines_format, &fp, &hunk, &lena, &lenb,
+	                      &a, &b))
 		return NULL;
 
 	while (1) {
 		todoa = lena - PyList_Size(a);
 		todob = lenb - PyList_Size(b);
 		num = todoa > todob ? todoa : todob;
 		if (num == 0)
-		    break;
+			break;
 		for (i = 0; i < num; i++) {
 			x = PyFile_GetLine(fp, 0);
 			s = PyBytes_AsString(x);
@@ -131,8 +128,7 @@
  * a control char at the start of each line, this char is ignored in the
  * compare
  */
-static PyObject *
-testhunk(PyObject *self, PyObject *args)
+static PyObject *testhunk(PyObject *self, PyObject *args)
 {
 
 	PyObject *a, *b;
@@ -158,21 +154,16 @@
 }
 
 static PyMethodDef methods[] = {
-	{"addlines", addlines, METH_VARARGS, "add lines to a hunk\n"},
-	{"fix_newline", fix_newline, METH_VARARGS, "fixup newline counters\n"},
-	{"testhunk", testhunk, METH_VARARGS, "test lines in a hunk\n"},
-	{NULL, NULL}
-};
+    {"addlines", addlines, METH_VARARGS, "add lines to a hunk\n"},
+    {"fix_newline", fix_newline, METH_VARARGS, "fixup newline counters\n"},
+    {"testhunk", testhunk, METH_VARARGS, "test lines in a hunk\n"},
+    {NULL, NULL}};
 
 static const int version = 1;
 
 #ifdef IS_PY3K
 static struct PyModuleDef diffhelpers_module = {
-	PyModuleDef_HEAD_INIT,
-	"diffhelpers",
-	diffhelpers_doc,
-	-1,
-	methods
+    PyModuleDef_HEAD_INIT, "diffhelpers", diffhelpers_doc, -1, methods,
 };
 
 PyMODINIT_FUNC PyInit_diffhelpers(void)
@@ -183,22 +174,21 @@
 	if (m == NULL)
 		return NULL;
 
-	diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError",
-											NULL, NULL);
+	diffhelpers_Error =
+	    PyErr_NewException("diffhelpers.diffhelpersError", NULL, NULL);
 	Py_INCREF(diffhelpers_Error);
 	PyModule_AddObject(m, "diffhelpersError", diffhelpers_Error);
 	PyModule_AddIntConstant(m, "version", version);
 
 	return m;
 }
 #else
-PyMODINIT_FUNC
-initdiffhelpers(void)
+PyMODINIT_FUNC initdiffhelpers(void)
 {
 	PyObject *m;
 	m = Py_InitModule3("diffhelpers", methods, diffhelpers_doc);
-	diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError",
-	                                        NULL, NULL);
+	diffhelpers_Error =
+	    PyErr_NewException("diffhelpers.diffhelpersError", NULL, NULL);
 	PyModule_AddIntConstant(m, "version", version);
 }
 #endif
diff --git a/contrib/clang-format-blacklist b/contrib/clang-format-blacklist
--- a/contrib/clang-format-blacklist
+++ b/contrib/clang-format-blacklist
@@ -4,7 +4,6 @@
 mercurial/cext/bdiff.c
 mercurial/cext/charencode.c
 mercurial/cext/charencode.h
-mercurial/cext/diffhelpers.c
 mercurial/cext/dirs.c
 mercurial/cext/manifest.c
 mercurial/cext/mpatch.c



To: durin42, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list