##// END OF EJS Templates
dirstate-entry: add a `state` property (and use it)...
marmoute -
r48301:769037a2 default
parent child Browse files
Show More
@@ -150,6 +150,16 b' static PyMethodDef dirstatetuple_methods'
150 150 {NULL} /* Sentinel */
151 151 };
152 152
153 static PyObject *dirstatetuple_get_state(dirstateTupleObject *self)
154 {
155 return PyBytes_FromStringAndSize(&self->state, 1);
156 };
157
158 static PyGetSetDef dirstatetuple_getset[] = {
159 {"state", (getter)dirstatetuple_get_state, NULL, "state", NULL},
160 {NULL} /* Sentinel */
161 };
162
153 163 PyTypeObject dirstateTupleType = {
154 164 PyVarObject_HEAD_INIT(NULL, 0) /* header */
155 165 "dirstate_tuple", /* tp_name */
@@ -180,7 +190,7 b' PyTypeObject dirstateTupleType = {'
180 190 0, /* tp_iternext */
181 191 dirstatetuple_methods, /* tp_methods */
182 192 0, /* tp_members */
183 0, /* tp_getset */
193 dirstatetuple_getset, /* tp_getset */
184 194 0, /* tp_base */
185 195 0, /* tp_dict */
186 196 0, /* tp_descr_get */
@@ -311,8 +311,15 b' class dirstate(object):'
311 311 r marked for removal
312 312 a marked for addition
313 313 ? not tracked
314
315 XXX The "state" is a bit obscure to be in the "public" API. we should
316 consider migrating all user of this to going through the dirstate entry
317 instead.
314 318 """
315 return self._map.get(key, (b"?",))[0]
319 entry = self._map.get(key)
320 if entry is not None:
321 return entry.state
322 return b'?'
316 323
317 324 def __contains__(self, key):
318 325 return key in self._map
@@ -380,13 +387,13 b' class dirstate(object):'
380 387 continue
381 388
382 389 # Discard 'm' markers when moving away from a merge state
383 if s[0] == b'm':
390 if s.state == b'm':
384 391 source = self._map.copymap.get(f)
385 392 if source:
386 393 copies[f] = source
387 394 self.normallookup(f)
388 395 # Also fix up otherparent markers
389 elif s[0] == b'n' and s[2] == FROM_P2:
396 elif s.state == b'n' and s[2] == FROM_P2:
390 397 source = self._map.copymap.get(f)
391 398 if source:
392 399 copies[f] = source
@@ -465,7 +472,7 b' class dirstate(object):'
465 472 if self._map.hastrackeddir(d):
466 473 break
467 474 entry = self._map.get(d)
468 if entry is not None and entry[0] != b'r':
475 if entry is not None and entry.state != b'r':
469 476 msg = _(b'file %r in dirstate clashes with %r')
470 477 msg %= (pycompat.bytestr(d), pycompat.bytestr(f))
471 478 raise error.Abort(msg)
@@ -524,7 +531,7 b' class dirstate(object):'
524 531 # being removed, restore that state.
525 532 entry = self._map.get(f)
526 533 if entry is not None:
527 if entry[0] == b'r' and entry[2] in (NONNORMAL, FROM_P2):
534 if entry.state == b'r' and entry[2] in (NONNORMAL, FROM_P2):
528 535 source = self._map.copymap.get(f)
529 536 if entry[2] == NONNORMAL:
530 537 self.merge(f)
@@ -533,7 +540,11 b' class dirstate(object):'
533 540 if source:
534 541 self.copy(source, f)
535 542 return
536 if entry[0] == b'm' or entry[0] == b'n' and entry[2] == FROM_P2:
543 if (
544 entry.state == b'm'
545 or entry.state == b'n'
546 and entry[2] == FROM_P2
547 ):
537 548 return
538 549 self._addpath(f, b'n', 0, possibly_dirty=True)
539 550 self._map.copymap.pop(f, None)
@@ -761,7 +772,7 b' class dirstate(object):'
761 772 if delaywrite > 0:
762 773 # do we have any files to delay for?
763 774 for f, e in pycompat.iteritems(self._map):
764 if e[0] == b'n' and e[3] == now:
775 if e.state == b'n' and e[3] == now:
765 776 import time # to avoid useless import
766 777
767 778 # rather than sleep n seconds, sleep until the next
@@ -1315,7 +1326,7 b' class dirstate(object):'
1315 1326 # general. That is much slower than simply accessing and storing the
1316 1327 # tuple members one by one.
1317 1328 t = dget(fn)
1318 state = t[0]
1329 state = t.state
1319 1330 mode = t[1]
1320 1331 size = t[2]
1321 1332 time = t[3]
@@ -64,6 +64,21 b' class dirstatetuple(object):'
64 64 else:
65 65 raise IndexError(idx)
66 66
67 @property
68 def state(self):
69 """
70 States are:
71 n normal
72 m needs merging
73 r marked for removal
74 a marked for addition
75
76 XXX This "state" is a bit obscure and mostly a direct expression of the
77 dirstatev1 format. It would make sense to ultimately deprecate it in
78 favor of the more "semantic" attributes.
79 """
80 return self._state
81
67 82 def v1_state(self):
68 83 """return a "state" suitable for v1 serialization"""
69 84 return self._state
General Comments 0
You need to be logged in to leave comments. Login now