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