One trailing comma!
Details
Details
- Reviewers
indygreg - Group Reviewers
hg-reviewers - Commits
- rHG7f8338b87c88: diffhelpers: allow clang-format oversight
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| indygreg |
| hg-reviewers |
One trailing comma!
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | contrib/clang-format-blacklist (1 line) | |||
| M | mercurial/cext/diffhelpers.c (54 lines) |
| # Files that just need to be migrated to the formatter. | # Files that just need to be migrated to the formatter. | ||||
| # Do not add new files here! | # Do not add new files here! | ||||
| mercurial/cext/base85.c | mercurial/cext/base85.c | ||||
| mercurial/cext/bdiff.c | mercurial/cext/bdiff.c | ||||
| mercurial/cext/charencode.c | mercurial/cext/charencode.c | ||||
| mercurial/cext/charencode.h | mercurial/cext/charencode.h | ||||
| mercurial/cext/diffhelpers.c | |||||
| mercurial/cext/dirs.c | mercurial/cext/dirs.c | ||||
| mercurial/cext/manifest.c | mercurial/cext/manifest.c | ||||
| mercurial/cext/mpatch.c | mercurial/cext/mpatch.c | ||||
| mercurial/cext/osutil.c | mercurial/cext/osutil.c | ||||
| mercurial/cext/revlog.c | mercurial/cext/revlog.c | ||||
| # Vendored code that we should never format: | # Vendored code that we should never format: | ||||
| contrib/python-zstandard/c-ext/bufferutil.c | contrib/python-zstandard/c-ext/bufferutil.c | ||||
| contrib/python-zstandard/c-ext/compressiondict.c | contrib/python-zstandard/c-ext/compressiondict.c | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "util.h" | #include "util.h" | ||||
| static char diffhelpers_doc[] = "Efficient diff parsing"; | static char diffhelpers_doc[] = "Efficient diff parsing"; | ||||
| static PyObject *diffhelpers_Error; | static PyObject *diffhelpers_Error; | ||||
| /* fixup the last lines of a and b when the patch has no newline at eof */ | /* 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) | static void _fix_newline(PyObject *hunk, PyObject *a, PyObject *b) | ||||
| { | { | ||||
| Py_ssize_t hunksz = PyList_Size(hunk); | 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); | char *l = PyBytes_AsString(s); | ||||
| Py_ssize_t alen = PyList_Size(a); | Py_ssize_t alen = PyList_Size(a); | ||||
| Py_ssize_t blen = PyList_Size(b); | Py_ssize_t blen = PyList_Size(b); | ||||
| char c = l[0]; | char c = l[0]; | ||||
| PyObject *hline; | PyObject *hline; | ||||
| Py_ssize_t sz = PyBytes_GET_SIZE(s); | 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 */ | /* tolerate CRLF in last line */ | ||||
| sz -= 1; | sz -= 1; | ||||
| hline = PyBytes_FromStringAndSize(l, sz-1); | hline = PyBytes_FromStringAndSize(l, sz - 1); | ||||
| if (!hline) { | if (!hline) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (c == ' ' || c == '+') { | if (c == ' ' || c == '+') { | ||||
| PyObject *rline = PyBytes_FromStringAndSize(l + 1, sz - 2); | PyObject *rline = PyBytes_FromStringAndSize(l + 1, sz - 2); | ||||
| PyList_SetItem(b, blen-1, rline); | PyList_SetItem(b, blen - 1, rline); | ||||
| } | } | ||||
| if (c == ' ' || c == '-') { | if (c == ' ' || c == '-') { | ||||
| Py_INCREF(hline); | 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 */ | /* python callable form of _fix_newline */ | ||||
| static PyObject * | static PyObject *fix_newline(PyObject *self, PyObject *args) | ||||
| fix_newline(PyObject *self, PyObject *args) | |||||
| { | { | ||||
| PyObject *hunk, *a, *b; | PyObject *hunk, *a, *b; | ||||
| if (!PyArg_ParseTuple(args, "OOO", &hunk, &a, &b)) | if (!PyArg_ParseTuple(args, "OOO", &hunk, &a, &b)) | ||||
| return NULL; | return NULL; | ||||
| _fix_newline(hunk, a, b); | _fix_newline(hunk, a, b); | ||||
| return Py_BuildValue("l", 0); | return Py_BuildValue("l", 0); | ||||
| } | } | ||||
| #if (PY_VERSION_HEX < 0x02050000) | #if (PY_VERSION_HEX < 0x02050000) | ||||
| static const char *addlines_format = "OOiiOO"; | static const char *addlines_format = "OOiiOO"; | ||||
| #else | #else | ||||
| static const char *addlines_format = "OOnnOO"; | static const char *addlines_format = "OOnnOO"; | ||||
| #endif | #endif | ||||
| /* | /* | ||||
| * read lines from fp into the hunk. The hunk is parsed into two arrays | * read lines from fp into the hunk. The hunk is parsed into two arrays | ||||
| * a and b. a gets the old state of the text, b gets the new state | * a and b. a gets the old state of the text, b gets the new state | ||||
| * The control char from the hunk is saved when inserting into a, but not b | * The control char from the hunk is saved when inserting into a, but not b | ||||
| * (for performance while deleting files) | * (for performance while deleting files) | ||||
| */ | */ | ||||
| static PyObject * | static PyObject *addlines(PyObject *self, PyObject *args) | ||||
| addlines(PyObject *self, PyObject *args) | |||||
| { | { | ||||
| PyObject *fp, *hunk, *a, *b, *x; | PyObject *fp, *hunk, *a, *b, *x; | ||||
| Py_ssize_t i; | Py_ssize_t i; | ||||
| Py_ssize_t lena, lenb; | Py_ssize_t lena, lenb; | ||||
| Py_ssize_t num; | Py_ssize_t num; | ||||
| Py_ssize_t todoa, todob; | Py_ssize_t todoa, todob; | ||||
| char *s, c; | char *s, c; | ||||
| PyObject *l; | PyObject *l; | ||||
| if (!PyArg_ParseTuple(args, addlines_format, | if (!PyArg_ParseTuple(args, addlines_format, &fp, &hunk, &lena, &lenb, | ||||
| &fp, &hunk, &lena, &lenb, &a, &b)) | &a, &b)) | ||||
| return NULL; | return NULL; | ||||
| while (1) { | while (1) { | ||||
| todoa = lena - PyList_Size(a); | todoa = lena - PyList_Size(a); | ||||
| todob = lenb - PyList_Size(b); | todob = lenb - PyList_Size(b); | ||||
| num = todoa > todob ? todoa : todob; | num = todoa > todob ? todoa : todob; | ||||
| if (num == 0) | if (num == 0) | ||||
| break; | break; | ||||
| for (i = 0; i < num; i++) { | for (i = 0; i < num; i++) { | ||||
| x = PyFile_GetLine(fp, 0); | x = PyFile_GetLine(fp, 0); | ||||
| s = PyBytes_AsString(x); | s = PyBytes_AsString(x); | ||||
| c = *s; | c = *s; | ||||
| if (strcmp(s, "\\ No newline at end of file\n") == 0) { | if (strcmp(s, "\\ No newline at end of file\n") == 0) { | ||||
| _fix_newline(hunk, a, b); | _fix_newline(hunk, a, b); | ||||
| continue; | continue; | ||||
| } | } | ||||
| return Py_BuildValue("l", 0); | return Py_BuildValue("l", 0); | ||||
| } | } | ||||
| /* | /* | ||||
| * compare the lines in a with the lines in b. a is assumed to have | * compare the lines in a with the lines in b. a is assumed to have | ||||
| * a control char at the start of each line, this char is ignored in the | * a control char at the start of each line, this char is ignored in the | ||||
| * compare | * compare | ||||
| */ | */ | ||||
| static PyObject * | static PyObject *testhunk(PyObject *self, PyObject *args) | ||||
| testhunk(PyObject *self, PyObject *args) | |||||
| { | { | ||||
| PyObject *a, *b; | PyObject *a, *b; | ||||
| long bstart; | long bstart; | ||||
| Py_ssize_t alen, blen; | Py_ssize_t alen, blen; | ||||
| Py_ssize_t i; | Py_ssize_t i; | ||||
| char *sa, *sb; | char *sa, *sb; | ||||
| sb = PyBytes_AsString(PyList_GET_ITEM(b, i + bstart)); | sb = PyBytes_AsString(PyList_GET_ITEM(b, i + bstart)); | ||||
| if (strcmp(sa + 1, sb) != 0) | if (strcmp(sa + 1, sb) != 0) | ||||
| return Py_BuildValue("l", -1); | return Py_BuildValue("l", -1); | ||||
| } | } | ||||
| return Py_BuildValue("l", 0); | return Py_BuildValue("l", 0); | ||||
| } | } | ||||
| static PyMethodDef methods[] = { | static PyMethodDef methods[] = { | ||||
| {"addlines", addlines, METH_VARARGS, "add lines to a hunk\n"}, | {"addlines", addlines, METH_VARARGS, "add lines to a hunk\n"}, | ||||
| {"fix_newline", fix_newline, METH_VARARGS, "fixup newline counters\n"}, | {"fix_newline", fix_newline, METH_VARARGS, "fixup newline counters\n"}, | ||||
| {"testhunk", testhunk, METH_VARARGS, "test lines in a hunk\n"}, | {"testhunk", testhunk, METH_VARARGS, "test lines in a hunk\n"}, | ||||
| {NULL, NULL} | {NULL, NULL}}; | ||||
| }; | |||||
| static const int version = 1; | static const int version = 1; | ||||
| #ifdef IS_PY3K | #ifdef IS_PY3K | ||||
| static struct PyModuleDef diffhelpers_module = { | static struct PyModuleDef diffhelpers_module = { | ||||
| PyModuleDef_HEAD_INIT, | PyModuleDef_HEAD_INIT, "diffhelpers", diffhelpers_doc, -1, methods, | ||||
| "diffhelpers", | |||||
| diffhelpers_doc, | |||||
| -1, | |||||
| methods | |||||
| }; | }; | ||||
| PyMODINIT_FUNC PyInit_diffhelpers(void) | PyMODINIT_FUNC PyInit_diffhelpers(void) | ||||
| { | { | ||||
| PyObject *m; | PyObject *m; | ||||
| m = PyModule_Create(&diffhelpers_module); | m = PyModule_Create(&diffhelpers_module); | ||||
| if (m == NULL) | if (m == NULL) | ||||
| return NULL; | return NULL; | ||||
| diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError", | diffhelpers_Error = | ||||
| NULL, NULL); | PyErr_NewException("diffhelpers.diffhelpersError", NULL, NULL); | ||||
| Py_INCREF(diffhelpers_Error); | Py_INCREF(diffhelpers_Error); | ||||
| PyModule_AddObject(m, "diffhelpersError", diffhelpers_Error); | PyModule_AddObject(m, "diffhelpersError", diffhelpers_Error); | ||||
| PyModule_AddIntConstant(m, "version", version); | PyModule_AddIntConstant(m, "version", version); | ||||
| return m; | return m; | ||||
| } | } | ||||
| #else | #else | ||||
| PyMODINIT_FUNC | PyMODINIT_FUNC initdiffhelpers(void) | ||||
| initdiffhelpers(void) | |||||
| { | { | ||||
| PyObject *m; | PyObject *m; | ||||
| m = Py_InitModule3("diffhelpers", methods, diffhelpers_doc); | m = Py_InitModule3("diffhelpers", methods, diffhelpers_doc); | ||||
| diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError", | diffhelpers_Error = | ||||
| NULL, NULL); | PyErr_NewException("diffhelpers.diffhelpersError", NULL, NULL); | ||||
| PyModule_AddIntConstant(m, "version", version); | PyModule_AddIntConstant(m, "version", version); | ||||
| } | } | ||||
| #endif | #endif | ||||