skip-blame because parsers.c is mechanically rewritten by
clang-format with no semantic change.
( )
| indygreg |
| hg-reviewers |
clang-format with no semantic change.
| Automatic diff as part of commit; lint not applicable. |
| Automatic diff as part of commit; unit tests not applicable. |
To review this, I suggest removing parsers.c from the blacklist and running make format-c (see D1167) to observe that the resulting diff matches what's in this commit, rather than hand-inspecting the entire diff.
| Path | Packages | |||
|---|---|---|---|---|
| M | contrib/clang-format-blacklist (1 line) | |||
| M | mercurial/cext/parsers.c (246 lines) |
| mercurial/cext/bdiff.c | mercurial/cext/bdiff.c | ||||
| mercurial/cext/charencode.c | mercurial/cext/charencode.c | ||||
| mercurial/cext/charencode.h | mercurial/cext/charencode.h | ||||
| mercurial/cext/diffhelpers.c | mercurial/cext/diffhelpers.c | ||||
| mercurial/cext/dirs.c | mercurial/cext/dirs.c | ||||
| mercurial/cext/manifest.c | mercurial/cext/manifest.c | ||||
| mercurial/cext/mpatch.c | mercurial/cext/mpatch.c | ||||
| mercurial/cext/osutil.c | mercurial/cext/osutil.c | ||||
| mercurial/cext/parsers.c | |||||
| mercurial/cext/pathencode.c | mercurial/cext/pathencode.c | ||||
| mercurial/cext/revlog.c | mercurial/cext/revlog.c | ||||
| # Vendored code that we should never format: | # Vendored code that we should never format: | ||||
| contrib/python-zstandard/c-ext/bufferutil.c | contrib/python-zstandard/c-ext/bufferutil.c | ||||
| contrib/python-zstandard/c-ext/compressiondict.c | contrib/python-zstandard/c-ext/compressiondict.c | ||||
| contrib/python-zstandard/c-ext/compressionparams.c | contrib/python-zstandard/c-ext/compressionparams.c | ||||
| contrib/python-zstandard/c-ext/compressionwriter.c | contrib/python-zstandard/c-ext/compressionwriter.c | ||||
| contrib/python-zstandard/c-ext/compressobj.c | contrib/python-zstandard/c-ext/compressobj.c | ||||
| * ('\n') characters. | * ('\n') characters. | ||||
| */ | */ | ||||
| static PyObject *parse_manifest(PyObject *self, PyObject *args) | static PyObject *parse_manifest(PyObject *self, PyObject *args) | ||||
| { | { | ||||
| PyObject *mfdict, *fdict; | PyObject *mfdict, *fdict; | ||||
| char *str, *start, *end; | char *str, *start, *end; | ||||
| int len; | int len; | ||||
| if (!PyArg_ParseTuple(args, "O!O!s#:parse_manifest", | if (!PyArg_ParseTuple(args, "O!O!s#:parse_manifest", &PyDict_Type, | ||||
| &PyDict_Type, &mfdict, | &mfdict, &PyDict_Type, &fdict, &str, &len)) | ||||
| &PyDict_Type, &fdict, | |||||
| &str, &len)) | |||||
| goto quit; | goto quit; | ||||
| start = str; | start = str; | ||||
| end = str + len; | end = str + len; | ||||
| while (start < end) { | while (start < end) { | ||||
| PyObject *file = NULL, *node = NULL; | PyObject *file = NULL, *node = NULL; | ||||
| PyObject *flags = NULL; | PyObject *flags = NULL; | ||||
| char *zero = NULL, *newline = NULL; | char *zero = NULL, *newline = NULL; | ||||
| ptrdiff_t nlen; | ptrdiff_t nlen; | ||||
| zero = memchr(start, '\0', end - start); | zero = memchr(start, '\0', end - start); | ||||
| if (!zero) { | if (!zero) { | ||||
| PyErr_SetString(PyExc_ValueError, | PyErr_SetString(PyExc_ValueError, | ||||
| "manifest entry has no separator"); | "manifest entry has no separator"); | ||||
| goto quit; | goto quit; | ||||
| } | } | ||||
| newline = memchr(zero + 1, '\n', end - (zero + 1)); | newline = memchr(zero + 1, '\n', end - (zero + 1)); | ||||
| if (!newline) { | if (!newline) { | ||||
| PyErr_SetString(PyExc_ValueError, | PyErr_SetString(PyExc_ValueError, | ||||
| "manifest contains trailing garbage"); | "manifest contains trailing garbage"); | ||||
| goto quit; | goto quit; | ||||
| } | } | ||||
| file = PyBytes_FromStringAndSize(start, zero - start); | file = PyBytes_FromStringAndSize(start, zero - start); | ||||
| if (!file) | if (!file) | ||||
| goto bail; | goto bail; | ||||
| nlen = newline - zero - 1; | nlen = newline - zero - 1; | ||||
| node = unhexlify(zero + 1, nlen > 40 ? 40 : (Py_ssize_t)nlen); | node = unhexlify(zero + 1, nlen > 40 ? 40 : (Py_ssize_t)nlen); | ||||
| if (!node) | if (!node) | ||||
| goto bail; | goto bail; | ||||
| if (nlen > 40) { | if (nlen > 40) { | ||||
| flags = PyBytes_FromStringAndSize(zero + 41, | flags = PyBytes_FromStringAndSize(zero + 41, nlen - 40); | ||||
| nlen - 40); | |||||
| if (!flags) | if (!flags) | ||||
| goto bail; | goto bail; | ||||
| if (PyDict_SetItem(fdict, file, flags) == -1) | if (PyDict_SetItem(fdict, file, flags) == -1) | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| if (PyDict_SetItem(mfdict, file, node) == -1) | if (PyDict_SetItem(mfdict, file, node) == -1) | ||||
| Py_INCREF(Py_None); | Py_INCREF(Py_None); | ||||
| return Py_None; | return Py_None; | ||||
| quit: | quit: | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static inline dirstateTupleObject *make_dirstate_tuple(char state, int mode, | static inline dirstateTupleObject *make_dirstate_tuple(char state, int mode, | ||||
| int size, int mtime) | int size, int mtime) | ||||
| { | { | ||||
| dirstateTupleObject *t = PyObject_New(dirstateTupleObject, | dirstateTupleObject *t = | ||||
| &dirstateTupleType); | PyObject_New(dirstateTupleObject, &dirstateTupleType); | ||||
| if (!t) | if (!t) | ||||
| return NULL; | return NULL; | ||||
| t->state = state; | t->state = state; | ||||
| t->mode = mode; | t->mode = mode; | ||||
| t->size = size; | t->size = size; | ||||
| t->mtime = mtime; | t->mtime = mtime; | ||||
| return t; | return t; | ||||
| } | } | ||||
| static PyObject *dirstate_tuple_new(PyTypeObject *subtype, PyObject *args, | static PyObject *dirstate_tuple_new(PyTypeObject *subtype, PyObject *args, | ||||
| PyObject *kwds) | PyObject *kwds) | ||||
| { | { | ||||
| /* We do all the initialization here and not a tp_init function because | /* We do all the initialization here and not a tp_init function because | ||||
| * dirstate_tuple is immutable. */ | * dirstate_tuple is immutable. */ | ||||
| dirstateTupleObject *t; | dirstateTupleObject *t; | ||||
| char state; | char state; | ||||
| int size, mode, mtime; | int size, mode, mtime; | ||||
| if (!PyArg_ParseTuple(args, "ciii", &state, &mode, &size, &mtime)) | if (!PyArg_ParseTuple(args, "ciii", &state, &mode, &size, &mtime)) | ||||
| return NULL; | return NULL; | ||||
| return PyInt_FromLong(t->mtime); | return PyInt_FromLong(t->mtime); | ||||
| default: | default: | ||||
| PyErr_SetString(PyExc_IndexError, "index out of range"); | PyErr_SetString(PyExc_IndexError, "index out of range"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| } | } | ||||
| static PySequenceMethods dirstate_tuple_sq = { | static PySequenceMethods dirstate_tuple_sq = { | ||||
| dirstate_tuple_length, /* sq_length */ | dirstate_tuple_length, /* sq_length */ | ||||
| 0, /* sq_concat */ | 0, /* sq_concat */ | ||||
| 0, /* sq_repeat */ | 0, /* sq_repeat */ | ||||
| dirstate_tuple_item, /* sq_item */ | dirstate_tuple_item, /* sq_item */ | ||||
| 0, /* sq_ass_item */ | 0, /* sq_ass_item */ | ||||
| 0, /* sq_contains */ | 0, /* sq_contains */ | ||||
| 0, /* sq_inplace_concat */ | 0, /* sq_inplace_concat */ | ||||
| 0 /* sq_inplace_repeat */ | 0 /* sq_inplace_repeat */ | ||||
| }; | }; | ||||
| PyTypeObject dirstateTupleType = { | PyTypeObject dirstateTupleType = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) /* header */ | PyVarObject_HEAD_INIT(NULL, 0) /* header */ | ||||
| "dirstate_tuple", /* tp_name */ | "dirstate_tuple", /* tp_name */ | ||||
| sizeof(dirstateTupleObject),/* tp_basicsize */ | sizeof(dirstateTupleObject), /* tp_basicsize */ | ||||
| 0, /* tp_itemsize */ | 0, /* tp_itemsize */ | ||||
| (destructor)dirstate_tuple_dealloc, /* tp_dealloc */ | (destructor)dirstate_tuple_dealloc, /* tp_dealloc */ | ||||
| 0, /* tp_print */ | 0, /* tp_print */ | ||||
| 0, /* tp_getattr */ | 0, /* tp_getattr */ | ||||
| 0, /* tp_setattr */ | 0, /* tp_setattr */ | ||||
| 0, /* tp_compare */ | 0, /* tp_compare */ | ||||
| 0, /* tp_repr */ | 0, /* tp_repr */ | ||||
| 0, /* tp_as_number */ | 0, /* tp_as_number */ | ||||
| &dirstate_tuple_sq, /* tp_as_sequence */ | &dirstate_tuple_sq, /* tp_as_sequence */ | ||||
| 0, /* tp_as_mapping */ | 0, /* tp_as_mapping */ | ||||
| 0, /* tp_hash */ | 0, /* tp_hash */ | ||||
| 0, /* tp_call */ | 0, /* tp_call */ | ||||
| 0, /* tp_str */ | 0, /* tp_str */ | ||||
| 0, /* tp_getattro */ | 0, /* tp_getattro */ | ||||
| 0, /* tp_setattro */ | 0, /* tp_setattro */ | ||||
| 0, /* tp_as_buffer */ | 0, /* tp_as_buffer */ | ||||
| Py_TPFLAGS_DEFAULT, /* tp_flags */ | Py_TPFLAGS_DEFAULT, /* tp_flags */ | ||||
| "dirstate tuple", /* tp_doc */ | "dirstate tuple", /* tp_doc */ | ||||
| 0, /* tp_traverse */ | 0, /* tp_traverse */ | ||||
| 0, /* tp_clear */ | 0, /* tp_clear */ | ||||
| 0, /* tp_richcompare */ | 0, /* tp_richcompare */ | ||||
| 0, /* tp_weaklistoffset */ | 0, /* tp_weaklistoffset */ | ||||
| 0, /* tp_iter */ | 0, /* tp_iter */ | ||||
| 0, /* tp_iternext */ | 0, /* tp_iternext */ | ||||
| 0, /* tp_methods */ | 0, /* tp_methods */ | ||||
| 0, /* tp_members */ | 0, /* tp_members */ | ||||
| 0, /* tp_getset */ | 0, /* tp_getset */ | ||||
| 0, /* tp_base */ | 0, /* tp_base */ | ||||
| 0, /* tp_dict */ | 0, /* tp_dict */ | ||||
| 0, /* tp_descr_get */ | 0, /* tp_descr_get */ | ||||
| 0, /* tp_descr_set */ | 0, /* tp_descr_set */ | ||||
| 0, /* tp_dictoffset */ | 0, /* tp_dictoffset */ | ||||
| 0, /* tp_init */ | 0, /* tp_init */ | ||||
| 0, /* tp_alloc */ | 0, /* tp_alloc */ | ||||
| dirstate_tuple_new, /* tp_new */ | dirstate_tuple_new, /* tp_new */ | ||||
| }; | }; | ||||
| static PyObject *parse_dirstate(PyObject *self, PyObject *args) | static PyObject *parse_dirstate(PyObject *self, PyObject *args) | ||||
| { | { | ||||
| PyObject *dmap, *cmap, *parents = NULL, *ret = NULL; | PyObject *dmap, *cmap, *parents = NULL, *ret = NULL; | ||||
| PyObject *fname = NULL, *cname = NULL, *entry = NULL; | PyObject *fname = NULL, *cname = NULL, *entry = NULL; | ||||
| char state, *cur, *str, *cpos; | char state, *cur, *str, *cpos; | ||||
| int mode, size, mtime; | int mode, size, mtime; | ||||
| unsigned int flen, len, pos = 40; | unsigned int flen, len, pos = 40; | ||||
| int readlen; | int readlen; | ||||
| if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", | if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", &PyDict_Type, | ||||
| &PyDict_Type, &dmap, | &dmap, &PyDict_Type, &cmap, &str, &readlen)) | ||||
| &PyDict_Type, &cmap, | |||||
| &str, &readlen)) | |||||
| goto quit; | goto quit; | ||||
| len = readlen; | len = readlen; | ||||
| /* read parents */ | /* read parents */ | ||||
| if (len < 40) { | if (len < 40) { | ||||
| PyErr_SetString( | PyErr_SetString(PyExc_ValueError, | ||||
| PyExc_ValueError, "too little data for parents"); | "too little data for parents"); | ||||
| goto quit; | goto quit; | ||||
| } | } | ||||
| parents = Py_BuildValue("s#s#", str, 20, str + 20, 20); | parents = Py_BuildValue("s#s#", str, 20, str + 20, 20); | ||||
| if (!parents) | if (!parents) | ||||
| goto quit; | goto quit; | ||||
| /* read filenames */ | /* read filenames */ | ||||
| while (pos >= 40 && pos < len) { | while (pos >= 40 && pos < len) { | ||||
| if (pos + 17 > len) { | if (pos + 17 > len) { | ||||
| PyErr_SetString(PyExc_ValueError, | PyErr_SetString(PyExc_ValueError, | ||||
| "overflow in dirstate"); | "overflow in dirstate"); | ||||
| goto quit; | goto quit; | ||||
| } | } | ||||
| cur = str + pos; | cur = str + pos; | ||||
| /* unpack header */ | /* unpack header */ | ||||
| state = *cur; | state = *cur; | ||||
| mode = getbe32(cur + 1); | mode = getbe32(cur + 1); | ||||
| size = getbe32(cur + 5); | size = getbe32(cur + 5); | ||||
| mtime = getbe32(cur + 9); | mtime = getbe32(cur + 9); | ||||
| flen = getbe32(cur + 13); | flen = getbe32(cur + 13); | ||||
| pos += 17; | pos += 17; | ||||
| cur += 17; | cur += 17; | ||||
| if (flen > len - pos) { | if (flen > len - pos) { | ||||
| PyErr_SetString(PyExc_ValueError, "overflow in dirstate"); | PyErr_SetString(PyExc_ValueError, | ||||
| "overflow in dirstate"); | |||||
| goto quit; | goto quit; | ||||
| } | } | ||||
| entry = (PyObject *)make_dirstate_tuple(state, mode, size, | entry = | ||||
| mtime); | (PyObject *)make_dirstate_tuple(state, mode, size, mtime); | ||||
| cpos = memchr(cur, 0, flen); | cpos = memchr(cur, 0, flen); | ||||
| if (cpos) { | if (cpos) { | ||||
| fname = PyBytes_FromStringAndSize(cur, cpos - cur); | fname = PyBytes_FromStringAndSize(cur, cpos - cur); | ||||
| cname = PyBytes_FromStringAndSize(cpos + 1, | cname = PyBytes_FromStringAndSize( | ||||
| flen - (cpos - cur) - 1); | cpos + 1, flen - (cpos - cur) - 1); | ||||
| if (!fname || !cname || | if (!fname || !cname || | ||||
| PyDict_SetItem(cmap, fname, cname) == -1 || | PyDict_SetItem(cmap, fname, cname) == -1 || | ||||
| PyDict_SetItem(dmap, fname, entry) == -1) | PyDict_SetItem(dmap, fname, entry) == -1) | ||||
| goto quit; | goto quit; | ||||
| Py_DECREF(cname); | Py_DECREF(cname); | ||||
| } else { | } else { | ||||
| fname = PyBytes_FromStringAndSize(cur, flen); | fname = PyBytes_FromStringAndSize(cur, flen); | ||||
| if (!fname || | if (!fname || PyDict_SetItem(dmap, fname, entry) == -1) | ||||
| PyDict_SetItem(dmap, fname, entry) == -1) | |||||
| goto quit; | goto quit; | ||||
| } | } | ||||
| Py_DECREF(fname); | Py_DECREF(fname); | ||||
| Py_DECREF(entry); | Py_DECREF(entry); | ||||
| fname = cname = entry = NULL; | fname = cname = entry = NULL; | ||||
| pos += flen; | pos += flen; | ||||
| } | } | ||||
| ret = parents; | ret = parents; | ||||
| Py_INCREF(ret); | Py_INCREF(ret); | ||||
| quit: | quit: | ||||
| Py_XDECREF(fname); | Py_XDECREF(fname); | ||||
| Py_XDECREF(cname); | Py_XDECREF(cname); | ||||
| Py_XDECREF(entry); | Py_XDECREF(entry); | ||||
| Py_XDECREF(parents); | Py_XDECREF(parents); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| /* | /* | ||||
| * Build a set of non-normal and other parent entries from the dirstate dmap | * Build a set of non-normal and other parent entries from the dirstate dmap | ||||
| */ | */ | ||||
| static PyObject *nonnormalotherparententries(PyObject *self, PyObject *args) | static PyObject *nonnormalotherparententries(PyObject *self, PyObject *args) | ||||
| { | { | ||||
| PyObject *dmap, *fname, *v; | PyObject *dmap, *fname, *v; | ||||
| PyObject *nonnset = NULL, *otherpset = NULL, *result = NULL; | PyObject *nonnset = NULL, *otherpset = NULL, *result = NULL; | ||||
| Py_ssize_t pos; | Py_ssize_t pos; | ||||
| if (!PyArg_ParseTuple(args, "O!:nonnormalentries", | if (!PyArg_ParseTuple(args, "O!:nonnormalentries", &PyDict_Type, &dmap)) | ||||
| &PyDict_Type, &dmap)) | |||||
| goto bail; | goto bail; | ||||
| nonnset = PySet_New(NULL); | nonnset = PySet_New(NULL); | ||||
| if (nonnset == NULL) | if (nonnset == NULL) | ||||
| goto bail; | goto bail; | ||||
| otherpset = PySet_New(NULL); | otherpset = PySet_New(NULL); | ||||
| if (otherpset == NULL) | if (otherpset == NULL) | ||||
| goto bail; | goto bail; | ||||
| pos = 0; | pos = 0; | ||||
| while (PyDict_Next(dmap, &pos, &fname, &v)) { | while (PyDict_Next(dmap, &pos, &fname, &v)) { | ||||
| dirstateTupleObject *t; | dirstateTupleObject *t; | ||||
| if (!dirstate_tuple_check(v)) { | if (!dirstate_tuple_check(v)) { | ||||
| PyErr_SetString(PyExc_TypeError, | PyErr_SetString(PyExc_TypeError, | ||||
| "expected a dirstate tuple"); | "expected a dirstate tuple"); | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| t = (dirstateTupleObject *)v; | t = (dirstateTupleObject *)v; | ||||
| if (t->state == 'n' && t->size == -2) { | if (t->state == 'n' && t->size == -2) { | ||||
| if (PySet_Add(otherpset, fname) == -1) { | if (PySet_Add(otherpset, fname) == -1) { | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| { | { | ||||
| PyObject *packobj = NULL; | PyObject *packobj = NULL; | ||||
| PyObject *map, *copymap, *pl, *mtime_unset = NULL; | PyObject *map, *copymap, *pl, *mtime_unset = NULL; | ||||
| Py_ssize_t nbytes, pos, l; | Py_ssize_t nbytes, pos, l; | ||||
| PyObject *k, *v = NULL, *pn; | PyObject *k, *v = NULL, *pn; | ||||
| char *p, *s; | char *p, *s; | ||||
| int now; | int now; | ||||
| if (!PyArg_ParseTuple(args, "O!O!Oi:pack_dirstate", | if (!PyArg_ParseTuple(args, "O!O!Oi:pack_dirstate", &PyDict_Type, &map, | ||||
| &PyDict_Type, &map, &PyDict_Type, ©map, | &PyDict_Type, ©map, &pl, &now)) | ||||
| &pl, &now)) | |||||
| return NULL; | return NULL; | ||||
| if (!PySequence_Check(pl) || PySequence_Size(pl) != 2) { | if (!PySequence_Check(pl) || PySequence_Size(pl) != 2) { | ||||
| PyErr_SetString(PyExc_TypeError, "expected 2-element sequence"); | PyErr_SetString(PyExc_TypeError, "expected 2-element sequence"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* Figure out how much we need to allocate. */ | /* Figure out how much we need to allocate. */ | ||||
| for (nbytes = 40, pos = 0; PyDict_Next(map, &pos, &k, &v);) { | for (nbytes = 40, pos = 0; PyDict_Next(map, &pos, &k, &v);) { | ||||
| PyObject *c; | PyObject *c; | ||||
| if (!PyBytes_Check(k)) { | if (!PyBytes_Check(k)) { | ||||
| PyErr_SetString(PyExc_TypeError, "expected string key"); | PyErr_SetString(PyExc_TypeError, "expected string key"); | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| nbytes += PyBytes_GET_SIZE(k) + 17; | nbytes += PyBytes_GET_SIZE(k) + 17; | ||||
| c = PyDict_GetItem(copymap, k); | c = PyDict_GetItem(copymap, k); | ||||
| if (c) { | if (c) { | ||||
| if (!PyBytes_Check(c)) { | if (!PyBytes_Check(c)) { | ||||
| PyErr_SetString(PyExc_TypeError, | PyErr_SetString(PyExc_TypeError, | ||||
| "expected string key"); | "expected string key"); | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| nbytes += PyBytes_GET_SIZE(c) + 1; | nbytes += PyBytes_GET_SIZE(c) + 1; | ||||
| } | } | ||||
| } | } | ||||
| packobj = PyBytes_FromStringAndSize(NULL, nbytes); | packobj = PyBytes_FromStringAndSize(NULL, nbytes); | ||||
| if (packobj == NULL) | if (packobj == NULL) | ||||
| pn = PySequence_ITEM(pl, 1); | pn = PySequence_ITEM(pl, 1); | ||||
| if (PyBytes_AsStringAndSize(pn, &s, &l) == -1 || l != 20) { | if (PyBytes_AsStringAndSize(pn, &s, &l) == -1 || l != 20) { | ||||
| PyErr_SetString(PyExc_TypeError, "expected a 20-byte hash"); | PyErr_SetString(PyExc_TypeError, "expected a 20-byte hash"); | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| memcpy(p, s, l); | memcpy(p, s, l); | ||||
| p += 20; | p += 20; | ||||
| for (pos = 0; PyDict_Next(map, &pos, &k, &v); ) { | for (pos = 0; PyDict_Next(map, &pos, &k, &v);) { | ||||
| dirstateTupleObject *tuple; | dirstateTupleObject *tuple; | ||||
| char state; | char state; | ||||
| int mode, size, mtime; | int mode, size, mtime; | ||||
| Py_ssize_t len, l; | Py_ssize_t len, l; | ||||
| PyObject *o; | PyObject *o; | ||||
| char *t; | char *t; | ||||
| if (!dirstate_tuple_check(v)) { | if (!dirstate_tuple_check(v)) { | ||||
| PyErr_SetString(PyExc_TypeError, | PyErr_SetString(PyExc_TypeError, | ||||
| "expected a dirstate tuple"); | "expected a dirstate tuple"); | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| tuple = (dirstateTupleObject *)v; | tuple = (dirstateTupleObject *)v; | ||||
| state = tuple->state; | state = tuple->state; | ||||
| mode = tuple->mode; | mode = tuple->mode; | ||||
| size = tuple->size; | size = tuple->size; | ||||
| mtime = tuple->mtime; | mtime = tuple->mtime; | ||||
| if (state == 'n' && mtime == now) { | if (state == 'n' && mtime == now) { | ||||
| /* See pure/parsers.py:pack_dirstate for why we do | /* See pure/parsers.py:pack_dirstate for why we do | ||||
| * this. */ | * this. */ | ||||
| mtime = -1; | mtime = -1; | ||||
| mtime_unset = (PyObject *)make_dirstate_tuple( | mtime_unset = (PyObject *)make_dirstate_tuple( | ||||
| state, mode, size, mtime); | state, mode, size, mtime); | ||||
| if (!mtime_unset) | if (!mtime_unset) | ||||
| goto bail; | goto bail; | ||||
| if (PyDict_SetItem(map, k, mtime_unset) == -1) | if (PyDict_SetItem(map, k, mtime_unset) == -1) | ||||
| goto bail; | goto bail; | ||||
| Py_DECREF(mtime_unset); | Py_DECREF(mtime_unset); | ||||
| mtime_unset = NULL; | mtime_unset = NULL; | ||||
| } | } | ||||
| *p++ = state; | *p++ = state; | ||||
| len += l + 1; | len += l + 1; | ||||
| } | } | ||||
| putbe32((uint32_t)len, t); | putbe32((uint32_t)len, t); | ||||
| } | } | ||||
| pos = p - PyBytes_AS_STRING(packobj); | pos = p - PyBytes_AS_STRING(packobj); | ||||
| if (pos != nbytes) { | if (pos != nbytes) { | ||||
| PyErr_Format(PyExc_SystemError, "bad dirstate size: %ld != %ld", | PyErr_Format(PyExc_SystemError, "bad dirstate size: %ld != %ld", | ||||
| (long)pos, (long)nbytes); | (long)pos, (long)nbytes); | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| return packobj; | return packobj; | ||||
| bail: | bail: | ||||
| Py_XDECREF(mtime_unset); | Py_XDECREF(mtime_unset); | ||||
| Py_XDECREF(packobj); | Py_XDECREF(packobj); | ||||
| Py_XDECREF(v); | Py_XDECREF(v); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| #define BUMPED_FIX 1 | #define BUMPED_FIX 1 | ||||
| #define USING_SHA_256 2 | #define USING_SHA_256 2 | ||||
| #define FM1_HEADER_SIZE (4 + 8 + 2 + 2 + 1 + 1 + 1) | #define FM1_HEADER_SIZE (4 + 8 + 2 + 2 + 1 + 1 + 1) | ||||
| static PyObject *readshas( | static PyObject *readshas(const char *source, unsigned char num, | ||||
| const char *source, unsigned char num, Py_ssize_t hashwidth) | Py_ssize_t hashwidth) | ||||
| { | { | ||||
| int i; | int i; | ||||
| PyObject *list = PyTuple_New(num); | PyObject *list = PyTuple_New(num); | ||||
| if (list == NULL) { | if (list == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| for (i = 0; i < num; i++) { | for (i = 0; i < num; i++) { | ||||
| PyObject *hash = PyBytes_FromStringAndSize(source, hashwidth); | PyObject *hash = PyBytes_FromStringAndSize(source, hashwidth); | ||||
| if (hash == NULL) { | if (hash == NULL) { | ||||
| Py_DECREF(list); | Py_DECREF(list); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| PyTuple_SET_ITEM(list, i, hash); | PyTuple_SET_ITEM(list, i, hash); | ||||
| source += hashwidth; | source += hashwidth; | ||||
| } | } | ||||
| return list; | return list; | ||||
| } | } | ||||
| static PyObject *fm1readmarker(const char *databegin, const char *dataend, | static PyObject *fm1readmarker(const char *databegin, const char *dataend, | ||||
| uint32_t *msize) | uint32_t *msize) | ||||
| { | { | ||||
| const char *data = databegin; | const char *data = databegin; | ||||
| const char *meta; | const char *meta; | ||||
| double mtime; | double mtime; | ||||
| int16_t tz; | int16_t tz; | ||||
| uint16_t flags; | uint16_t flags; | ||||
| unsigned char nsuccs, nparents, nmetadata; | unsigned char nsuccs, nparents, nmetadata; | ||||
| nsuccs = (unsigned char)(*data++); | nsuccs = (unsigned char)(*data++); | ||||
| nparents = (unsigned char)(*data++); | nparents = (unsigned char)(*data++); | ||||
| nmetadata = (unsigned char)(*data++); | nmetadata = (unsigned char)(*data++); | ||||
| if (databegin + *msize > dataend) { | if (databegin + *msize > dataend) { | ||||
| goto overflow; | goto overflow; | ||||
| } | } | ||||
| dataend = databegin + *msize; /* narrow down to marker size */ | dataend = databegin + *msize; /* narrow down to marker size */ | ||||
| if (data + hashwidth > dataend) { | if (data + hashwidth > dataend) { | ||||
| goto overflow; | goto overflow; | ||||
| } | } | ||||
| prec = PyBytes_FromStringAndSize(data, hashwidth); | prec = PyBytes_FromStringAndSize(data, hashwidth); | ||||
| data += hashwidth; | data += hashwidth; | ||||
| if (prec == NULL) { | if (prec == NULL) { | ||||
| goto bail; | goto bail; | ||||
| Py_XDECREF(right); | Py_XDECREF(right); | ||||
| Py_XDECREF(tmp); | Py_XDECREF(tmp); | ||||
| goto bail; | goto bail; | ||||
| } | } | ||||
| PyTuple_SET_ITEM(tmp, 0, left); | PyTuple_SET_ITEM(tmp, 0, left); | ||||
| PyTuple_SET_ITEM(tmp, 1, right); | PyTuple_SET_ITEM(tmp, 1, right); | ||||
| PyTuple_SET_ITEM(metadata, i, tmp); | PyTuple_SET_ITEM(metadata, i, tmp); | ||||
| } | } | ||||
| ret = Py_BuildValue("(OOHO(di)O)", prec, succs, flags, | ret = Py_BuildValue("(OOHO(di)O)", prec, succs, flags, metadata, mtime, | ||||
| metadata, mtime, (int)tz * 60, parents); | (int)tz * 60, parents); | ||||
| goto bail; /* return successfully */ | goto bail; /* return successfully */ | ||||
| overflow: | overflow: | ||||
| PyErr_SetString(PyExc_ValueError, "overflow in obsstore"); | PyErr_SetString(PyExc_ValueError, "overflow in obsstore"); | ||||
| bail: | bail: | ||||
| Py_XDECREF(prec); | Py_XDECREF(prec); | ||||
| Py_XDECREF(succs); | Py_XDECREF(succs); | ||||
| Py_XDECREF(metadata); | Py_XDECREF(metadata); | ||||
| Py_XDECREF(parents); | Py_XDECREF(parents); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| static PyObject *fm1readmarkers(PyObject *self, PyObject *args) | static PyObject *fm1readmarkers(PyObject *self, PyObject *args) | ||||
| { | { | ||||
| const char *data, *dataend; | const char *data, *dataend; | ||||
| int datalen; | int datalen; | ||||
| Py_ssize_t offset, stop; | Py_ssize_t offset, stop; | ||||
| PyObject *markers = NULL; | PyObject *markers = NULL; | ||||
| if (!PyArg_ParseTuple(args, "s#nn", &data, &datalen, &offset, &stop)) { | if (!PyArg_ParseTuple(args, "s#nn", &data, &datalen, &offset, &stop)) { | ||||
| static char parsers_doc[] = "Efficient content parsing."; | static char parsers_doc[] = "Efficient content parsing."; | ||||
| PyObject *encodedir(PyObject *self, PyObject *args); | PyObject *encodedir(PyObject *self, PyObject *args); | ||||
| PyObject *pathencode(PyObject *self, PyObject *args); | PyObject *pathencode(PyObject *self, PyObject *args); | ||||
| PyObject *lowerencode(PyObject *self, PyObject *args); | PyObject *lowerencode(PyObject *self, PyObject *args); | ||||
| PyObject *parse_index2(PyObject *self, PyObject *args); | PyObject *parse_index2(PyObject *self, PyObject *args); | ||||
| static PyMethodDef methods[] = { | static PyMethodDef methods[] = { | ||||
| {"pack_dirstate", pack_dirstate, METH_VARARGS, "pack a dirstate\n"}, | {"pack_dirstate", pack_dirstate, METH_VARARGS, "pack a dirstate\n"}, | ||||
| {"nonnormalotherparententries", nonnormalotherparententries, METH_VARARGS, | {"nonnormalotherparententries", nonnormalotherparententries, METH_VARARGS, | ||||
| "create a set containing non-normal and other parent entries of given " | "create a set containing non-normal and other parent entries of given " | ||||
| "dirstate\n"}, | "dirstate\n"}, | ||||
| {"parse_manifest", parse_manifest, METH_VARARGS, "parse a manifest\n"}, | {"parse_manifest", parse_manifest, METH_VARARGS, "parse a manifest\n"}, | ||||
| {"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"}, | {"parse_dirstate", parse_dirstate, METH_VARARGS, "parse a dirstate\n"}, | ||||
| {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"}, | {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"}, | ||||
| {"isasciistr", isasciistr, METH_VARARGS, "check if an ASCII string\n"}, | {"isasciistr", isasciistr, METH_VARARGS, "check if an ASCII string\n"}, | ||||
| {"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"}, | {"asciilower", asciilower, METH_VARARGS, "lowercase an ASCII string\n"}, | ||||
| {"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"}, | {"asciiupper", asciiupper, METH_VARARGS, "uppercase an ASCII string\n"}, | ||||
| {"dict_new_presized", dict_new_presized, METH_VARARGS, | {"dict_new_presized", dict_new_presized, METH_VARARGS, | ||||
| "construct a dict with an expected size\n"}, | "construct a dict with an expected size\n"}, | ||||
| {"make_file_foldmap", make_file_foldmap, METH_VARARGS, | {"make_file_foldmap", make_file_foldmap, METH_VARARGS, | ||||
| "make file foldmap\n"}, | "make file foldmap\n"}, | ||||
| {"jsonescapeu8fast", jsonescapeu8fast, METH_VARARGS, | {"jsonescapeu8fast", jsonescapeu8fast, METH_VARARGS, | ||||
| "escape a UTF-8 byte string to JSON (fast path)\n"}, | "escape a UTF-8 byte string to JSON (fast path)\n"}, | ||||
| {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"}, | {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"}, | ||||
| {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"}, | {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"}, | ||||
| {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"}, | {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"}, | ||||
| {"fm1readmarkers", fm1readmarkers, METH_VARARGS, | {"fm1readmarkers", fm1readmarkers, METH_VARARGS, | ||||
| "parse v1 obsolete markers\n"}, | "parse v1 obsolete markers\n"}, | ||||
| {NULL, NULL} | {NULL, NULL}}; | ||||
| }; | |||||
| void dirs_module_init(PyObject *mod); | void dirs_module_init(PyObject *mod); | ||||
| void manifest_module_init(PyObject *mod); | void manifest_module_init(PyObject *mod); | ||||
| void revlog_module_init(PyObject *mod); | void revlog_module_init(PyObject *mod); | ||||
| static const int version = 3; | static const int version = 3; | ||||
| static void module_init(PyObject *mod) | static void module_init(PyObject *mod) | ||||
| dirs_module_init(mod); | dirs_module_init(mod); | ||||
| manifest_module_init(mod); | manifest_module_init(mod); | ||||
| revlog_module_init(mod); | revlog_module_init(mod); | ||||
| if (PyType_Ready(&dirstateTupleType) < 0) | if (PyType_Ready(&dirstateTupleType) < 0) | ||||
| return; | return; | ||||
| Py_INCREF(&dirstateTupleType); | Py_INCREF(&dirstateTupleType); | ||||
| PyModule_AddObject(mod, "dirstatetuple", | PyModule_AddObject(mod, "dirstatetuple", | ||||
| (PyObject *)&dirstateTupleType); | (PyObject *)&dirstateTupleType); | ||||
| } | } | ||||
| static int check_python_version(void) | static int check_python_version(void) | ||||
| { | { | ||||
| PyObject *sys = PyImport_ImportModule("sys"), *ver; | PyObject *sys = PyImport_ImportModule("sys"), *ver; | ||||
| long hexversion; | long hexversion; | ||||
| if (!sys) | if (!sys) | ||||
| return -1; | return -1; | ||||
| ver = PyObject_GetAttrString(sys, "hexversion"); | ver = PyObject_GetAttrString(sys, "hexversion"); | ||||
| Py_DECREF(sys); | Py_DECREF(sys); | ||||
| if (!ver) | if (!ver) | ||||
| return -1; | return -1; | ||||
| hexversion = PyInt_AsLong(ver); | hexversion = PyInt_AsLong(ver); | ||||
| Py_DECREF(ver); | Py_DECREF(ver); | ||||
| /* sys.hexversion is a 32-bit number by default, so the -1 case | /* sys.hexversion is a 32-bit number by default, so the -1 case | ||||
| * should only occur in unusual circumstances (e.g. if sys.hexversion | * should only occur in unusual circumstances (e.g. if sys.hexversion | ||||
| * is manually set to an invalid value). */ | * is manually set to an invalid value). */ | ||||
| if ((hexversion == -1) || (hexversion >> 16 != PY_VERSION_HEX >> 16)) { | if ((hexversion == -1) || (hexversion >> 16 != PY_VERSION_HEX >> 16)) { | ||||
| PyErr_Format(PyExc_ImportError, "%s: The Mercurial extension " | PyErr_Format(PyExc_ImportError, | ||||
| "modules were compiled with Python " PY_VERSION ", but " | "%s: The Mercurial extension " | ||||
| "Mercurial is currently using Python with sys.hexversion=%ld: " | "modules were compiled with Python " PY_VERSION | ||||
| "Python %s\n at: %s", versionerrortext, hexversion, | ", but " | ||||
| Py_GetVersion(), Py_GetProgramFullPath()); | "Mercurial is currently using Python with " | ||||
| "sys.hexversion=%ld: " | |||||
| "Python %s\n at: %s", | |||||
| versionerrortext, hexversion, Py_GetVersion(), | |||||
| Py_GetProgramFullPath()); | |||||
| return -1; | return -1; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| #ifdef IS_PY3K | #ifdef IS_PY3K | ||||
| static struct PyModuleDef parsers_module = { | static struct PyModuleDef parsers_module = {PyModuleDef_HEAD_INIT, "parsers", | ||||
| PyModuleDef_HEAD_INIT, | parsers_doc, -1, methods}; | ||||
| "parsers", | |||||
| parsers_doc, | |||||
| -1, | |||||
| methods | |||||
| }; | |||||
| PyMODINIT_FUNC PyInit_parsers(void) | PyMODINIT_FUNC PyInit_parsers(void) | ||||
| { | { | ||||
| PyObject *mod; | PyObject *mod; | ||||
| if (check_python_version() == -1) | if (check_python_version() == -1) | ||||
| return NULL; | return NULL; | ||||
| mod = PyModule_Create(&parsers_module); | mod = PyModule_Create(&parsers_module); | ||||