##// END OF EJS Templates
diffhelpers: allow clang-format oversight...
Augie Fackler -
r36074:7f8338b8 default
parent child Browse files
Show More
@@ -3,7 +3,6 b''
3 3 mercurial/cext/base85.c
4 4 mercurial/cext/charencode.c
5 5 mercurial/cext/charencode.h
6 mercurial/cext/diffhelpers.c
7 6 mercurial/cext/dirs.c
8 7 mercurial/cext/manifest.c
9 8 mercurial/cext/mpatch.c
@@ -16,12 +16,11 b''
16 16 static char diffhelpers_doc[] = "Efficient diff parsing";
17 17 static PyObject *diffhelpers_Error;
18 18
19
20 19 /* fixup the last lines of a and b when the patch has no newline at eof */
21 20 static void _fix_newline(PyObject *hunk, PyObject *a, PyObject *b)
22 21 {
23 22 Py_ssize_t hunksz = PyList_Size(hunk);
24 PyObject *s = PyList_GET_ITEM(hunk, hunksz-1);
23 PyObject *s = PyList_GET_ITEM(hunk, hunksz - 1);
25 24 char *l = PyBytes_AsString(s);
26 25 Py_ssize_t alen = PyList_Size(a);
27 26 Py_ssize_t blen = PyList_Size(b);
@@ -29,29 +28,28 b' static void _fix_newline(PyObject *hunk,'
29 28 PyObject *hline;
30 29 Py_ssize_t sz = PyBytes_GET_SIZE(s);
31 30
32 if (sz > 1 && l[sz-2] == '\r')
31 if (sz > 1 && l[sz - 2] == '\r')
33 32 /* tolerate CRLF in last line */
34 33 sz -= 1;
35 34
36 hline = PyBytes_FromStringAndSize(l, sz-1);
35 hline = PyBytes_FromStringAndSize(l, sz - 1);
37 36 if (!hline) {
38 37 return;
39 38 }
40 39
41 40 if (c == ' ' || c == '+') {
42 41 PyObject *rline = PyBytes_FromStringAndSize(l + 1, sz - 2);
43 PyList_SetItem(b, blen-1, rline);
42 PyList_SetItem(b, blen - 1, rline);
44 43 }
45 44 if (c == ' ' || c == '-') {
46 45 Py_INCREF(hline);
47 PyList_SetItem(a, alen-1, hline);
46 PyList_SetItem(a, alen - 1, hline);
48 47 }
49 PyList_SetItem(hunk, hunksz-1, hline);
48 PyList_SetItem(hunk, hunksz - 1, hline);
50 49 }
51 50
52 51 /* python callable form of _fix_newline */
53 static PyObject *
54 fix_newline(PyObject *self, PyObject *args)
52 static PyObject *fix_newline(PyObject *self, PyObject *args)
55 53 {
56 54 PyObject *hunk, *a, *b;
57 55 if (!PyArg_ParseTuple(args, "OOO", &hunk, &a, &b))
@@ -72,8 +70,7 b' static const char *addlines_format = "OO'
72 70 * The control char from the hunk is saved when inserting into a, but not b
73 71 * (for performance while deleting files)
74 72 */
75 static PyObject *
76 addlines(PyObject *self, PyObject *args)
73 static PyObject *addlines(PyObject *self, PyObject *args)
77 74 {
78 75
79 76 PyObject *fp, *hunk, *a, *b, *x;
@@ -83,8 +80,8 b' addlines(PyObject *self, PyObject *args)'
83 80 Py_ssize_t todoa, todob;
84 81 char *s, c;
85 82 PyObject *l;
86 if (!PyArg_ParseTuple(args, addlines_format,
87 &fp, &hunk, &lena, &lenb, &a, &b))
83 if (!PyArg_ParseTuple(args, addlines_format, &fp, &hunk, &lena, &lenb,
84 &a, &b))
88 85 return NULL;
89 86
90 87 while (1) {
@@ -92,7 +89,7 b' addlines(PyObject *self, PyObject *args)'
92 89 todob = lenb - PyList_Size(b);
93 90 num = todoa > todob ? todoa : todob;
94 91 if (num == 0)
95 break;
92 break;
96 93 for (i = 0; i < num; i++) {
97 94 x = PyFile_GetLine(fp, 0);
98 95 s = PyBytes_AsString(x);
@@ -131,8 +128,7 b' addlines(PyObject *self, PyObject *args)'
131 128 * a control char at the start of each line, this char is ignored in the
132 129 * compare
133 130 */
134 static PyObject *
135 testhunk(PyObject *self, PyObject *args)
131 static PyObject *testhunk(PyObject *self, PyObject *args)
136 132 {
137 133
138 134 PyObject *a, *b;
@@ -158,21 +154,16 b' testhunk(PyObject *self, PyObject *args)'
158 154 }
159 155
160 156 static PyMethodDef methods[] = {
161 {"addlines", addlines, METH_VARARGS, "add lines to a hunk\n"},
162 {"fix_newline", fix_newline, METH_VARARGS, "fixup newline counters\n"},
163 {"testhunk", testhunk, METH_VARARGS, "test lines in a hunk\n"},
164 {NULL, NULL}
165 };
157 {"addlines", addlines, METH_VARARGS, "add lines to a hunk\n"},
158 {"fix_newline", fix_newline, METH_VARARGS, "fixup newline counters\n"},
159 {"testhunk", testhunk, METH_VARARGS, "test lines in a hunk\n"},
160 {NULL, NULL}};
166 161
167 162 static const int version = 1;
168 163
169 164 #ifdef IS_PY3K
170 165 static struct PyModuleDef diffhelpers_module = {
171 PyModuleDef_HEAD_INIT,
172 "diffhelpers",
173 diffhelpers_doc,
174 -1,
175 methods
166 PyModuleDef_HEAD_INIT, "diffhelpers", diffhelpers_doc, -1, methods,
176 167 };
177 168
178 169 PyMODINIT_FUNC PyInit_diffhelpers(void)
@@ -183,8 +174,8 b' PyMODINIT_FUNC PyInit_diffhelpers(void)'
183 174 if (m == NULL)
184 175 return NULL;
185 176
186 diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError",
187 NULL, NULL);
177 diffhelpers_Error =
178 PyErr_NewException("diffhelpers.diffhelpersError", NULL, NULL);
188 179 Py_INCREF(diffhelpers_Error);
189 180 PyModule_AddObject(m, "diffhelpersError", diffhelpers_Error);
190 181 PyModule_AddIntConstant(m, "version", version);
@@ -192,13 +183,12 b' PyMODINIT_FUNC PyInit_diffhelpers(void)'
192 183 return m;
193 184 }
194 185 #else
195 PyMODINIT_FUNC
196 initdiffhelpers(void)
186 PyMODINIT_FUNC initdiffhelpers(void)
197 187 {
198 188 PyObject *m;
199 189 m = Py_InitModule3("diffhelpers", methods, diffhelpers_doc);
200 diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError",
201 NULL, NULL);
190 diffhelpers_Error =
191 PyErr_NewException("diffhelpers.diffhelpersError", NULL, NULL);
202 192 PyModule_AddIntConstant(m, "version", version);
203 193 }
204 194 #endif
General Comments 0
You need to be logged in to leave comments. Login now