Show More
@@ -11,6 +11,8 b'' | |||||
11 | #include <stdlib.h> |
|
11 | #include <stdlib.h> | |
12 | #include <string.h> |
|
12 | #include <string.h> | |
13 |
|
13 | |||
|
14 | #include "util.h" | |||
|
15 | ||||
14 | static char diffhelpers_doc[] = "Efficient diff parsing"; |
|
16 | static char diffhelpers_doc[] = "Efficient diff parsing"; | |
15 | static PyObject *diffhelpers_Error; |
|
17 | static PyObject *diffhelpers_Error; | |
16 |
|
18 | |||
@@ -20,20 +22,21 b' static void _fix_newline(PyObject *hunk,' | |||||
20 | { |
|
22 | { | |
21 | int hunksz = PyList_Size(hunk); |
|
23 | int hunksz = PyList_Size(hunk); | |
22 | PyObject *s = PyList_GET_ITEM(hunk, hunksz-1); |
|
24 | PyObject *s = PyList_GET_ITEM(hunk, hunksz-1); | |
23 |
char *l = PyString |
|
25 | char *l = PyBytes_AsString(s); | |
24 | int alen = PyList_Size(a); |
|
26 | int alen = PyList_Size(a); | |
25 | int blen = PyList_Size(b); |
|
27 | int blen = PyList_Size(b); | |
26 | char c = l[0]; |
|
28 | char c = l[0]; | |
27 | PyObject *hline; |
|
29 | PyObject *hline; | |
28 |
int sz = Py |
|
30 | int sz = PyBytes_GET_SIZE(s); | |
29 |
|
31 | |||
30 | if (sz > 1 && l[sz-2] == '\r') |
|
32 | if (sz > 1 && l[sz-2] == '\r') | |
31 | /* tolerate CRLF in last line */ |
|
33 | /* tolerate CRLF in last line */ | |
32 | sz -= 1; |
|
34 | sz -= 1; | |
33 | hline = PyString_FromStringAndSize(l, sz-1); |
|
35 | ||
|
36 | hline = PyBytes_FromStringAndSize(l, sz-1); | |||
34 |
|
37 | |||
35 | if (c == ' ' || c == '+') { |
|
38 | if (c == ' ' || c == '+') { | |
36 |
PyObject *rline = Py |
|
39 | PyObject *rline = PyBytes_FromStringAndSize(l + 1, sz - 2); | |
37 | PyList_SetItem(b, blen-1, rline); |
|
40 | PyList_SetItem(b, blen-1, rline); | |
38 | } |
|
41 | } | |
39 | if (c == ' ' || c == '-') { |
|
42 | if (c == ' ' || c == '-') { | |
@@ -82,7 +85,7 b' addlines(PyObject *self, PyObject *args)' | |||||
82 | break; |
|
85 | break; | |
83 | for (i = 0; i < num; i++) { |
|
86 | for (i = 0; i < num; i++) { | |
84 | x = PyFile_GetLine(fp, 0); |
|
87 | x = PyFile_GetLine(fp, 0); | |
85 |
s = PyString |
|
88 | s = PyBytes_AsString(x); | |
86 | c = *s; |
|
89 | c = *s; | |
87 | if (strcmp(s, "\\ No newline at end of file\n") == 0) { |
|
90 | if (strcmp(s, "\\ No newline at end of file\n") == 0) { | |
88 | _fix_newline(hunk, a, b); |
|
91 | _fix_newline(hunk, a, b); | |
@@ -92,17 +95,17 b' addlines(PyObject *self, PyObject *args)' | |||||
92 | /* Some patches may be missing the control char |
|
95 | /* Some patches may be missing the control char | |
93 | * on empty lines. Supply a leading space. */ |
|
96 | * on empty lines. Supply a leading space. */ | |
94 | Py_DECREF(x); |
|
97 | Py_DECREF(x); | |
95 |
x = Py |
|
98 | x = PyBytes_FromString(" \n"); | |
96 | } |
|
99 | } | |
97 | PyList_Append(hunk, x); |
|
100 | PyList_Append(hunk, x); | |
98 | if (c == '+') { |
|
101 | if (c == '+') { | |
99 |
l = Py |
|
102 | l = PyBytes_FromString(s + 1); | |
100 | PyList_Append(b, l); |
|
103 | PyList_Append(b, l); | |
101 | Py_DECREF(l); |
|
104 | Py_DECREF(l); | |
102 | } else if (c == '-') { |
|
105 | } else if (c == '-') { | |
103 | PyList_Append(a, x); |
|
106 | PyList_Append(a, x); | |
104 | } else { |
|
107 | } else { | |
105 |
l = Py |
|
108 | l = PyBytes_FromString(s + 1); | |
106 | PyList_Append(b, l); |
|
109 | PyList_Append(b, l); | |
107 | Py_DECREF(l); |
|
110 | Py_DECREF(l); | |
108 | PyList_Append(a, x); |
|
111 | PyList_Append(a, x); | |
@@ -136,8 +139,8 b' testhunk(PyObject *self, PyObject *args)' | |||||
136 | return Py_BuildValue("l", -1); |
|
139 | return Py_BuildValue("l", -1); | |
137 | } |
|
140 | } | |
138 | for (i = 0; i < alen; i++) { |
|
141 | for (i = 0; i < alen; i++) { | |
139 |
sa = PyString |
|
142 | sa = PyBytes_AsString(PyList_GET_ITEM(a, i)); | |
140 |
sb = PyString |
|
143 | sb = PyBytes_AsString(PyList_GET_ITEM(b, i + bstart)); | |
141 | if (strcmp(sa + 1, sb) != 0) |
|
144 | if (strcmp(sa + 1, sb) != 0) | |
142 | return Py_BuildValue("l", -1); |
|
145 | return Py_BuildValue("l", -1); | |
143 | } |
|
146 | } | |
@@ -151,6 +154,31 b' static PyMethodDef methods[] = {' | |||||
151 | {NULL, NULL} |
|
154 | {NULL, NULL} | |
152 | }; |
|
155 | }; | |
153 |
|
156 | |||
|
157 | #ifdef IS_PY3K | |||
|
158 | static struct PyModuleDef diffhelpers_module = { | |||
|
159 | PyModuleDef_HEAD_INIT, | |||
|
160 | "diffhelpers", | |||
|
161 | diffhelpers_doc, | |||
|
162 | -1, | |||
|
163 | methods | |||
|
164 | }; | |||
|
165 | ||||
|
166 | PyMODINIT_FUNC PyInit_diffhelpers(void) | |||
|
167 | { | |||
|
168 | PyObject *m; | |||
|
169 | ||||
|
170 | m = PyModule_Create(&diffhelpers_module); | |||
|
171 | if (m == NULL) | |||
|
172 | return NULL; | |||
|
173 | ||||
|
174 | diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError", | |||
|
175 | NULL, NULL); | |||
|
176 | Py_INCREF(diffhelpers_Error); | |||
|
177 | PyModule_AddObject(m, "diffhelpersError", diffhelpers_Error); | |||
|
178 | ||||
|
179 | return m; | |||
|
180 | } | |||
|
181 | #else | |||
154 | PyMODINIT_FUNC |
|
182 | PyMODINIT_FUNC | |
155 | initdiffhelpers(void) |
|
183 | initdiffhelpers(void) | |
156 | { |
|
184 | { | |
@@ -158,4 +186,5 b' initdiffhelpers(void)' | |||||
158 | diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError", |
|
186 | diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError", | |
159 | NULL, NULL); |
|
187 | NULL, NULL); | |
160 | } |
|
188 | } | |
|
189 | #endif | |||
161 |
|
190 |
General Comments 0
You need to be logged in to leave comments.
Login now