Mercurial > hg
diff mercurial/cext/diffhelpers.c @ 36057:7f8338b87c88
diffhelpers: allow clang-format oversight
One trailing comma!
Differential Revision: https://phab.mercurial-scm.org/D2179
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 12 Feb 2018 10:31:17 -0500 |
parents | 017ad85e5ac8 |
children |
line wrap: on
line diff
--- a/mercurial/cext/diffhelpers.c Mon Feb 12 10:29:02 2018 -0500 +++ b/mercurial/cext/diffhelpers.c Mon Feb 12 10:31:17 2018 -0500 @@ -16,12 +16,11 @@ 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); @@ -29,29 +28,28 @@ 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,8 +80,8 @@ 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) { @@ -92,7 +89,7 @@ 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,8 +174,8 @@ 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); @@ -192,13 +183,12 @@ 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