##// END OF EJS Templates
dirstate: Use the Rust implementation of DirstateItem when Rust is enabled...
Simon Sapin -
r48858:d5528ac9 default
parent child Browse files
Show More
@@ -1233,7 +1233,6 b' static const int version = 20;'
1233 1233
1234 1234 static void module_init(PyObject *mod)
1235 1235 {
1236 PyObject *capsule = NULL;
1237 1236 PyModule_AddIntConstant(mod, "version", version);
1238 1237
1239 1238 /* This module constant has two purposes. First, it lets us unit test
@@ -1250,12 +1249,6 b' static void module_init(PyObject *mod)'
1250 1249 manifest_module_init(mod);
1251 1250 revlog_module_init(mod);
1252 1251
1253 capsule = PyCapsule_New(
1254 dirstate_item_from_v1_data,
1255 "mercurial.cext.parsers.make_dirstate_item_CAPI", NULL);
1256 if (capsule != NULL)
1257 PyModule_AddObject(mod, "make_dirstate_item_CAPI", capsule);
1258
1259 1252 if (PyType_Ready(&dirstateItemType) < 0) {
1260 1253 return;
1261 1254 }
@@ -45,7 +45,7 b' propertycache = util.propertycache'
45 45 filecache = scmutil.filecache
46 46 _rangemask = dirstatemap.rangemask
47 47
48 DirstateItem = parsers.DirstateItem
48 DirstateItem = dirstatemap.DirstateItem
49 49
50 50
51 51 class repocache(filecache):
@@ -27,7 +27,10 b" rustmod = policy.importrust('dirstate')"
27 27
28 28 propertycache = util.propertycache
29 29
30 DirstateItem = parsers.DirstateItem
30 if rustmod is None:
31 DirstateItem = parsers.DirstateItem
32 else:
33 DirstateItem = rustmod.DirstateItem
31 34
32 35 rangemask = 0x7FFFFFFF
33 36
@@ -22,51 +22,8 b' use crate::{'
22 22 },
23 23 exceptions,
24 24 };
25 use cpython::{
26 PyBytes, PyDict, PyErr, PyList, PyModule, PyObject, PyResult, Python,
27 };
25 use cpython::{PyBytes, PyDict, PyList, PyModule, PyObject, PyResult, Python};
28 26 use hg::dirstate_tree::on_disk::V2_FORMAT_MARKER;
29 use hg::DirstateEntry;
30 use libc::{c_char, c_int};
31
32 // C code uses a custom `dirstate_tuple` type, checks in multiple instances
33 // for this type, and raises a Python `Exception` if the check does not pass.
34 // Because this type differs only in name from the regular Python tuple, it
35 // would be a good idea in the near future to remove it entirely to allow
36 // for a pure Python tuple of the same effective structure to be used,
37 // rendering this type and the capsule below useless.
38 py_capsule_fn!(
39 from mercurial.cext.parsers import make_dirstate_item_CAPI
40 as make_dirstate_item_capi
41 signature (
42 state: c_char,
43 mode: c_int,
44 size: c_int,
45 mtime: c_int,
46 ) -> *mut RawPyObject
47 );
48
49 pub fn make_dirstate_item(
50 py: Python,
51 entry: &DirstateEntry,
52 ) -> PyResult<PyObject> {
53 // Explicitly go through u8 first, then cast to platform-specific `c_char`
54 // because Into<u8> has a specific implementation while `as c_char` would
55 // just do a naive enum cast.
56 let state_code: u8 = entry.state().into();
57
58 let make = make_dirstate_item_capi::retrieve(py)?;
59 let maybe_obj = unsafe {
60 let ptr = make(
61 state_code as c_char,
62 entry.mode(),
63 entry.size(),
64 entry.mtime(),
65 );
66 PyObject::from_owned_ptr_opt(py, ptr)
67 };
68 maybe_obj.ok_or_else(|| PyErr::fetch(py))
69 }
70 27
71 28 /// Create the module, with `__package__` given from parent
72 29 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
@@ -19,7 +19,7 b' use cpython::{'
19 19
20 20 use crate::{
21 21 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
22 dirstate::make_dirstate_item,
22 dirstate::item::DirstateItem,
23 23 dirstate::non_normal_entries::{
24 24 NonNormalEntries, NonNormalEntriesIterator,
25 25 },
@@ -123,7 +123,7 b' py_class!(pub class DirstateMap |py| {'
123 123 .map_err(|e| v2_error(py, e))?
124 124 {
125 125 Some(entry) => {
126 Ok(Some(make_dirstate_item(py, &entry)?))
126 Ok(Some(DirstateItem::new_as_pyobject(py, entry)?))
127 127 },
128 128 None => Ok(default)
129 129 }
@@ -450,7 +450,7 b' py_class!(pub class DirstateMap |py| {'
450 450 .map_err(|e| v2_error(py, e))?
451 451 {
452 452 Some(entry) => {
453 Ok(make_dirstate_item(py, &entry)?)
453 Ok(DirstateItem::new_as_pyobject(py, entry)?)
454 454 },
455 455 None => Err(PyErr::new::<exc::KeyError, _>(
456 456 py,
@@ -639,7 +639,7 b' impl DirstateMap {'
639 639 let (f, entry) = res.map_err(|e| v2_error(py, e))?;
640 640 Ok(Some((
641 641 PyBytes::new(py, f.as_bytes()),
642 make_dirstate_item(py, &entry)?,
642 DirstateItem::new_as_pyobject(py, entry)?,
643 643 )))
644 644 }
645 645 }
General Comments 0
You need to be logged in to leave comments. Login now