##// END OF EJS Templates
diffhelpers: allow clang-format oversight...
Augie Fackler -
r36074:7f8338b8 default
parent child Browse files
Show More
@@ -1,59 +1,58 b''
1 # Files that just need to be migrated to the formatter.
1 # Files that just need to be migrated to the formatter.
2 # Do not add new files here!
2 # Do not add new files here!
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
10 mercurial/cext/osutil.c
9 mercurial/cext/osutil.c
11 mercurial/cext/revlog.c
10 mercurial/cext/revlog.c
12 # Vendored code that we should never format:
11 # Vendored code that we should never format:
13 contrib/python-zstandard/c-ext/bufferutil.c
12 contrib/python-zstandard/c-ext/bufferutil.c
14 contrib/python-zstandard/c-ext/compressiondict.c
13 contrib/python-zstandard/c-ext/compressiondict.c
15 contrib/python-zstandard/c-ext/compressionparams.c
14 contrib/python-zstandard/c-ext/compressionparams.c
16 contrib/python-zstandard/c-ext/compressionwriter.c
15 contrib/python-zstandard/c-ext/compressionwriter.c
17 contrib/python-zstandard/c-ext/compressobj.c
16 contrib/python-zstandard/c-ext/compressobj.c
18 contrib/python-zstandard/c-ext/compressor.c
17 contrib/python-zstandard/c-ext/compressor.c
19 contrib/python-zstandard/c-ext/compressoriterator.c
18 contrib/python-zstandard/c-ext/compressoriterator.c
20 contrib/python-zstandard/c-ext/constants.c
19 contrib/python-zstandard/c-ext/constants.c
21 contrib/python-zstandard/c-ext/decompressionwriter.c
20 contrib/python-zstandard/c-ext/decompressionwriter.c
22 contrib/python-zstandard/c-ext/decompressobj.c
21 contrib/python-zstandard/c-ext/decompressobj.c
23 contrib/python-zstandard/c-ext/decompressor.c
22 contrib/python-zstandard/c-ext/decompressor.c
24 contrib/python-zstandard/c-ext/decompressoriterator.c
23 contrib/python-zstandard/c-ext/decompressoriterator.c
25 contrib/python-zstandard/c-ext/frameparams.c
24 contrib/python-zstandard/c-ext/frameparams.c
26 contrib/python-zstandard/c-ext/python-zstandard.h
25 contrib/python-zstandard/c-ext/python-zstandard.h
27 contrib/python-zstandard/zstd.c
26 contrib/python-zstandard/zstd.c
28 contrib/python-zstandard/zstd/common/bitstream.h
27 contrib/python-zstandard/zstd/common/bitstream.h
29 contrib/python-zstandard/zstd/common/entropy_common.c
28 contrib/python-zstandard/zstd/common/entropy_common.c
30 contrib/python-zstandard/zstd/common/error_private.c
29 contrib/python-zstandard/zstd/common/error_private.c
31 contrib/python-zstandard/zstd/common/error_private.h
30 contrib/python-zstandard/zstd/common/error_private.h
32 contrib/python-zstandard/zstd/common/fse.h
31 contrib/python-zstandard/zstd/common/fse.h
33 contrib/python-zstandard/zstd/common/fse_decompress.c
32 contrib/python-zstandard/zstd/common/fse_decompress.c
34 contrib/python-zstandard/zstd/common/huf.h
33 contrib/python-zstandard/zstd/common/huf.h
35 contrib/python-zstandard/zstd/common/mem.h
34 contrib/python-zstandard/zstd/common/mem.h
36 contrib/python-zstandard/zstd/common/pool.c
35 contrib/python-zstandard/zstd/common/pool.c
37 contrib/python-zstandard/zstd/common/pool.h
36 contrib/python-zstandard/zstd/common/pool.h
38 contrib/python-zstandard/zstd/common/threading.c
37 contrib/python-zstandard/zstd/common/threading.c
39 contrib/python-zstandard/zstd/common/threading.h
38 contrib/python-zstandard/zstd/common/threading.h
40 contrib/python-zstandard/zstd/common/xxhash.c
39 contrib/python-zstandard/zstd/common/xxhash.c
41 contrib/python-zstandard/zstd/common/xxhash.h
40 contrib/python-zstandard/zstd/common/xxhash.h
42 contrib/python-zstandard/zstd/common/zstd_common.c
41 contrib/python-zstandard/zstd/common/zstd_common.c
43 contrib/python-zstandard/zstd/common/zstd_errors.h
42 contrib/python-zstandard/zstd/common/zstd_errors.h
44 contrib/python-zstandard/zstd/common/zstd_internal.h
43 contrib/python-zstandard/zstd/common/zstd_internal.h
45 contrib/python-zstandard/zstd/compress/fse_compress.c
44 contrib/python-zstandard/zstd/compress/fse_compress.c
46 contrib/python-zstandard/zstd/compress/huf_compress.c
45 contrib/python-zstandard/zstd/compress/huf_compress.c
47 contrib/python-zstandard/zstd/compress/zstd_compress.c
46 contrib/python-zstandard/zstd/compress/zstd_compress.c
48 contrib/python-zstandard/zstd/compress/zstd_opt.h
47 contrib/python-zstandard/zstd/compress/zstd_opt.h
49 contrib/python-zstandard/zstd/compress/zstdmt_compress.c
48 contrib/python-zstandard/zstd/compress/zstdmt_compress.c
50 contrib/python-zstandard/zstd/compress/zstdmt_compress.h
49 contrib/python-zstandard/zstd/compress/zstdmt_compress.h
51 contrib/python-zstandard/zstd/decompress/huf_decompress.c
50 contrib/python-zstandard/zstd/decompress/huf_decompress.c
52 contrib/python-zstandard/zstd/decompress/zstd_decompress.c
51 contrib/python-zstandard/zstd/decompress/zstd_decompress.c
53 contrib/python-zstandard/zstd/dictBuilder/cover.c
52 contrib/python-zstandard/zstd/dictBuilder/cover.c
54 contrib/python-zstandard/zstd/dictBuilder/divsufsort.c
53 contrib/python-zstandard/zstd/dictBuilder/divsufsort.c
55 contrib/python-zstandard/zstd/dictBuilder/divsufsort.h
54 contrib/python-zstandard/zstd/dictBuilder/divsufsort.h
56 contrib/python-zstandard/zstd/dictBuilder/zdict.c
55 contrib/python-zstandard/zstd/dictBuilder/zdict.c
57 contrib/python-zstandard/zstd/dictBuilder/zdict.h
56 contrib/python-zstandard/zstd/dictBuilder/zdict.h
58 contrib/python-zstandard/zstd/zstd.h
57 contrib/python-zstandard/zstd/zstd.h
59 hgext/fsmonitor/pywatchman/bser.c
58 hgext/fsmonitor/pywatchman/bser.c
@@ -1,204 +1,194 b''
1 /*
1 /*
2 * diffhelpers.c - helper routines for mpatch
2 * diffhelpers.c - helper routines for mpatch
3 *
3 *
4 * Copyright 2007 Chris Mason <chris.mason@oracle.com>
4 * Copyright 2007 Chris Mason <chris.mason@oracle.com>
5 *
5 *
6 * This software may be used and distributed according to the terms
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License v2, incorporated herein by reference.
7 * of the GNU General Public License v2, incorporated herein by reference.
8 */
8 */
9
9
10 #include <Python.h>
10 #include <Python.h>
11 #include <stdlib.h>
11 #include <stdlib.h>
12 #include <string.h>
12 #include <string.h>
13
13
14 #include "util.h"
14 #include "util.h"
15
15
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);
28 char c = l[0];
27 char c = l[0];
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))
58 return NULL;
56 return NULL;
59 _fix_newline(hunk, a, b);
57 _fix_newline(hunk, a, b);
60 return Py_BuildValue("l", 0);
58 return Py_BuildValue("l", 0);
61 }
59 }
62
60
63 #if (PY_VERSION_HEX < 0x02050000)
61 #if (PY_VERSION_HEX < 0x02050000)
64 static const char *addlines_format = "OOiiOO";
62 static const char *addlines_format = "OOiiOO";
65 #else
63 #else
66 static const char *addlines_format = "OOnnOO";
64 static const char *addlines_format = "OOnnOO";
67 #endif
65 #endif
68
66
69 /*
67 /*
70 * read lines from fp into the hunk. The hunk is parsed into two arrays
68 * read lines from fp into the hunk. The hunk is parsed into two arrays
71 * a and b. a gets the old state of the text, b gets the new state
69 * a and b. a gets the old state of the text, b gets the new state
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;
80 Py_ssize_t i;
77 Py_ssize_t i;
81 Py_ssize_t lena, lenb;
78 Py_ssize_t lena, lenb;
82 Py_ssize_t num;
79 Py_ssize_t num;
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) {
91 todoa = lena - PyList_Size(a);
88 todoa = lena - PyList_Size(a);
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);
99 c = *s;
96 c = *s;
100 if (strcmp(s, "\\ No newline at end of file\n") == 0) {
97 if (strcmp(s, "\\ No newline at end of file\n") == 0) {
101 _fix_newline(hunk, a, b);
98 _fix_newline(hunk, a, b);
102 continue;
99 continue;
103 }
100 }
104 if (c == '\n') {
101 if (c == '\n') {
105 /* Some patches may be missing the control char
102 /* Some patches may be missing the control char
106 * on empty lines. Supply a leading space. */
103 * on empty lines. Supply a leading space. */
107 Py_DECREF(x);
104 Py_DECREF(x);
108 x = PyBytes_FromString(" \n");
105 x = PyBytes_FromString(" \n");
109 }
106 }
110 PyList_Append(hunk, x);
107 PyList_Append(hunk, x);
111 if (c == '+') {
108 if (c == '+') {
112 l = PyBytes_FromString(s + 1);
109 l = PyBytes_FromString(s + 1);
113 PyList_Append(b, l);
110 PyList_Append(b, l);
114 Py_DECREF(l);
111 Py_DECREF(l);
115 } else if (c == '-') {
112 } else if (c == '-') {
116 PyList_Append(a, x);
113 PyList_Append(a, x);
117 } else {
114 } else {
118 l = PyBytes_FromString(s + 1);
115 l = PyBytes_FromString(s + 1);
119 PyList_Append(b, l);
116 PyList_Append(b, l);
120 Py_DECREF(l);
117 Py_DECREF(l);
121 PyList_Append(a, x);
118 PyList_Append(a, x);
122 }
119 }
123 Py_DECREF(x);
120 Py_DECREF(x);
124 }
121 }
125 }
122 }
126 return Py_BuildValue("l", 0);
123 return Py_BuildValue("l", 0);
127 }
124 }
128
125
129 /*
126 /*
130 * compare the lines in a with the lines in b. a is assumed to have
127 * compare the lines in a with the lines in b. a is assumed to have
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;
139 long bstart;
135 long bstart;
140 Py_ssize_t alen, blen;
136 Py_ssize_t alen, blen;
141 Py_ssize_t i;
137 Py_ssize_t i;
142 char *sa, *sb;
138 char *sa, *sb;
143
139
144 if (!PyArg_ParseTuple(args, "OOl", &a, &b, &bstart))
140 if (!PyArg_ParseTuple(args, "OOl", &a, &b, &bstart))
145 return NULL;
141 return NULL;
146 alen = PyList_Size(a);
142 alen = PyList_Size(a);
147 blen = PyList_Size(b);
143 blen = PyList_Size(b);
148 if (alen > blen - bstart || bstart < 0) {
144 if (alen > blen - bstart || bstart < 0) {
149 return Py_BuildValue("l", -1);
145 return Py_BuildValue("l", -1);
150 }
146 }
151 for (i = 0; i < alen; i++) {
147 for (i = 0; i < alen; i++) {
152 sa = PyBytes_AsString(PyList_GET_ITEM(a, i));
148 sa = PyBytes_AsString(PyList_GET_ITEM(a, i));
153 sb = PyBytes_AsString(PyList_GET_ITEM(b, i + bstart));
149 sb = PyBytes_AsString(PyList_GET_ITEM(b, i + bstart));
154 if (strcmp(sa + 1, sb) != 0)
150 if (strcmp(sa + 1, sb) != 0)
155 return Py_BuildValue("l", -1);
151 return Py_BuildValue("l", -1);
156 }
152 }
157 return Py_BuildValue("l", 0);
153 return Py_BuildValue("l", 0);
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)
179 {
170 {
180 PyObject *m;
171 PyObject *m;
181
172
182 m = PyModule_Create(&diffhelpers_module);
173 m = PyModule_Create(&diffhelpers_module);
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);
191
182
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