##// END OF EJS Templates
dirstate-item: add dedicated "legacy" constructor for `addfile` case...
marmoute -
r48716:c0d6a59a default
parent child Browse files
Show More
@@ -277,6 +277,102 b' static PyObject *dirstate_item_from_v1_m'
277 277 return (PyObject *)t;
278 278 };
279 279
280 /* constructor to help legacy API to build a new "added" item
281
282 Should eventually be removed */
283 static PyObject *dirstate_item_new_added(PyTypeObject *subtype)
284 {
285 dirstateItemObject *t;
286 t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1);
287 if (!t) {
288 return NULL;
289 }
290 t->state = 'a';
291 t->mode = 0;
292 t->size = dirstate_v1_nonnormal;
293 t->mtime = ambiguous_time;
294 return (PyObject *)t;
295 };
296
297 /* constructor to help legacy API to build a new "merged" item
298
299 Should eventually be removed */
300 static PyObject *dirstate_item_new_merged(PyTypeObject *subtype)
301 {
302 dirstateItemObject *t;
303 t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1);
304 if (!t) {
305 return NULL;
306 }
307 t->state = 'm';
308 t->mode = 0;
309 t->size = dirstate_v1_from_p2;
310 t->mtime = ambiguous_time;
311 return (PyObject *)t;
312 };
313
314 /* constructor to help legacy API to build a new "from_p2" item
315
316 Should eventually be removed */
317 static PyObject *dirstate_item_new_from_p2(PyTypeObject *subtype)
318 {
319 /* We do all the initialization here and not a tp_init function because
320 * dirstate_item is immutable. */
321 dirstateItemObject *t;
322 t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1);
323 if (!t) {
324 return NULL;
325 }
326 t->state = 'n';
327 t->mode = 0;
328 t->size = dirstate_v1_from_p2;
329 t->mtime = ambiguous_time;
330 return (PyObject *)t;
331 };
332
333 /* constructor to help legacy API to build a new "possibly" item
334
335 Should eventually be removed */
336 static PyObject *dirstate_item_new_possibly_dirty(PyTypeObject *subtype)
337 {
338 /* We do all the initialization here and not a tp_init function because
339 * dirstate_item is immutable. */
340 dirstateItemObject *t;
341 t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1);
342 if (!t) {
343 return NULL;
344 }
345 t->state = 'n';
346 t->mode = 0;
347 t->size = dirstate_v1_nonnormal;
348 t->mtime = ambiguous_time;
349 return (PyObject *)t;
350 };
351
352 /* constructor to help legacy API to build a new "normal" item
353
354 Should eventually be removed */
355 static PyObject *dirstate_item_new_normal(PyTypeObject *subtype, PyObject *args)
356 {
357 /* We do all the initialization here and not a tp_init function because
358 * dirstate_item is immutable. */
359 dirstateItemObject *t;
360 int size, mode, mtime;
361 if (!PyArg_ParseTuple(args, "iii", &mode, &size, &mtime)) {
362 return NULL;
363 }
364
365 t = (dirstateItemObject *)subtype->tp_alloc(subtype, 1);
366 if (!t) {
367 return NULL;
368 }
369 t->state = 'n';
370 t->mode = mode;
371 t->size = size;
372 t->mtime = mtime;
373 return (PyObject *)t;
374 };
375
280 376 /* This means the next status call will have to actually check its content
281 377 to make sure it is correct. */
282 378 static PyObject *dirstate_item_set_possibly_dirty(dirstateItemObject *self)
@@ -313,6 +409,21 b' static PyMethodDef dirstate_item_methods'
313 409 "True if the stored mtime would be ambiguous with the current time"},
314 410 {"from_v1_data", (PyCFunction)dirstate_item_from_v1_meth,
315 411 METH_VARARGS | METH_CLASS, "build a new DirstateItem object from V1 data"},
412 {"new_added", (PyCFunction)dirstate_item_new_added,
413 METH_NOARGS | METH_CLASS,
414 "constructor to help legacy API to build a new \"added\" item"},
415 {"new_merged", (PyCFunction)dirstate_item_new_merged,
416 METH_NOARGS | METH_CLASS,
417 "constructor to help legacy API to build a new \"merged\" item"},
418 {"new_from_p2", (PyCFunction)dirstate_item_new_from_p2,
419 METH_NOARGS | METH_CLASS,
420 "constructor to help legacy API to build a new \"from_p2\" item"},
421 {"new_possibly_dirty", (PyCFunction)dirstate_item_new_possibly_dirty,
422 METH_NOARGS | METH_CLASS,
423 "constructor to help legacy API to build a new \"possibly_dirty\" item"},
424 {"new_normal", (PyCFunction)dirstate_item_new_normal,
425 METH_VARARGS | METH_CLASS,
426 "constructor to help legacy API to build a new \"normal\" item"},
316 427 {"set_possibly_dirty", (PyCFunction)dirstate_item_set_possibly_dirty,
317 428 METH_NOARGS, "mark a file as \"possibly dirty\""},
318 429 {"set_untracked", (PyCFunction)dirstate_item_set_untracked, METH_NOARGS,
@@ -188,42 +188,28 b' class dirstatemap(object):'
188 188 assert not merged
189 189 assert not possibly_dirty
190 190 assert not from_p2
191 state = b'a'
192 size = NONNORMAL
193 mtime = AMBIGUOUS_TIME
191 new_entry = DirstateItem.new_added()
194 192 elif merged:
195 193 assert not possibly_dirty
196 194 assert not from_p2
197 state = b'm'
198 size = FROM_P2
199 mtime = AMBIGUOUS_TIME
195 new_entry = DirstateItem.new_merged()
200 196 elif from_p2:
201 197 assert not possibly_dirty
202 state = b'n'
203 size = FROM_P2
204 mtime = AMBIGUOUS_TIME
198 new_entry = DirstateItem.new_from_p2()
205 199 elif possibly_dirty:
206 state = b'n'
207 size = NONNORMAL
208 mtime = AMBIGUOUS_TIME
200 new_entry = DirstateItem.new_possibly_dirty()
209 201 else:
210 assert size != FROM_P2
211 assert size != NONNORMAL
212 202 assert size is not None
213 203 assert mtime is not None
214
215 state = b'n'
216 204 size = size & rangemask
217 205 mtime = mtime & rangemask
218 assert state is not None
219 assert size is not None
220 assert mtime is not None
206 new_entry = DirstateItem.new_normal(mode, size, mtime)
221 207 old_entry = self.get(f)
222 208 self._dirs_incr(f, old_entry)
223 e = self._map[f] = DirstateItem.from_v1_data(state, mode, size, mtime)
224 if e.dm_nonnormal:
209 self._map[f] = new_entry
210 if new_entry.dm_nonnormal:
225 211 self.nonnormalset.add(f)
226 if e.dm_otherparent:
212 if new_entry.dm_otherparent:
227 213 self.otherparentset.add(f)
228 214
229 215 def reset_state(
@@ -119,6 +119,73 b' class DirstateItem(object):'
119 119 assert False, 'unreachable'
120 120
121 121 @classmethod
122 def new_added(cls):
123 """constructor to help legacy API to build a new "added" item
124
125 Should eventually be removed
126 """
127 instance = cls()
128 instance._state = b'a'
129 instance._mode = 0
130 instance._size = NONNORMAL
131 instance._mtime = AMBIGUOUS_TIME
132 return instance
133
134 @classmethod
135 def new_merged(cls):
136 """constructor to help legacy API to build a new "merged" item
137
138 Should eventually be removed
139 """
140 instance = cls()
141 instance._state = b'm'
142 instance._mode = 0
143 instance._size = FROM_P2
144 instance._mtime = AMBIGUOUS_TIME
145 return instance
146
147 @classmethod
148 def new_from_p2(cls):
149 """constructor to help legacy API to build a new "from_p2" item
150
151 Should eventually be removed
152 """
153 instance = cls()
154 instance._state = b'n'
155 instance._mode = 0
156 instance._size = FROM_P2
157 instance._mtime = AMBIGUOUS_TIME
158 return instance
159
160 @classmethod
161 def new_possibly_dirty(cls):
162 """constructor to help legacy API to build a new "possibly_dirty" item
163
164 Should eventually be removed
165 """
166 instance = cls()
167 instance._state = b'n'
168 instance._mode = 0
169 instance._size = NONNORMAL
170 instance._mtime = AMBIGUOUS_TIME
171 return instance
172
173 @classmethod
174 def new_normal(cls, mode, size, mtime):
175 """constructor to help legacy API to build a new "normal" item
176
177 Should eventually be removed
178 """
179 assert size != FROM_P2
180 assert size != NONNORMAL
181 instance = cls()
182 instance._state = b'n'
183 instance._mode = mode
184 instance._size = size
185 instance._mtime = mtime
186 return instance
187
188 @classmethod
122 189 def from_v1_data(cls, state, mode, size, mtime):
123 190 """Build a new DirstateItem object from V1 data
124 191
General Comments 0
You need to be logged in to leave comments. Login now