##// 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 {NULL} /* Sentinel */
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 PyTypeObject dirstateTupleType = {
163 PyTypeObject dirstateTupleType = {
154 PyVarObject_HEAD_INIT(NULL, 0) /* header */
164 PyVarObject_HEAD_INIT(NULL, 0) /* header */
155 "dirstate_tuple", /* tp_name */
165 "dirstate_tuple", /* tp_name */
@@ -180,7 +190,7 b' PyTypeObject dirstateTupleType = {'
180 0, /* tp_iternext */
190 0, /* tp_iternext */
181 dirstatetuple_methods, /* tp_methods */
191 dirstatetuple_methods, /* tp_methods */
182 0, /* tp_members */
192 0, /* tp_members */
183 0, /* tp_getset */
193 dirstatetuple_getset, /* tp_getset */
184 0, /* tp_base */
194 0, /* tp_base */
185 0, /* tp_dict */
195 0, /* tp_dict */
186 0, /* tp_descr_get */
196 0, /* tp_descr_get */
@@ -311,8 +311,15 b' class dirstate(object):'
311 r marked for removal
311 r marked for removal
312 a marked for addition
312 a marked for addition
313 ? not tracked
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 def __contains__(self, key):
324 def __contains__(self, key):
318 return key in self._map
325 return key in self._map
@@ -380,13 +387,13 b' class dirstate(object):'
380 continue
387 continue
381
388
382 # Discard 'm' markers when moving away from a merge state
389 # Discard 'm' markers when moving away from a merge state
383 if s[0] == b'm':
390 if s.state == b'm':
384 source = self._map.copymap.get(f)
391 source = self._map.copymap.get(f)
385 if source:
392 if source:
386 copies[f] = source
393 copies[f] = source
387 self.normallookup(f)
394 self.normallookup(f)
388 # Also fix up otherparent markers
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 source = self._map.copymap.get(f)
397 source = self._map.copymap.get(f)
391 if source:
398 if source:
392 copies[f] = source
399 copies[f] = source
@@ -465,7 +472,7 b' class dirstate(object):'
465 if self._map.hastrackeddir(d):
472 if self._map.hastrackeddir(d):
466 break
473 break
467 entry = self._map.get(d)
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 msg = _(b'file %r in dirstate clashes with %r')
476 msg = _(b'file %r in dirstate clashes with %r')
470 msg %= (pycompat.bytestr(d), pycompat.bytestr(f))
477 msg %= (pycompat.bytestr(d), pycompat.bytestr(f))
471 raise error.Abort(msg)
478 raise error.Abort(msg)
@@ -524,7 +531,7 b' class dirstate(object):'
524 # being removed, restore that state.
531 # being removed, restore that state.
525 entry = self._map.get(f)
532 entry = self._map.get(f)
526 if entry is not None:
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 source = self._map.copymap.get(f)
535 source = self._map.copymap.get(f)
529 if entry[2] == NONNORMAL:
536 if entry[2] == NONNORMAL:
530 self.merge(f)
537 self.merge(f)
@@ -533,7 +540,11 b' class dirstate(object):'
533 if source:
540 if source:
534 self.copy(source, f)
541 self.copy(source, f)
535 return
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 return
548 return
538 self._addpath(f, b'n', 0, possibly_dirty=True)
549 self._addpath(f, b'n', 0, possibly_dirty=True)
539 self._map.copymap.pop(f, None)
550 self._map.copymap.pop(f, None)
@@ -761,7 +772,7 b' class dirstate(object):'
761 if delaywrite > 0:
772 if delaywrite > 0:
762 # do we have any files to delay for?
773 # do we have any files to delay for?
763 for f, e in pycompat.iteritems(self._map):
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 import time # to avoid useless import
776 import time # to avoid useless import
766
777
767 # rather than sleep n seconds, sleep until the next
778 # rather than sleep n seconds, sleep until the next
@@ -1315,7 +1326,7 b' class dirstate(object):'
1315 # general. That is much slower than simply accessing and storing the
1326 # general. That is much slower than simply accessing and storing the
1316 # tuple members one by one.
1327 # tuple members one by one.
1317 t = dget(fn)
1328 t = dget(fn)
1318 state = t[0]
1329 state = t.state
1319 mode = t[1]
1330 mode = t[1]
1320 size = t[2]
1331 size = t[2]
1321 time = t[3]
1332 time = t[3]
@@ -64,6 +64,21 b' class dirstatetuple(object):'
64 else:
64 else:
65 raise IndexError(idx)
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 def v1_state(self):
82 def v1_state(self):
68 """return a "state" suitable for v1 serialization"""
83 """return a "state" suitable for v1 serialization"""
69 return self._state
84 return self._state
General Comments 0
You need to be logged in to leave comments. Login now