In the spirit of changing the content and storage of the dirstate entry, we add
new method that the code doing v1 serialisation can use.
Adding such method to the C object is quite trivial.
SimonSapin | |
pulkit |
hg-reviewers |
In the spirit of changing the content and storage of the dirstate entry, we add
new method that the code doing v1 serialisation can use.
Adding such method to the C object is quite trivial.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/cext/parsers.c (34 lines) | |||
M | mercurial/pure/parsers.py (25 lines) |
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 */ | ||||
}; | }; | ||||
static PyObject *dirstatetuple_v1_state(dirstateTupleObject *self) | |||||
{ | |||||
return PyBytes_FromStringAndSize(&self->state, 1); | |||||
}; | |||||
static PyObject *dirstatetuple_v1_mode(dirstateTupleObject *self) | |||||
{ | |||||
return PyInt_FromLong(self->mode); | |||||
}; | |||||
static PyObject *dirstatetuple_v1_size(dirstateTupleObject *self) | |||||
{ | |||||
return PyInt_FromLong(self->size); | |||||
}; | |||||
static PyObject *dirstatetuple_v1_mtime(dirstateTupleObject *self) | |||||
{ | |||||
return PyInt_FromLong(self->mtime); | |||||
}; | |||||
static PyMethodDef dirstatetuple_methods[] = { | |||||
{"v1_state", (PyCFunction)dirstatetuple_v1_state, METH_NOARGS, | |||||
"return a \"state\" suitable for v1 serialization"}, | |||||
{"v1_mode", (PyCFunction)dirstatetuple_v1_mode, METH_NOARGS, | |||||
"return a \"mode\" suitable for v1 serialization"}, | |||||
{"v1_size", (PyCFunction)dirstatetuple_v1_size, METH_NOARGS, | |||||
"return a \"size\" suitable for v1 serialization"}, | |||||
{"v1_mtime", (PyCFunction)dirstatetuple_v1_mtime, METH_NOARGS, | |||||
"return a \"mtime\" suitable for v1 serialization"}, | |||||
{NULL} /* Sentinel */ | |||||
}; | |||||
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 */ | ||||
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 */ | dirstatetuple_methods, /* 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 */ |
return self._mode | return self._mode | ||||
elif idx == 2 or idx == -2: | elif idx == 2 or idx == -2: | ||||
return self._size | return self._size | ||||
elif idx == 3 or idx == -1: | elif idx == 3 or idx == -1: | ||||
return self._mtime | return self._mtime | ||||
else: | else: | ||||
raise IndexError(idx) | raise IndexError(idx) | ||||
def v1_state(self): | |||||
"""return a "state" suitable for v1 serialization""" | |||||
return self._state | |||||
def v1_mode(self): | |||||
"""return a "mode" suitable for v1 serialization""" | |||||
return self._mode | |||||
def v1_size(self): | |||||
"""return a "size" suitable for v1 serialization""" | |||||
return self._size | |||||
def v1_mtime(self): | |||||
"""return a "mtime" suitable for v1 serialization""" | |||||
return self._mtime | |||||
def gettype(q): | def gettype(q): | ||||
return int(q & 0xFFFF) | return int(q & 0xFFFF) | ||||
class BaseIndexObject(object): | class BaseIndexObject(object): | ||||
# Can I be passed to an algorithme implemented in Rust ? | # Can I be passed to an algorithme implemented in Rust ? | ||||
rust_ext_compat = 0 | rust_ext_compat = 0 | ||||
# dirstate, forcing future 'status' calls to compare the | # dirstate, forcing future 'status' calls to compare the | ||||
# contents of the file if the size is the same. This prevents | # contents of the file if the size is the same. This prevents | ||||
# mistakenly treating such files as clean. | # mistakenly treating such files as clean. | ||||
e = dirstatetuple(e[0], e[1], e[2], -1) | e = dirstatetuple(e[0], e[1], e[2], -1) | ||||
dmap[f] = e | dmap[f] = e | ||||
if f in copymap: | if f in copymap: | ||||
f = b"%s\0%s" % (f, copymap[f]) | f = b"%s\0%s" % (f, copymap[f]) | ||||
e = _pack(b">cllll", e[0], e[1], e[2], e[3], len(f)) | e = _pack( | ||||
b">cllll", | |||||
e.v1_state(), | |||||
e.v1_mode(), | |||||
e.v1_size(), | |||||
e.v1_mtime(), | |||||
len(f), | |||||
) | |||||
write(e) | write(e) | ||||
write(f) | write(f) | ||||
return cs.getvalue() | return cs.getvalue() |