Show More
@@ -155,6 +155,48 b' static PyObject *dirstate_item_need_dela' | |||
|
155 | 155 | } |
|
156 | 156 | }; |
|
157 | 157 | |
|
158 | /* This will never change since it's bound to V1, unlike `make_dirstate_item` | |
|
159 | */ | |
|
160 | static inline dirstateItemObject * | |
|
161 | dirstate_item_from_v1_data(char state, int mode, int size, int mtime) | |
|
162 | { | |
|
163 | dirstateItemObject *t = | |
|
164 | PyObject_New(dirstateItemObject, &dirstateItemType); | |
|
165 | if (!t) { | |
|
166 | return NULL; | |
|
167 | } | |
|
168 | t->state = state; | |
|
169 | t->mode = mode; | |
|
170 | t->size = size; | |
|
171 | t->mtime = mtime; | |
|
172 | return t; | |
|
173 | } | |
|
174 | ||
|
175 | /* This will never change since it's bound to V1, unlike `dirstate_item_new` */ | |
|
176 | static PyObject *dirstate_item_from_v1_meth(PyTypeObject *subtype, | |
|
177 | PyObject *args) | |
|
178 | { | |
|
179 | /* We do all the initialization here and not a tp_init function because | |
|
180 | * dirstate_item is immutable. */ | |
|
181 | dirstateItemObject *t; | |
|
182 | char state; | |
|
183 | int size, mode, mtime; | |
|
184 | if (!PyArg_ParseTuple(args, "ciii", &state, &mode, &size, &mtime)) { | |
|
185 | return NULL; | |
|
186 | } | |
|
187 | ||
|
188 | t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1); | |
|
189 | if (!t) { | |
|
190 | return NULL; | |
|
191 | } | |
|
192 | t->state = state; | |
|
193 | t->mode = mode; | |
|
194 | t->size = size; | |
|
195 | t->mtime = mtime; | |
|
196 | ||
|
197 | return (PyObject *)t; | |
|
198 | }; | |
|
199 | ||
|
158 | 200 | static PyMethodDef dirstate_item_methods[] = { |
|
159 | 201 | {"v1_state", (PyCFunction)dirstate_item_v1_state, METH_NOARGS, |
|
160 | 202 | "return a \"state\" suitable for v1 serialization"}, |
@@ -166,6 +208,8 b' static PyMethodDef dirstate_item_methods' | |||
|
166 | 208 | "return a \"mtime\" suitable for v1 serialization"}, |
|
167 | 209 | {"need_delay", (PyCFunction)dirstate_item_need_delay, METH_O, |
|
168 | 210 | "True if the stored mtime would be ambiguous with the current time"}, |
|
211 | {"from_v1_data", (PyCFunction)dirstate_item_from_v1_meth, METH_O, | |
|
212 | "build a new DirstateItem object from V1 data"}, | |
|
169 | 213 | {NULL} /* Sentinel */ |
|
170 | 214 | }; |
|
171 | 215 | |
@@ -363,8 +407,8 b' static PyObject *parse_dirstate(PyObject' | |||
|
363 | 407 | goto quit; |
|
364 | 408 | } |
|
365 | 409 | |
|
366 | entry = | |
|
367 | (PyObject *)make_dirstate_item(state, mode, size, mtime); | |
|
410 | entry = (PyObject *)dirstate_item_from_v1_data(state, mode, | |
|
411 | size, mtime); | |
|
368 | 412 | cpos = memchr(cur, 0, flen); |
|
369 | 413 | if (cpos) { |
|
370 | 414 | fname = PyBytes_FromStringAndSize(cur, cpos - cur); |
@@ -67,6 +67,20 b' class DirstateItem(object):' | |||
|
67 | 67 | self._size = size |
|
68 | 68 | self._mtime = mtime |
|
69 | 69 | |
|
70 | @classmethod | |
|
71 | def from_v1_data(cls, state, mode, size, mtime): | |
|
72 | """Build a new DirstateItem object from V1 data | |
|
73 | ||
|
74 | Since the dirstate-v1 format is frozen, the signature of this function | |
|
75 | is not expected to change, unlike the __init__ one. | |
|
76 | """ | |
|
77 | return cls( | |
|
78 | state=state, | |
|
79 | mode=mode, | |
|
80 | size=size, | |
|
81 | mtime=mtime, | |
|
82 | ) | |
|
83 | ||
|
70 | 84 | def __getitem__(self, idx): |
|
71 | 85 | if idx == 0 or idx == -4: |
|
72 | 86 | msg = b"do not use item[x], use item.state" |
@@ -546,7 +560,7 b' def parse_dirstate(dmap, copymap, st):' | |||
|
546 | 560 | if b'\0' in f: |
|
547 | 561 | f, c = f.split(b'\0') |
|
548 | 562 | copymap[f] = c |
|
549 | dmap[f] = DirstateItem(*e[:4]) | |
|
563 | dmap[f] = DirstateItem.from_v1_data(*e[:4]) | |
|
550 | 564 | return parents |
|
551 | 565 | |
|
552 | 566 |
General Comments 0
You need to be logged in to leave comments.
Login now