Show More
@@ -1,103 +1,102 b'' | |||
|
1 | 1 | # Files that just need to be migrated to the formatter. |
|
2 | 2 | # Do not add new files here! |
|
3 | mercurial/cext/dirs.c | |
|
4 | 3 | mercurial/cext/manifest.c |
|
5 | 4 | mercurial/cext/osutil.c |
|
6 | 5 | # Vendored code that we should never format: |
|
7 | 6 | contrib/python-zstandard/c-ext/bufferutil.c |
|
8 | 7 | contrib/python-zstandard/c-ext/compressionchunker.c |
|
9 | 8 | contrib/python-zstandard/c-ext/compressiondict.c |
|
10 | 9 | contrib/python-zstandard/c-ext/compressionparams.c |
|
11 | 10 | contrib/python-zstandard/c-ext/compressionreader.c |
|
12 | 11 | contrib/python-zstandard/c-ext/compressionwriter.c |
|
13 | 12 | contrib/python-zstandard/c-ext/compressobj.c |
|
14 | 13 | contrib/python-zstandard/c-ext/compressor.c |
|
15 | 14 | contrib/python-zstandard/c-ext/compressoriterator.c |
|
16 | 15 | contrib/python-zstandard/c-ext/constants.c |
|
17 | 16 | contrib/python-zstandard/c-ext/decompressionreader.c |
|
18 | 17 | contrib/python-zstandard/c-ext/decompressionwriter.c |
|
19 | 18 | contrib/python-zstandard/c-ext/decompressobj.c |
|
20 | 19 | contrib/python-zstandard/c-ext/decompressor.c |
|
21 | 20 | contrib/python-zstandard/c-ext/decompressoriterator.c |
|
22 | 21 | contrib/python-zstandard/c-ext/frameparams.c |
|
23 | 22 | contrib/python-zstandard/c-ext/python-zstandard.h |
|
24 | 23 | contrib/python-zstandard/zstd.c |
|
25 | 24 | contrib/python-zstandard/zstd/common/bitstream.h |
|
26 | 25 | contrib/python-zstandard/zstd/common/compiler.h |
|
27 | 26 | contrib/python-zstandard/zstd/common/cpu.h |
|
28 | 27 | contrib/python-zstandard/zstd/common/debug.c |
|
29 | 28 | contrib/python-zstandard/zstd/common/debug.h |
|
30 | 29 | contrib/python-zstandard/zstd/common/entropy_common.c |
|
31 | 30 | contrib/python-zstandard/zstd/common/error_private.c |
|
32 | 31 | contrib/python-zstandard/zstd/common/error_private.h |
|
33 | 32 | contrib/python-zstandard/zstd/common/fse_decompress.c |
|
34 | 33 | contrib/python-zstandard/zstd/common/fse.h |
|
35 | 34 | contrib/python-zstandard/zstd/common/huf.h |
|
36 | 35 | contrib/python-zstandard/zstd/common/mem.h |
|
37 | 36 | contrib/python-zstandard/zstd/common/pool.c |
|
38 | 37 | contrib/python-zstandard/zstd/common/pool.h |
|
39 | 38 | contrib/python-zstandard/zstd/common/threading.c |
|
40 | 39 | contrib/python-zstandard/zstd/common/threading.h |
|
41 | 40 | contrib/python-zstandard/zstd/common/xxhash.c |
|
42 | 41 | contrib/python-zstandard/zstd/common/xxhash.h |
|
43 | 42 | contrib/python-zstandard/zstd/common/zstd_common.c |
|
44 | 43 | contrib/python-zstandard/zstd/common/zstd_errors.h |
|
45 | 44 | contrib/python-zstandard/zstd/common/zstd_internal.h |
|
46 | 45 | contrib/python-zstandard/zstd/compress/fse_compress.c |
|
47 | 46 | contrib/python-zstandard/zstd/compress/hist.c |
|
48 | 47 | contrib/python-zstandard/zstd/compress/hist.h |
|
49 | 48 | contrib/python-zstandard/zstd/compress/huf_compress.c |
|
50 | 49 | contrib/python-zstandard/zstd/compress/zstd_compress.c |
|
51 | 50 | contrib/python-zstandard/zstd/compress/zstd_compress_internal.h |
|
52 | 51 | contrib/python-zstandard/zstd/compress/zstd_compress_literals.c |
|
53 | 52 | contrib/python-zstandard/zstd/compress/zstd_compress_literals.h |
|
54 | 53 | contrib/python-zstandard/zstd/compress/zstd_compress_sequences.c |
|
55 | 54 | contrib/python-zstandard/zstd/compress/zstd_compress_sequences.h |
|
56 | 55 | contrib/python-zstandard/zstd/compress/zstd_double_fast.c |
|
57 | 56 | contrib/python-zstandard/zstd/compress/zstd_double_fast.h |
|
58 | 57 | contrib/python-zstandard/zstd/compress/zstd_fast.c |
|
59 | 58 | contrib/python-zstandard/zstd/compress/zstd_fast.h |
|
60 | 59 | contrib/python-zstandard/zstd/compress/zstd_lazy.c |
|
61 | 60 | contrib/python-zstandard/zstd/compress/zstd_lazy.h |
|
62 | 61 | contrib/python-zstandard/zstd/compress/zstd_ldm.c |
|
63 | 62 | contrib/python-zstandard/zstd/compress/zstd_ldm.h |
|
64 | 63 | contrib/python-zstandard/zstd/compress/zstdmt_compress.c |
|
65 | 64 | contrib/python-zstandard/zstd/compress/zstdmt_compress.h |
|
66 | 65 | contrib/python-zstandard/zstd/compress/zstd_opt.c |
|
67 | 66 | contrib/python-zstandard/zstd/compress/zstd_opt.h |
|
68 | 67 | contrib/python-zstandard/zstd/decompress/huf_decompress.c |
|
69 | 68 | contrib/python-zstandard/zstd/decompress/zstd_ddict.c |
|
70 | 69 | contrib/python-zstandard/zstd/decompress/zstd_ddict.h |
|
71 | 70 | contrib/python-zstandard/zstd/decompress/zstd_decompress_block.c |
|
72 | 71 | contrib/python-zstandard/zstd/decompress/zstd_decompress_block.h |
|
73 | 72 | contrib/python-zstandard/zstd/decompress/zstd_decompress_internal.h |
|
74 | 73 | contrib/python-zstandard/zstd/decompress/zstd_decompress.c |
|
75 | 74 | contrib/python-zstandard/zstd/deprecated/zbuff_common.c |
|
76 | 75 | contrib/python-zstandard/zstd/deprecated/zbuff_compress.c |
|
77 | 76 | contrib/python-zstandard/zstd/deprecated/zbuff_decompress.c |
|
78 | 77 | contrib/python-zstandard/zstd/deprecated/zbuff.h |
|
79 | 78 | contrib/python-zstandard/zstd/dictBuilder/cover.c |
|
80 | 79 | contrib/python-zstandard/zstd/dictBuilder/cover.h |
|
81 | 80 | contrib/python-zstandard/zstd/dictBuilder/divsufsort.c |
|
82 | 81 | contrib/python-zstandard/zstd/dictBuilder/divsufsort.h |
|
83 | 82 | contrib/python-zstandard/zstd/dictBuilder/fastcover.c |
|
84 | 83 | contrib/python-zstandard/zstd/dictBuilder/zdict.c |
|
85 | 84 | contrib/python-zstandard/zstd/dictBuilder/zdict.h |
|
86 | 85 | contrib/python-zstandard/zstd/zstd.h |
|
87 | 86 | hgext/fsmonitor/pywatchman/bser.c |
|
88 | 87 | mercurial/thirdparty/xdiff/xdiff.h |
|
89 | 88 | mercurial/thirdparty/xdiff/xdiffi.c |
|
90 | 89 | mercurial/thirdparty/xdiff/xdiffi.h |
|
91 | 90 | mercurial/thirdparty/xdiff/xemit.c |
|
92 | 91 | mercurial/thirdparty/xdiff/xemit.h |
|
93 | 92 | mercurial/thirdparty/xdiff/xhistogram.c |
|
94 | 93 | mercurial/thirdparty/xdiff/xinclude.h |
|
95 | 94 | mercurial/thirdparty/xdiff/xmacros.h |
|
96 | 95 | mercurial/thirdparty/xdiff/xmerge.c |
|
97 | 96 | mercurial/thirdparty/xdiff/xpatience.c |
|
98 | 97 | mercurial/thirdparty/xdiff/xprepare.c |
|
99 | 98 | mercurial/thirdparty/xdiff/xprepare.h |
|
100 | 99 | mercurial/thirdparty/xdiff/xtypes.h |
|
101 | 100 | mercurial/thirdparty/xdiff/xutils.c |
|
102 | 101 | mercurial/thirdparty/xdiff/xutils.h |
|
103 | 102 | mercurial/thirdparty/zope/interface/_zope_interface_coptimizations.c |
@@ -1,305 +1,305 b'' | |||
|
1 | 1 | /* |
|
2 | 2 | dirs.c - dynamic directory diddling for dirstates |
|
3 | 3 | |
|
4 | 4 | Copyright 2013 Facebook |
|
5 | 5 | |
|
6 | 6 | This software may be used and distributed according to the terms of |
|
7 | 7 | the GNU General Public License, incorporated herein by reference. |
|
8 | 8 | */ |
|
9 | 9 | |
|
10 | 10 | #define PY_SSIZE_T_CLEAN |
|
11 | 11 | #include <Python.h> |
|
12 | 12 | |
|
13 | 13 | #include "util.h" |
|
14 | 14 | |
|
15 | 15 | #ifdef IS_PY3K |
|
16 | 16 | #define PYLONG_VALUE(o) ((PyLongObject *)o)->ob_digit[1] |
|
17 | 17 | #else |
|
18 | 18 | #define PYLONG_VALUE(o) PyInt_AS_LONG(o) |
|
19 | 19 | #endif |
|
20 | 20 | |
|
21 | 21 | /* |
|
22 | 22 | * This is a multiset of directory names, built from the files that |
|
23 | 23 | * appear in a dirstate or manifest. |
|
24 | 24 | * |
|
25 | 25 | * A few implementation notes: |
|
26 | 26 | * |
|
27 | 27 | * We modify Python integers for refcounting, but those integers are |
|
28 | 28 | * never visible to Python code. |
|
29 | 29 | */ |
|
30 | 30 | /* clang-format off */ |
|
31 | 31 | typedef struct { |
|
32 | 32 | PyObject_HEAD |
|
33 | 33 | PyObject *dict; |
|
34 | 34 | } dirsObject; |
|
35 | 35 | /* clang-format on */ |
|
36 | 36 | |
|
37 | 37 | static inline Py_ssize_t _finddir(const char *path, Py_ssize_t pos) |
|
38 | 38 | { |
|
39 | 39 | while (pos != -1) { |
|
40 | 40 | if (path[pos] == '/') |
|
41 | 41 | break; |
|
42 | 42 | pos -= 1; |
|
43 | 43 | } |
|
44 | 44 | if (pos == -1) { |
|
45 |
|
|
|
45 | return 0; | |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | return pos; |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | static int _addpath(PyObject *dirs, PyObject *path) |
|
52 | 52 | { |
|
53 | 53 | const char *cpath = PyBytes_AS_STRING(path); |
|
54 | 54 | Py_ssize_t pos = PyBytes_GET_SIZE(path); |
|
55 | 55 | PyObject *key = NULL; |
|
56 | 56 | int ret = -1; |
|
57 | 57 | |
|
58 | 58 | /* This loop is super critical for performance. That's why we inline |
|
59 | * access to Python structs instead of going through a supported API. | |
|
60 | * The implementation, therefore, is heavily dependent on CPython | |
|
61 | * implementation details. We also commit violations of the Python | |
|
62 | * "protocol" such as mutating immutable objects. But since we only | |
|
63 | * mutate objects created in this function or in other well-defined | |
|
64 | * locations, the references are known so these violations should go | |
|
65 | * unnoticed. */ | |
|
59 | * access to Python structs instead of going through a supported API. | |
|
60 | * The implementation, therefore, is heavily dependent on CPython | |
|
61 | * implementation details. We also commit violations of the Python | |
|
62 | * "protocol" such as mutating immutable objects. But since we only | |
|
63 | * mutate objects created in this function or in other well-defined | |
|
64 | * locations, the references are known so these violations should go | |
|
65 | * unnoticed. */ | |
|
66 | 66 | while ((pos = _finddir(cpath, pos - 1)) != -1) { |
|
67 | 67 | PyObject *val; |
|
68 | 68 | |
|
69 | 69 | key = PyBytes_FromStringAndSize(cpath, pos); |
|
70 | 70 | if (key == NULL) |
|
71 | 71 | goto bail; |
|
72 | 72 | |
|
73 | 73 | val = PyDict_GetItem(dirs, key); |
|
74 | 74 | if (val != NULL) { |
|
75 | 75 | PYLONG_VALUE(val) += 1; |
|
76 | 76 | Py_CLEAR(key); |
|
77 | 77 | break; |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | /* Force Python to not reuse a small shared int. */ |
|
81 | 81 | #ifdef IS_PY3K |
|
82 | 82 | val = PyLong_FromLong(0x1eadbeef); |
|
83 | 83 | #else |
|
84 | 84 | val = PyInt_FromLong(0x1eadbeef); |
|
85 | 85 | #endif |
|
86 | 86 | |
|
87 | 87 | if (val == NULL) |
|
88 | 88 | goto bail; |
|
89 | 89 | |
|
90 | 90 | PYLONG_VALUE(val) = 1; |
|
91 | 91 | ret = PyDict_SetItem(dirs, key, val); |
|
92 | 92 | Py_DECREF(val); |
|
93 | 93 | if (ret == -1) |
|
94 | 94 | goto bail; |
|
95 | 95 | Py_CLEAR(key); |
|
96 | 96 | } |
|
97 | 97 | ret = 0; |
|
98 | 98 | |
|
99 | 99 | bail: |
|
100 | 100 | Py_XDECREF(key); |
|
101 | 101 | |
|
102 | 102 | return ret; |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | static int _delpath(PyObject *dirs, PyObject *path) |
|
106 | 106 | { |
|
107 | 107 | char *cpath = PyBytes_AS_STRING(path); |
|
108 | 108 | Py_ssize_t pos = PyBytes_GET_SIZE(path); |
|
109 | 109 | PyObject *key = NULL; |
|
110 | 110 | int ret = -1; |
|
111 | 111 | |
|
112 | 112 | while ((pos = _finddir(cpath, pos - 1)) != -1) { |
|
113 | 113 | PyObject *val; |
|
114 | 114 | |
|
115 | 115 | key = PyBytes_FromStringAndSize(cpath, pos); |
|
116 | 116 | |
|
117 | 117 | if (key == NULL) |
|
118 | 118 | goto bail; |
|
119 | 119 | |
|
120 | 120 | val = PyDict_GetItem(dirs, key); |
|
121 | 121 | if (val == NULL) { |
|
122 | 122 | PyErr_SetString(PyExc_ValueError, |
|
123 |
|
|
|
123 | "expected a value, found none"); | |
|
124 | 124 | goto bail; |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | if (--PYLONG_VALUE(val) <= 0) { |
|
128 | 128 | if (PyDict_DelItem(dirs, key) == -1) |
|
129 | 129 | goto bail; |
|
130 | 130 | } else |
|
131 | 131 | break; |
|
132 | 132 | Py_CLEAR(key); |
|
133 | 133 | } |
|
134 | 134 | ret = 0; |
|
135 | 135 | |
|
136 | 136 | bail: |
|
137 | 137 | Py_XDECREF(key); |
|
138 | 138 | |
|
139 | 139 | return ret; |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | static int dirs_fromdict(PyObject *dirs, PyObject *source, char skipchar) |
|
143 | 143 | { |
|
144 | 144 | PyObject *key, *value; |
|
145 | 145 | Py_ssize_t pos = 0; |
|
146 | 146 | |
|
147 | 147 | while (PyDict_Next(source, &pos, &key, &value)) { |
|
148 | 148 | if (!PyBytes_Check(key)) { |
|
149 | 149 | PyErr_SetString(PyExc_TypeError, "expected string key"); |
|
150 | 150 | return -1; |
|
151 | 151 | } |
|
152 | 152 | if (skipchar) { |
|
153 | 153 | if (!dirstate_tuple_check(value)) { |
|
154 | 154 | PyErr_SetString(PyExc_TypeError, |
|
155 |
|
|
|
155 | "expected a dirstate tuple"); | |
|
156 | 156 | return -1; |
|
157 | 157 | } |
|
158 | 158 | if (((dirstateTupleObject *)value)->state == skipchar) |
|
159 | 159 | continue; |
|
160 | 160 | } |
|
161 | 161 | |
|
162 | 162 | if (_addpath(dirs, key) == -1) |
|
163 | 163 | return -1; |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | return 0; |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | static int dirs_fromiter(PyObject *dirs, PyObject *source) |
|
170 | 170 | { |
|
171 | 171 | PyObject *iter, *item = NULL; |
|
172 | 172 | int ret; |
|
173 | 173 | |
|
174 | 174 | iter = PyObject_GetIter(source); |
|
175 | 175 | if (iter == NULL) |
|
176 | 176 | return -1; |
|
177 | 177 | |
|
178 | 178 | while ((item = PyIter_Next(iter)) != NULL) { |
|
179 | 179 | if (!PyBytes_Check(item)) { |
|
180 | 180 | PyErr_SetString(PyExc_TypeError, "expected string"); |
|
181 | 181 | break; |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | if (_addpath(dirs, item) == -1) |
|
185 | 185 | break; |
|
186 | 186 | Py_CLEAR(item); |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | ret = PyErr_Occurred() ? -1 : 0; |
|
190 | 190 | Py_DECREF(iter); |
|
191 | 191 | Py_XDECREF(item); |
|
192 | 192 | return ret; |
|
193 | 193 | } |
|
194 | 194 | |
|
195 | 195 | /* |
|
196 | 196 | * Calculate a refcounted set of directory names for the files in a |
|
197 | 197 | * dirstate. |
|
198 | 198 | */ |
|
199 | 199 | static int dirs_init(dirsObject *self, PyObject *args) |
|
200 | 200 | { |
|
201 | 201 | PyObject *dirs = NULL, *source = NULL; |
|
202 | 202 | char skipchar = 0; |
|
203 | 203 | int ret = -1; |
|
204 | 204 | |
|
205 | 205 | self->dict = NULL; |
|
206 | 206 | |
|
207 | 207 | if (!PyArg_ParseTuple(args, "|Oc:__init__", &source, &skipchar)) |
|
208 | 208 | return -1; |
|
209 | 209 | |
|
210 | 210 | dirs = PyDict_New(); |
|
211 | 211 | |
|
212 | 212 | if (dirs == NULL) |
|
213 | 213 | return -1; |
|
214 | 214 | |
|
215 | 215 | if (source == NULL) |
|
216 | 216 | ret = 0; |
|
217 | 217 | else if (PyDict_Check(source)) |
|
218 | 218 | ret = dirs_fromdict(dirs, source, skipchar); |
|
219 | 219 | else if (skipchar) |
|
220 | 220 | PyErr_SetString(PyExc_ValueError, |
|
221 |
|
|
|
222 |
|
|
|
221 | "skip character is only supported " | |
|
222 | "with a dict source"); | |
|
223 | 223 | else |
|
224 | 224 | ret = dirs_fromiter(dirs, source); |
|
225 | 225 | |
|
226 | 226 | if (ret == -1) |
|
227 | 227 | Py_XDECREF(dirs); |
|
228 | 228 | else |
|
229 | 229 | self->dict = dirs; |
|
230 | 230 | |
|
231 | 231 | return ret; |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | PyObject *dirs_addpath(dirsObject *self, PyObject *args) |
|
235 | 235 | { |
|
236 | 236 | PyObject *path; |
|
237 | 237 | |
|
238 | 238 | if (!PyArg_ParseTuple(args, "O!:addpath", &PyBytes_Type, &path)) |
|
239 | 239 | return NULL; |
|
240 | 240 | |
|
241 | 241 | if (_addpath(self->dict, path) == -1) |
|
242 | 242 | return NULL; |
|
243 | 243 | |
|
244 | 244 | Py_RETURN_NONE; |
|
245 | 245 | } |
|
246 | 246 | |
|
247 | 247 | static PyObject *dirs_delpath(dirsObject *self, PyObject *args) |
|
248 | 248 | { |
|
249 | 249 | PyObject *path; |
|
250 | 250 | |
|
251 | 251 | if (!PyArg_ParseTuple(args, "O!:delpath", &PyBytes_Type, &path)) |
|
252 | 252 | return NULL; |
|
253 | 253 | |
|
254 | 254 | if (_delpath(self->dict, path) == -1) |
|
255 | 255 | return NULL; |
|
256 | 256 | |
|
257 | 257 | Py_RETURN_NONE; |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | static int dirs_contains(dirsObject *self, PyObject *value) |
|
261 | 261 | { |
|
262 | 262 | return PyBytes_Check(value) ? PyDict_Contains(self->dict, value) : 0; |
|
263 | 263 | } |
|
264 | 264 | |
|
265 | 265 | static void dirs_dealloc(dirsObject *self) |
|
266 | 266 | { |
|
267 | 267 | Py_XDECREF(self->dict); |
|
268 | 268 | PyObject_Del(self); |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | static PyObject *dirs_iter(dirsObject *self) |
|
272 | 272 | { |
|
273 | 273 | return PyObject_GetIter(self->dict); |
|
274 | 274 | } |
|
275 | 275 | |
|
276 | 276 | static PySequenceMethods dirs_sequence_methods; |
|
277 | 277 | |
|
278 | 278 | static PyMethodDef dirs_methods[] = { |
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
|
279 | {"addpath", (PyCFunction)dirs_addpath, METH_VARARGS, "add a path"}, | |
|
280 | {"delpath", (PyCFunction)dirs_delpath, METH_VARARGS, "remove a path"}, | |
|
281 | {NULL} /* Sentinel */ | |
|
282 | 282 | }; |
|
283 | 283 | |
|
284 |
static PyTypeObject dirsType = { |
|
|
284 | static PyTypeObject dirsType = {PyVarObject_HEAD_INIT(NULL, 0)}; | |
|
285 | 285 | |
|
286 | 286 | void dirs_module_init(PyObject *mod) |
|
287 | 287 | { |
|
288 | 288 | dirs_sequence_methods.sq_contains = (objobjproc)dirs_contains; |
|
289 | 289 | dirsType.tp_name = "parsers.dirs"; |
|
290 | 290 | dirsType.tp_new = PyType_GenericNew; |
|
291 | 291 | dirsType.tp_basicsize = sizeof(dirsObject); |
|
292 | 292 | dirsType.tp_dealloc = (destructor)dirs_dealloc; |
|
293 | 293 | dirsType.tp_as_sequence = &dirs_sequence_methods; |
|
294 | 294 | dirsType.tp_flags = Py_TPFLAGS_DEFAULT; |
|
295 | 295 | dirsType.tp_doc = "dirs"; |
|
296 | 296 | dirsType.tp_iter = (getiterfunc)dirs_iter; |
|
297 | 297 | dirsType.tp_methods = dirs_methods; |
|
298 | 298 | dirsType.tp_init = (initproc)dirs_init; |
|
299 | 299 | |
|
300 | 300 | if (PyType_Ready(&dirsType) < 0) |
|
301 | 301 | return; |
|
302 | 302 | Py_INCREF(&dirsType); |
|
303 | 303 | |
|
304 | 304 | PyModule_AddObject(mod, "dirs", (PyObject *)&dirsType); |
|
305 | 305 | } |
General Comments 0
You need to be logged in to leave comments.
Login now