Show More
@@ -173,6 +173,72 static PyObject *asciiupper(PyObject *se | |||||
173 | return _asciitransform(str_obj, uppertable, NULL); |
|
173 | return _asciitransform(str_obj, uppertable, NULL); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
|
176 | static PyObject *make_file_foldmap(PyObject *self, PyObject *args) | |||
|
177 | { | |||
|
178 | PyObject *dmap, *spec_obj, *normcase_fallback; | |||
|
179 | PyObject *file_foldmap = NULL; | |||
|
180 | enum normcase_spec spec; | |||
|
181 | PyObject *k, *v; | |||
|
182 | dirstateTupleObject *tuple; | |||
|
183 | Py_ssize_t pos = 0; | |||
|
184 | const char *table; | |||
|
185 | ||||
|
186 | if (!PyArg_ParseTuple(args, "O!O!O!:make_file_foldmap", | |||
|
187 | &PyDict_Type, &dmap, | |||
|
188 | &PyInt_Type, &spec_obj, | |||
|
189 | &PyFunction_Type, &normcase_fallback)) | |||
|
190 | goto quit; | |||
|
191 | ||||
|
192 | spec = PyInt_AS_LONG(spec_obj); | |||
|
193 | switch (spec) { | |||
|
194 | case NORMCASE_LOWER: | |||
|
195 | table = lowertable; | |||
|
196 | break; | |||
|
197 | case NORMCASE_UPPER: | |||
|
198 | table = uppertable; | |||
|
199 | break; | |||
|
200 | case NORMCASE_OTHER: | |||
|
201 | table = NULL; | |||
|
202 | break; | |||
|
203 | default: | |||
|
204 | PyErr_SetString(PyExc_TypeError, "invalid normcasespec"); | |||
|
205 | goto quit; | |||
|
206 | } | |||
|
207 | ||||
|
208 | file_foldmap = PyDict_New(); | |||
|
209 | if (file_foldmap == NULL) | |||
|
210 | goto quit; | |||
|
211 | ||||
|
212 | while (PyDict_Next(dmap, &pos, &k, &v)) { | |||
|
213 | if (!dirstate_tuple_check(v)) { | |||
|
214 | PyErr_SetString(PyExc_TypeError, | |||
|
215 | "expected a dirstate tuple"); | |||
|
216 | goto quit; | |||
|
217 | } | |||
|
218 | ||||
|
219 | tuple = (dirstateTupleObject *)v; | |||
|
220 | if (tuple->state != 'r') { | |||
|
221 | PyObject *normed; | |||
|
222 | if (table != NULL) { | |||
|
223 | normed = _asciitransform(k, table, | |||
|
224 | normcase_fallback); | |||
|
225 | } else { | |||
|
226 | normed = PyObject_CallFunctionObjArgs( | |||
|
227 | normcase_fallback, k, NULL); | |||
|
228 | } | |||
|
229 | ||||
|
230 | if (normed == NULL) | |||
|
231 | goto quit; | |||
|
232 | if (PyDict_SetItem(file_foldmap, normed, k) == -1) | |||
|
233 | goto quit; | |||
|
234 | } | |||
|
235 | } | |||
|
236 | return file_foldmap; | |||
|
237 | quit: | |||
|
238 | Py_XDECREF(file_foldmap); | |||
|
239 | return NULL; | |||
|
240 | } | |||
|
241 | ||||
176 | /* |
|
242 | /* | |
177 | * This code assumes that a manifest is stitched together with newline |
|
243 | * This code assumes that a manifest is stitched together with newline | |
178 | * ('\n') characters. |
|
244 | * ('\n') characters. | |
@@ -2463,6 +2529,8 static PyMethodDef methods[] = { | |||||
2463 | {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"}, |
|
2529 | {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"}, | |
2464 | {"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"}, |
|
2530 | {"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"}, | |
2465 | {"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"}, |
|
2531 | {"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"}, | |
|
2532 | {"make_file_foldmap", make_file_foldmap, METH_VARARGS, | |||
|
2533 | "make file foldmap\n"}, | |||
2466 | {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"}, |
|
2534 | {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"}, | |
2467 | {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"}, |
|
2535 | {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"}, | |
2468 | {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"}, |
|
2536 | {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"}, |
General Comments 0
You need to be logged in to leave comments.
Login now