##// END OF EJS Templates
parsers: allow clang-format here...
Augie Fackler -
r34863:d92dc725 default
parent child Browse files
Show More
@@ -17,7 +17,6 b' mercurial/cext/dirs.c'
17 17 mercurial/cext/manifest.c
18 18 mercurial/cext/mpatch.c
19 19 mercurial/cext/osutil.c
20 mercurial/cext/parsers.c
21 20 mercurial/cext/pathencode.c
22 21 mercurial/cext/revlog.c
23 22 # Vendored code that we should never format:
@@ -48,10 +48,8 b' static PyObject *parse_manifest(PyObject'
48 48 char *str, *start, *end;
49 49 int len;
50 50
51 if (!PyArg_ParseTuple(args, "O!O!s#:parse_manifest",
52 &PyDict_Type, &mfdict,
53 &PyDict_Type, &fdict,
54 &str, &len))
51 if (!PyArg_ParseTuple(args, "O!O!s#:parse_manifest", &PyDict_Type,
52 &mfdict, &PyDict_Type, &fdict, &str, &len))
55 53 goto quit;
56 54
57 55 start = str;
@@ -65,14 +63,14 b' static PyObject *parse_manifest(PyObject'
65 63 zero = memchr(start, '\0', end - start);
66 64 if (!zero) {
67 65 PyErr_SetString(PyExc_ValueError,
68 "manifest entry has no separator");
66 "manifest entry has no separator");
69 67 goto quit;
70 68 }
71 69
72 70 newline = memchr(zero + 1, '\n', end - (zero + 1));
73 71 if (!newline) {
74 72 PyErr_SetString(PyExc_ValueError,
75 "manifest contains trailing garbage");
73 "manifest contains trailing garbage");
76 74 goto quit;
77 75 }
78 76
@@ -88,8 +86,7 b' static PyObject *parse_manifest(PyObject'
88 86 goto bail;
89 87
90 88 if (nlen > 40) {
91 flags = PyBytes_FromStringAndSize(zero + 41,
92 nlen - 40);
89 flags = PyBytes_FromStringAndSize(zero + 41, nlen - 40);
93 90 if (!flags)
94 91 goto bail;
95 92
@@ -120,10 +117,10 b' quit:'
120 117 }
121 118
122 119 static inline dirstateTupleObject *make_dirstate_tuple(char state, int mode,
123 int size, int mtime)
120 int size, int mtime)
124 121 {
125 dirstateTupleObject *t = PyObject_New(dirstateTupleObject,
126 &dirstateTupleType);
122 dirstateTupleObject *t =
123 PyObject_New(dirstateTupleObject, &dirstateTupleType);
127 124 if (!t)
128 125 return NULL;
129 126 t->state = state;
@@ -134,7 +131,7 b' static inline dirstateTupleObject *make_'
134 131 }
135 132
136 133 static PyObject *dirstate_tuple_new(PyTypeObject *subtype, PyObject *args,
137 PyObject *kwds)
134 PyObject *kwds)
138 135 {
139 136 /* We do all the initialization here and not a tp_init function because
140 137 * dirstate_tuple is immutable. */
@@ -184,55 +181,55 b' static PyObject *dirstate_tuple_item(PyO'
184 181 }
185 182
186 183 static PySequenceMethods dirstate_tuple_sq = {
187 dirstate_tuple_length, /* sq_length */
188 0, /* sq_concat */
189 0, /* sq_repeat */
190 dirstate_tuple_item, /* sq_item */
191 0, /* sq_ass_item */
192 0, /* sq_contains */
193 0, /* sq_inplace_concat */
194 0 /* sq_inplace_repeat */
184 dirstate_tuple_length, /* sq_length */
185 0, /* sq_concat */
186 0, /* sq_repeat */
187 dirstate_tuple_item, /* sq_item */
188 0, /* sq_ass_item */
189 0, /* sq_contains */
190 0, /* sq_inplace_concat */
191 0 /* sq_inplace_repeat */
195 192 };
196 193
197 194 PyTypeObject dirstateTupleType = {
198 PyVarObject_HEAD_INIT(NULL, 0) /* header */
199 "dirstate_tuple", /* tp_name */
200 sizeof(dirstateTupleObject),/* tp_basicsize */
201 0, /* tp_itemsize */
202 (destructor)dirstate_tuple_dealloc, /* tp_dealloc */
203 0, /* tp_print */
204 0, /* tp_getattr */
205 0, /* tp_setattr */
206 0, /* tp_compare */
207 0, /* tp_repr */
208 0, /* tp_as_number */
209 &dirstate_tuple_sq, /* tp_as_sequence */
210 0, /* tp_as_mapping */
211 0, /* tp_hash */
212 0, /* tp_call */
213 0, /* tp_str */
214 0, /* tp_getattro */
215 0, /* tp_setattro */
216 0, /* tp_as_buffer */
217 Py_TPFLAGS_DEFAULT, /* tp_flags */
218 "dirstate tuple", /* tp_doc */
219 0, /* tp_traverse */
220 0, /* tp_clear */
221 0, /* tp_richcompare */
222 0, /* tp_weaklistoffset */
223 0, /* tp_iter */
224 0, /* tp_iternext */
225 0, /* tp_methods */
226 0, /* tp_members */
227 0, /* tp_getset */
228 0, /* tp_base */
229 0, /* tp_dict */
230 0, /* tp_descr_get */
231 0, /* tp_descr_set */
232 0, /* tp_dictoffset */
233 0, /* tp_init */
234 0, /* tp_alloc */
235 dirstate_tuple_new, /* tp_new */
195 PyVarObject_HEAD_INIT(NULL, 0) /* header */
196 "dirstate_tuple", /* tp_name */
197 sizeof(dirstateTupleObject), /* tp_basicsize */
198 0, /* tp_itemsize */
199 (destructor)dirstate_tuple_dealloc, /* tp_dealloc */
200 0, /* tp_print */
201 0, /* tp_getattr */
202 0, /* tp_setattr */
203 0, /* tp_compare */
204 0, /* tp_repr */
205 0, /* tp_as_number */
206 &dirstate_tuple_sq, /* tp_as_sequence */
207 0, /* tp_as_mapping */
208 0, /* tp_hash */
209 0, /* tp_call */
210 0, /* tp_str */
211 0, /* tp_getattro */
212 0, /* tp_setattro */
213 0, /* tp_as_buffer */
214 Py_TPFLAGS_DEFAULT, /* tp_flags */
215 "dirstate tuple", /* tp_doc */
216 0, /* tp_traverse */
217 0, /* tp_clear */
218 0, /* tp_richcompare */
219 0, /* tp_weaklistoffset */
220 0, /* tp_iter */
221 0, /* tp_iternext */
222 0, /* tp_methods */
223 0, /* tp_members */
224 0, /* tp_getset */
225 0, /* tp_base */
226 0, /* tp_dict */
227 0, /* tp_descr_get */
228 0, /* tp_descr_set */
229 0, /* tp_dictoffset */
230 0, /* tp_init */
231 0, /* tp_alloc */
232 dirstate_tuple_new, /* tp_new */
236 233 };
237 234
238 235 static PyObject *parse_dirstate(PyObject *self, PyObject *args)
@@ -244,18 +241,16 b' static PyObject *parse_dirstate(PyObject'
244 241 unsigned int flen, len, pos = 40;
245 242 int readlen;
246 243
247 if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate",
248 &PyDict_Type, &dmap,
249 &PyDict_Type, &cmap,
250 &str, &readlen))
244 if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", &PyDict_Type,
245 &dmap, &PyDict_Type, &cmap, &str, &readlen))
251 246 goto quit;
252 247
253 248 len = readlen;
254 249
255 250 /* read parents */
256 251 if (len < 40) {
257 PyErr_SetString(
258 PyExc_ValueError, "too little data for parents");
252 PyErr_SetString(PyExc_ValueError,
253 "too little data for parents");
259 254 goto quit;
260 255 }
261 256
@@ -267,7 +262,7 b' static PyObject *parse_dirstate(PyObject'
267 262 while (pos >= 40 && pos < len) {
268 263 if (pos + 17 > len) {
269 264 PyErr_SetString(PyExc_ValueError,
270 "overflow in dirstate");
265 "overflow in dirstate");
271 266 goto quit;
272 267 }
273 268 cur = str + pos;
@@ -280,17 +275,18 b' static PyObject *parse_dirstate(PyObject'
280 275 pos += 17;
281 276 cur += 17;
282 277 if (flen > len - pos) {
283 PyErr_SetString(PyExc_ValueError, "overflow in dirstate");
278 PyErr_SetString(PyExc_ValueError,
279 "overflow in dirstate");
284 280 goto quit;
285 281 }
286 282
287 entry = (PyObject *)make_dirstate_tuple(state, mode, size,
288 mtime);
283 entry =
284 (PyObject *)make_dirstate_tuple(state, mode, size, mtime);
289 285 cpos = memchr(cur, 0, flen);
290 286 if (cpos) {
291 287 fname = PyBytes_FromStringAndSize(cur, cpos - cur);
292 cname = PyBytes_FromStringAndSize(cpos + 1,
293 flen - (cpos - cur) - 1);
288 cname = PyBytes_FromStringAndSize(
289 cpos + 1, flen - (cpos - cur) - 1);
294 290 if (!fname || !cname ||
295 291 PyDict_SetItem(cmap, fname, cname) == -1 ||
296 292 PyDict_SetItem(dmap, fname, entry) == -1)
@@ -298,8 +294,7 b' static PyObject *parse_dirstate(PyObject'
298 294 Py_DECREF(cname);
299 295 } else {
300 296 fname = PyBytes_FromStringAndSize(cur, flen);
301 if (!fname ||
302 PyDict_SetItem(dmap, fname, entry) == -1)
297 if (!fname || PyDict_SetItem(dmap, fname, entry) == -1)
303 298 goto quit;
304 299 }
305 300 Py_DECREF(fname);
@@ -320,15 +315,14 b' quit:'
320 315
321 316 /*
322 317 * Build a set of non-normal and other parent entries from the dirstate dmap
323 */
318 */
324 319 static PyObject *nonnormalotherparententries(PyObject *self, PyObject *args)
325 320 {
326 321 PyObject *dmap, *fname, *v;
327 322 PyObject *nonnset = NULL, *otherpset = NULL, *result = NULL;
328 323 Py_ssize_t pos;
329 324
330 if (!PyArg_ParseTuple(args, "O!:nonnormalentries",
331 &PyDict_Type, &dmap))
325 if (!PyArg_ParseTuple(args, "O!:nonnormalentries", &PyDict_Type, &dmap))
332 326 goto bail;
333 327
334 328 nonnset = PySet_New(NULL);
@@ -344,7 +338,7 b' static PyObject *nonnormalotherparentent'
344 338 dirstateTupleObject *t;
345 339 if (!dirstate_tuple_check(v)) {
346 340 PyErr_SetString(PyExc_TypeError,
347 "expected a dirstate tuple");
341 "expected a dirstate tuple");
348 342 goto bail;
349 343 }
350 344 t = (dirstateTupleObject *)v;
@@ -386,9 +380,8 b' static PyObject *pack_dirstate(PyObject '
386 380 char *p, *s;
387 381 int now;
388 382
389 if (!PyArg_ParseTuple(args, "O!O!Oi:pack_dirstate",
390 &PyDict_Type, &map, &PyDict_Type, &copymap,
391 &pl, &now))
383 if (!PyArg_ParseTuple(args, "O!O!Oi:pack_dirstate", &PyDict_Type, &map,
384 &PyDict_Type, &copymap, &pl, &now))
392 385 return NULL;
393 386
394 387 if (!PySequence_Check(pl) || PySequence_Size(pl) != 2) {
@@ -408,7 +401,7 b' static PyObject *pack_dirstate(PyObject '
408 401 if (c) {
409 402 if (!PyBytes_Check(c)) {
410 403 PyErr_SetString(PyExc_TypeError,
411 "expected string key");
404 "expected string key");
412 405 goto bail;
413 406 }
414 407 nbytes += PyBytes_GET_SIZE(c) + 1;
@@ -436,7 +429,7 b' static PyObject *pack_dirstate(PyObject '
436 429 memcpy(p, s, l);
437 430 p += 20;
438 431
439 for (pos = 0; PyDict_Next(map, &pos, &k, &v); ) {
432 for (pos = 0; PyDict_Next(map, &pos, &k, &v);) {
440 433 dirstateTupleObject *tuple;
441 434 char state;
442 435 int mode, size, mtime;
@@ -446,7 +439,7 b' static PyObject *pack_dirstate(PyObject '
446 439
447 440 if (!dirstate_tuple_check(v)) {
448 441 PyErr_SetString(PyExc_TypeError,
449 "expected a dirstate tuple");
442 "expected a dirstate tuple");
450 443 goto bail;
451 444 }
452 445 tuple = (dirstateTupleObject *)v;
@@ -460,7 +453,7 b' static PyObject *pack_dirstate(PyObject '
460 453 * this. */
461 454 mtime = -1;
462 455 mtime_unset = (PyObject *)make_dirstate_tuple(
463 state, mode, size, mtime);
456 state, mode, size, mtime);
464 457 if (!mtime_unset)
465 458 goto bail;
466 459 if (PyDict_SetItem(map, k, mtime_unset) == -1)
@@ -491,7 +484,7 b' static PyObject *pack_dirstate(PyObject '
491 484 pos = p - PyBytes_AS_STRING(packobj);
492 485 if (pos != nbytes) {
493 486 PyErr_Format(PyExc_SystemError, "bad dirstate size: %ld != %ld",
494 (long)pos, (long)nbytes);
487 (long)pos, (long)nbytes);
495 488 goto bail;
496 489 }
497 490
@@ -507,8 +500,8 b' bail:'
507 500 #define USING_SHA_256 2
508 501 #define FM1_HEADER_SIZE (4 + 8 + 2 + 2 + 1 + 1 + 1)
509 502
510 static PyObject *readshas(
511 const char *source, unsigned char num, Py_ssize_t hashwidth)
503 static PyObject *readshas(const char *source, unsigned char num,
504 Py_ssize_t hashwidth)
512 505 {
513 506 int i;
514 507 PyObject *list = PyTuple_New(num);
@@ -528,7 +521,7 b' static PyObject *readshas('
528 521 }
529 522
530 523 static PyObject *fm1readmarker(const char *databegin, const char *dataend,
531 uint32_t *msize)
524 uint32_t *msize)
532 525 {
533 526 const char *data = databegin;
534 527 const char *meta;
@@ -567,7 +560,7 b' static PyObject *fm1readmarker(const cha'
567 560 if (databegin + *msize > dataend) {
568 561 goto overflow;
569 562 }
570 dataend = databegin + *msize; /* narrow down to marker size */
563 dataend = databegin + *msize; /* narrow down to marker size */
571 564
572 565 if (data + hashwidth > dataend) {
573 566 goto overflow;
@@ -631,9 +624,9 b' static PyObject *fm1readmarker(const cha'
631 624 PyTuple_SET_ITEM(tmp, 1, right);
632 625 PyTuple_SET_ITEM(metadata, i, tmp);
633 626 }
634 ret = Py_BuildValue("(OOHO(di)O)", prec, succs, flags,
635 metadata, mtime, (int)tz * 60, parents);
636 goto bail; /* return successfully */
627 ret = Py_BuildValue("(OOHO(di)O)", prec, succs, flags, metadata, mtime,
628 (int)tz * 60, parents);
629 goto bail; /* return successfully */
637 630
638 631 overflow:
639 632 PyErr_SetString(PyExc_ValueError, "overflow in obsstore");
@@ -645,7 +638,6 b' bail:'
645 638 return ret;
646 639 }
647 640
648
649 641 static PyObject *fm1readmarkers(PyObject *self, PyObject *args)
650 642 {
651 643 const char *data, *dataend;
@@ -691,29 +683,28 b' PyObject *lowerencode(PyObject *self, Py'
691 683 PyObject *parse_index2(PyObject *self, PyObject *args);
692 684
693 685 static PyMethodDef methods[] = {
694 {"pack_dirstate", pack_dirstate, METH_VARARGS, "pack a dirstate\n"},
695 {"nonnormalotherparententries", nonnormalotherparententries, METH_VARARGS,
696 "create a set containing non-normal and other parent entries of given "
697 "dirstate\n"},
698 {"parse_manifest", parse_manifest, METH_VARARGS, "parse a manifest\n"},
699 {"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"},
700 {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"},
701 {"isasciistr", isasciistr, METH_VARARGS, "check if an ASCII string\n"},
702 {"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"},
703 {"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"},
704 {"dict_new_presized", dict_new_presized, METH_VARARGS,
705 "construct a dict with an expected size\n"},
706 {"make_file_foldmap", make_file_foldmap, METH_VARARGS,
707 "make file foldmap\n"},
708 {"jsonescapeu8fast", jsonescapeu8fast, METH_VARARGS,
709 "escape a UTF-8 byte string to JSON (fast path)\n"},
710 {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"},
711 {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"},
712 {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"},
713 {"fm1readmarkers", fm1readmarkers, METH_VARARGS,
714 "parse v1 obsolete markers\n"},
715 {NULL, NULL}
716 };
686 {"pack_dirstate", pack_dirstate, METH_VARARGS, "pack a dirstate\n"},
687 {"nonnormalotherparententries", nonnormalotherparententries, METH_VARARGS,
688 "create a set containing non-normal and other parent entries of given "
689 "dirstate\n"},
690 {"parse_manifest", parse_manifest, METH_VARARGS, "parse a manifest\n"},
691 {"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"},
692 {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"},
693 {"isasciistr", isasciistr, METH_VARARGS, "check if an ASCII string\n"},
694 {"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"},
695 {"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"},
696 {"dict_new_presized", dict_new_presized, METH_VARARGS,
697 "construct a dict with an expected size\n"},
698 {"make_file_foldmap", make_file_foldmap, METH_VARARGS,
699 "make file foldmap\n"},
700 {"jsonescapeu8fast", jsonescapeu8fast, METH_VARARGS,
701 "escape a UTF-8 byte string to JSON (fast path)\n"},
702 {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"},
703 {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"},
704 {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"},
705 {"fm1readmarkers", fm1readmarkers, METH_VARARGS,
706 "parse v1 obsolete markers\n"},
707 {NULL, NULL}};
717 708
718 709 void dirs_module_init(PyObject *mod);
719 710 void manifest_module_init(PyObject *mod);
@@ -743,7 +734,7 b' static void module_init(PyObject *mod)'
743 734 return;
744 735 Py_INCREF(&dirstateTupleType);
745 736 PyModule_AddObject(mod, "dirstatetuple",
746 (PyObject *)&dirstateTupleType);
737 (PyObject *)&dirstateTupleType);
747 738 }
748 739
749 740 static int check_python_version(void)
@@ -762,24 +753,23 b' static int check_python_version(void)'
762 753 * should only occur in unusual circumstances (e.g. if sys.hexversion
763 754 * is manually set to an invalid value). */
764 755 if ((hexversion == -1) || (hexversion >> 16 != PY_VERSION_HEX >> 16)) {
765 PyErr_Format(PyExc_ImportError, "%s: The Mercurial extension "
766 "modules were compiled with Python " PY_VERSION ", but "
767 "Mercurial is currently using Python with sys.hexversion=%ld: "
768 "Python %s\n at: %s", versionerrortext, hexversion,
769 Py_GetVersion(), Py_GetProgramFullPath());
756 PyErr_Format(PyExc_ImportError,
757 "%s: The Mercurial extension "
758 "modules were compiled with Python " PY_VERSION
759 ", but "
760 "Mercurial is currently using Python with "
761 "sys.hexversion=%ld: "
762 "Python %s\n at: %s",
763 versionerrortext, hexversion, Py_GetVersion(),
764 Py_GetProgramFullPath());
770 765 return -1;
771 766 }
772 767 return 0;
773 768 }
774 769
775 770 #ifdef IS_PY3K
776 static struct PyModuleDef parsers_module = {
777 PyModuleDef_HEAD_INIT,
778 "parsers",
779 parsers_doc,
780 -1,
781 methods
782 };
771 static struct PyModuleDef parsers_module = {PyModuleDef_HEAD_INIT, "parsers",
772 parsers_doc, -1, methods};
783 773
784 774 PyMODINIT_FUNC PyInit_parsers(void)
785 775 {
General Comments 0
You need to be logged in to leave comments. Login now