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