##// END OF EJS Templates
dirstate: remove v1_* methods from Python/C/Rust shared API...
Raphaël Gomès -
r49920:be9bf75a default
parent child Browse files
Show More
@@ -335,7 +335,7 b' def overridewalk(orig, self, match, subr'
335 nonnormalset = {
335 nonnormalset = {
336 f
336 f
337 for f, e in self._map.items()
337 for f, e in self._map.items()
338 if e.v1_state() != b"n" or e.v1_mtime() == -1
338 if e._v1_state() != b"n" or e._v1_mtime() == -1
339 }
339 }
340
340
341 copymap = self._map.copymap
341 copymap = self._map.copymap
@@ -289,27 +289,6 b' static PyObject *dirstate_item_v2_data(d'
289 self->mtime_ns);
289 self->mtime_ns);
290 };
290 };
291
291
292 static PyObject *dirstate_item_v1_state(dirstateItemObject *self)
293 {
294 char state = dirstate_item_c_v1_state(self);
295 return PyBytes_FromStringAndSize(&state, 1);
296 };
297
298 static PyObject *dirstate_item_v1_mode(dirstateItemObject *self)
299 {
300 return PyLong_FromLong(dirstate_item_c_v1_mode(self));
301 };
302
303 static PyObject *dirstate_item_v1_size(dirstateItemObject *self)
304 {
305 return PyLong_FromLong(dirstate_item_c_v1_size(self));
306 };
307
308 static PyObject *dirstate_item_v1_mtime(dirstateItemObject *self)
309 {
310 return PyLong_FromLong(dirstate_item_c_v1_mtime(self));
311 };
312
313 static PyObject *dirstate_item_mtime_likely_equal_to(dirstateItemObject *self,
292 static PyObject *dirstate_item_mtime_likely_equal_to(dirstateItemObject *self,
314 PyObject *other)
293 PyObject *other)
315 {
294 {
@@ -403,20 +382,6 b' dirstate_item_from_v1_data(char state, i'
403 return t;
382 return t;
404 }
383 }
405
384
406 /* This will never change since it's bound to V1, unlike `dirstate_item_new` */
407 static PyObject *dirstate_item_from_v1_meth(PyTypeObject *subtype,
408 PyObject *args)
409 {
410 /* We do all the initialization here and not a tp_init function because
411 * dirstate_item is immutable. */
412 char state;
413 int size, mode, mtime;
414 if (!PyArg_ParseTuple(args, "ciii", &state, &mode, &size, &mtime)) {
415 return NULL;
416 }
417 return (PyObject *)dirstate_item_from_v1_data(state, mode, size, mtime);
418 };
419
420 static PyObject *dirstate_item_from_v2_meth(PyTypeObject *subtype,
385 static PyObject *dirstate_item_from_v2_meth(PyTypeObject *subtype,
421 PyObject *args)
386 PyObject *args)
422 {
387 {
@@ -526,18 +491,8 b' static PyObject *dirstate_item_drop_merg'
526 static PyMethodDef dirstate_item_methods[] = {
491 static PyMethodDef dirstate_item_methods[] = {
527 {"v2_data", (PyCFunction)dirstate_item_v2_data, METH_NOARGS,
492 {"v2_data", (PyCFunction)dirstate_item_v2_data, METH_NOARGS,
528 "return data suitable for v2 serialization"},
493 "return data suitable for v2 serialization"},
529 {"v1_state", (PyCFunction)dirstate_item_v1_state, METH_NOARGS,
530 "return a \"state\" suitable for v1 serialization"},
531 {"v1_mode", (PyCFunction)dirstate_item_v1_mode, METH_NOARGS,
532 "return a \"mode\" suitable for v1 serialization"},
533 {"v1_size", (PyCFunction)dirstate_item_v1_size, METH_NOARGS,
534 "return a \"size\" suitable for v1 serialization"},
535 {"v1_mtime", (PyCFunction)dirstate_item_v1_mtime, METH_NOARGS,
536 "return a \"mtime\" suitable for v1 serialization"},
537 {"mtime_likely_equal_to", (PyCFunction)dirstate_item_mtime_likely_equal_to,
494 {"mtime_likely_equal_to", (PyCFunction)dirstate_item_mtime_likely_equal_to,
538 METH_O, "True if the stored mtime is likely equal to the given mtime"},
495 METH_O, "True if the stored mtime is likely equal to the given mtime"},
539 {"from_v1_data", (PyCFunction)dirstate_item_from_v1_meth,
540 METH_VARARGS | METH_CLASS, "build a new DirstateItem object from V1 data"},
541 {"from_v2_data", (PyCFunction)dirstate_item_from_v2_meth,
496 {"from_v2_data", (PyCFunction)dirstate_item_from_v2_meth,
542 METH_VARARGS | METH_CLASS, "build a new DirstateItem object from V2 data"},
497 METH_VARARGS | METH_CLASS, "build a new DirstateItem object from V2 data"},
543 {"set_possibly_dirty", (PyCFunction)dirstate_item_set_possibly_dirty,
498 {"set_possibly_dirty", (PyCFunction)dirstate_item_set_possibly_dirty,
@@ -291,15 +291,15 b' class DirstateItem:'
291
291
292 @property
292 @property
293 def mode(self):
293 def mode(self):
294 return self.v1_mode()
294 return self._v1_mode()
295
295
296 @property
296 @property
297 def size(self):
297 def size(self):
298 return self.v1_size()
298 return self._v1_size()
299
299
300 @property
300 @property
301 def mtime(self):
301 def mtime(self):
302 return self.v1_mtime()
302 return self._v1_mtime()
303
303
304 def mtime_likely_equal_to(self, other_mtime):
304 def mtime_likely_equal_to(self, other_mtime):
305 self_sec = self._mtime_s
305 self_sec = self._mtime_s
@@ -338,7 +338,7 b' class DirstateItem:'
338 """
338 """
339 if not self.any_tracked:
339 if not self.any_tracked:
340 return b'?'
340 return b'?'
341 return self.v1_state()
341 return self._v1_state()
342
342
343 @property
343 @property
344 def has_fallback_exec(self):
344 def has_fallback_exec(self):
@@ -498,7 +498,7 b' class DirstateItem:'
498 # since we never set _DIRSTATE_V2_HAS_DIRCTORY_MTIME
498 # since we never set _DIRSTATE_V2_HAS_DIRCTORY_MTIME
499 return (flags, self._size or 0, self._mtime_s or 0, self._mtime_ns or 0)
499 return (flags, self._size or 0, self._mtime_s or 0, self._mtime_ns or 0)
500
500
501 def v1_state(self):
501 def _v1_state(self):
502 """return a "state" suitable for v1 serialization"""
502 """return a "state" suitable for v1 serialization"""
503 if not self.any_tracked:
503 if not self.any_tracked:
504 # the object has no state to record, this is -currently-
504 # the object has no state to record, this is -currently-
@@ -513,11 +513,11 b' class DirstateItem:'
513 else:
513 else:
514 return b'n'
514 return b'n'
515
515
516 def v1_mode(self):
516 def _v1_mode(self):
517 """return a "mode" suitable for v1 serialization"""
517 """return a "mode" suitable for v1 serialization"""
518 return self._mode if self._mode is not None else 0
518 return self._mode if self._mode is not None else 0
519
519
520 def v1_size(self):
520 def _v1_size(self):
521 """return a "size" suitable for v1 serialization"""
521 """return a "size" suitable for v1 serialization"""
522 if not self.any_tracked:
522 if not self.any_tracked:
523 # the object has no state to record, this is -currently-
523 # the object has no state to record, this is -currently-
@@ -536,7 +536,7 b' class DirstateItem:'
536 else:
536 else:
537 return self._size
537 return self._size
538
538
539 def v1_mtime(self):
539 def _v1_mtime(self):
540 """return a "mtime" suitable for v1 serialization"""
540 """return a "mtime" suitable for v1 serialization"""
541 if not self.any_tracked:
541 if not self.any_tracked:
542 # the object has no state to record, this is -currently-
542 # the object has no state to record, this is -currently-
@@ -963,10 +963,10 b' def pack_dirstate(dmap, copymap, pl):'
963 f = b"%s\0%s" % (f, copymap[f])
963 f = b"%s\0%s" % (f, copymap[f])
964 e = _pack(
964 e = _pack(
965 b">cllll",
965 b">cllll",
966 e.v1_state(),
966 e._v1_state(),
967 e.v1_mode(),
967 e._v1_mode(),
968 e.v1_size(),
968 e._v1_size(),
969 e.v1_mtime(),
969 e._v1_mtime(),
970 len(f),
970 len(f),
971 )
971 )
972 write(e)
972 write(e)
@@ -8,10 +8,8 b' use cpython::PyResult;'
8 use cpython::Python;
8 use cpython::Python;
9 use cpython::PythonObject;
9 use cpython::PythonObject;
10 use hg::dirstate::DirstateEntry;
10 use hg::dirstate::DirstateEntry;
11 use hg::dirstate::EntryState;
12 use hg::dirstate::TruncatedTimestamp;
11 use hg::dirstate::TruncatedTimestamp;
13 use std::cell::Cell;
12 use std::cell::Cell;
14 use std::convert::TryFrom;
15
13
16 py_class!(pub class DirstateItem |py| {
14 py_class!(pub class DirstateItem |py| {
17 data entry: Cell<DirstateEntry>;
15 data entry: Cell<DirstateEntry>;
@@ -173,27 +171,6 b' py_class!(pub class DirstateItem |py| {'
173 Ok(self.entry(py).get().any_tracked())
171 Ok(self.entry(py).get().any_tracked())
174 }
172 }
175
173
176 def v1_state(&self) -> PyResult<PyBytes> {
177 let (state, _mode, _size, _mtime) = self.entry(py).get().v1_data();
178 let state_byte: u8 = state.into();
179 Ok(PyBytes::new(py, &[state_byte]))
180 }
181
182 def v1_mode(&self) -> PyResult<i32> {
183 let (_state, mode, _size, _mtime) = self.entry(py).get().v1_data();
184 Ok(mode)
185 }
186
187 def v1_size(&self) -> PyResult<i32> {
188 let (_state, _mode, size, _mtime) = self.entry(py).get().v1_data();
189 Ok(size)
190 }
191
192 def v1_mtime(&self) -> PyResult<i32> {
193 let (_state, _mode, _size, mtime) = self.entry(py).get().v1_data();
194 Ok(mtime)
195 }
196
197 def mtime_likely_equal_to(&self, other: (u32, u32, bool))
174 def mtime_likely_equal_to(&self, other: (u32, u32, bool))
198 -> PyResult<bool> {
175 -> PyResult<bool> {
199 if let Some(mtime) = self.entry(py).get().truncated_mtime() {
176 if let Some(mtime) = self.entry(py).get().truncated_mtime() {
@@ -203,22 +180,6 b' py_class!(pub class DirstateItem |py| {'
203 }
180 }
204 }
181 }
205
182
206 @classmethod
207 def from_v1_data(
208 _cls,
209 state: PyBytes,
210 mode: i32,
211 size: i32,
212 mtime: i32,
213 ) -> PyResult<Self> {
214 let state = <[u8; 1]>::try_from(state.data(py))
215 .ok()
216 .and_then(|state| EntryState::try_from(state[0]).ok())
217 .ok_or_else(|| PyErr::new::<exc::ValueError, _>(py, "invalid state"))?;
218 let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
219 DirstateItem::create_instance(py, Cell::new(entry))
220 }
221
222 def drop_merge_data(&self) -> PyResult<PyNone> {
183 def drop_merge_data(&self) -> PyResult<PyNone> {
223 self.update(py, |entry| entry.drop_merge_data());
184 self.update(py, |entry| entry.drop_merge_data());
224 Ok(PyNone)
185 Ok(PyNone)
General Comments 0
You need to be logged in to leave comments. Login now