20 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
20 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
21 dirstate::item::DirstateItem, |
21 dirstate::item::DirstateItem, |
22 pybytes_deref::PyBytesDeref, |
22 pybytes_deref::PyBytesDeref, |
23 }; |
23 }; |
24 use hg::{ |
24 use hg::{ |
25 dirstate::StateMapIter, dirstate_tree::on_disk::DirstateV2ParseError, |
25 dirstate::StateMapIter, dirstate_tree::dirstate_map::DirstateMapWriteMode, |
|
26 dirstate_tree::on_disk::DirstateV2ParseError, |
26 dirstate_tree::owning::OwningDirstateMap, revlog::Node, |
27 dirstate_tree::owning::OwningDirstateMap, revlog::Node, |
27 utils::files::normalize_case, utils::hg_path::HgPath, DirstateEntry, |
28 utils::files::normalize_case, utils::hg_path::HgPath, DirstateEntry, |
28 DirstateError, DirstateParents, |
29 DirstateError, DirstateParents, |
29 }; |
30 }; |
30 |
31 |
45 |
46 |
46 /// Returns a `(dirstate_map, parents)` tuple |
47 /// Returns a `(dirstate_map, parents)` tuple |
47 @staticmethod |
48 @staticmethod |
48 def new_v1( |
49 def new_v1( |
49 on_disk: PyBytes, |
50 on_disk: PyBytes, |
|
51 identity: Option<u64>, |
50 ) -> PyResult<PyObject> { |
52 ) -> PyResult<PyObject> { |
51 let on_disk = PyBytesDeref::new(py, on_disk); |
53 let on_disk = PyBytesDeref::new(py, on_disk); |
52 let (map, parents) = OwningDirstateMap::new_v1(on_disk) |
54 let (map, parents) = OwningDirstateMap::new_v1(on_disk, identity) |
53 .map_err(|e| dirstate_error(py, e))?; |
55 .map_err(|e| dirstate_error(py, e))?; |
54 let map = Self::create_instance(py, map)?; |
56 let map = Self::create_instance(py, map)?; |
55 let p1 = PyBytes::new(py, parents.p1.as_bytes()); |
57 let p1 = PyBytes::new(py, parents.p1.as_bytes()); |
56 let p2 = PyBytes::new(py, parents.p2.as_bytes()); |
58 let p2 = PyBytes::new(py, parents.p2.as_bytes()); |
57 let parents = (p1, p2); |
59 let parents = (p1, p2); |
62 @staticmethod |
64 @staticmethod |
63 def new_v2( |
65 def new_v2( |
64 on_disk: PyBytes, |
66 on_disk: PyBytes, |
65 data_size: usize, |
67 data_size: usize, |
66 tree_metadata: PyBytes, |
68 tree_metadata: PyBytes, |
|
69 uuid: PyBytes, |
|
70 identity: Option<u64>, |
67 ) -> PyResult<PyObject> { |
71 ) -> PyResult<PyObject> { |
68 let dirstate_error = |e: DirstateError| { |
72 let dirstate_error = |e: DirstateError| { |
69 PyErr::new::<exc::OSError, _>(py, format!("Dirstate error: {:?}", e)) |
73 PyErr::new::<exc::OSError, _>(py, format!("Dirstate error: {:?}", e)) |
70 }; |
74 }; |
71 let on_disk = PyBytesDeref::new(py, on_disk); |
75 let on_disk = PyBytesDeref::new(py, on_disk); |
|
76 let uuid = uuid.data(py); |
72 let map = OwningDirstateMap::new_v2( |
77 let map = OwningDirstateMap::new_v2( |
73 on_disk, data_size, tree_metadata.data(py), |
78 on_disk, |
|
79 data_size, |
|
80 tree_metadata.data(py), |
|
81 uuid.to_owned(), |
|
82 identity, |
74 ).map_err(dirstate_error)?; |
83 ).map_err(dirstate_error)?; |
|
84 let map = Self::create_instance(py, map)?; |
|
85 Ok(map.into_object()) |
|
86 } |
|
87 |
|
88 /// Returns an empty DirstateMap. Only used for a new dirstate. |
|
89 @staticmethod |
|
90 def new_empty() -> PyResult<PyObject> { |
|
91 let map = OwningDirstateMap::new_empty(vec![]); |
75 let map = Self::create_instance(py, map)?; |
92 let map = Self::create_instance(py, map)?; |
76 Ok(map.into_object()) |
93 Ok(map.into_object()) |
77 } |
94 } |
78 |
95 |
79 def clear(&self) -> PyResult<PyObject> { |
96 def clear(&self) -> PyResult<PyObject> { |
234 /// Returns new data together with whether that data should be appended to |
251 /// Returns new data together with whether that data should be appended to |
235 /// the existing data file whose content is at `self.on_disk` (True), |
252 /// the existing data file whose content is at `self.on_disk` (True), |
236 /// instead of written to a new data file (False). |
253 /// instead of written to a new data file (False). |
237 def write_v2( |
254 def write_v2( |
238 &self, |
255 &self, |
239 can_append: bool, |
256 write_mode: usize, |
240 ) -> PyResult<PyObject> { |
257 ) -> PyResult<PyObject> { |
241 let inner = self.inner(py).borrow(); |
258 let inner = self.inner(py).borrow(); |
242 let result = inner.pack_v2(can_append); |
259 let rust_write_mode = match write_mode { |
|
260 0 => DirstateMapWriteMode::Auto, |
|
261 1 => DirstateMapWriteMode::ForceNewDataFile, |
|
262 2 => DirstateMapWriteMode::ForceAppend, |
|
263 _ => DirstateMapWriteMode::Auto, // XXX should we error out? |
|
264 }; |
|
265 let result = inner.pack_v2(rust_write_mode); |
243 match result { |
266 match result { |
244 Ok((packed, tree_metadata, append, _old_data_size)) => { |
267 Ok((packed, tree_metadata, append, _old_data_size)) => { |
245 let packed = PyBytes::new(py, &packed); |
268 let packed = PyBytes::new(py, &packed); |
246 let tree_metadata = PyBytes::new(py, tree_metadata.as_bytes()); |
269 let tree_metadata = PyBytes::new(py, tree_metadata.as_bytes()); |
247 let tuple = (packed, tree_metadata, append); |
270 let tuple = (packed, tree_metadata, append); |