Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 49101:dd0430434ce9
rust-dirstatemap: add Rust implementation of `reset_state`
This is the new API which has already been defined in Python
Differential Revision: https://phab.mercurial-scm.org/D12499
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 23 Mar 2022 17:27:58 +0100 |
parents | 55c158a33fa5 |
children | b5c2aca84618 |
comparison
equal
deleted
inserted
replaced
49100:38e5bb1425dd | 49101:dd0430434ce9 |
---|---|
13 | 13 |
14 use cpython::{ | 14 use cpython::{ |
15 exc, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, PyNone, PyObject, | 15 exc, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, PyNone, PyObject, |
16 PyResult, Python, PythonObject, ToPyObject, UnsafePyLeaked, | 16 PyResult, Python, PythonObject, ToPyObject, UnsafePyLeaked, |
17 }; | 17 }; |
18 use hg::dirstate::{ParentFileData, TruncatedTimestamp}; | |
18 | 19 |
19 use crate::{ | 20 use crate::{ |
20 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, | 21 dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator}, |
21 dirstate::item::DirstateItem, | 22 dirstate::item::DirstateItem, |
22 pybytes_deref::PyBytesDeref, | 23 pybytes_deref::PyBytesDeref, |
139 Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string())) | 140 Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string())) |
140 })?; | 141 })?; |
141 Ok(was_tracked.to_py_object(py)) | 142 Ok(was_tracked.to_py_object(py)) |
142 } | 143 } |
143 | 144 |
145 def reset_state( | |
146 &self, | |
147 f: PyObject, | |
148 wc_tracked: bool, | |
149 p1_tracked: bool, | |
150 p2_info: bool, | |
151 has_meaningful_mtime: bool, | |
152 parentfiledata: Option<(u32, u32, Option<(i64, u32, bool)>)>, | |
153 ) -> PyResult<PyNone> { | |
154 let mut has_meaningful_mtime = has_meaningful_mtime; | |
155 let parent_file_data = match parentfiledata { | |
156 None => { | |
157 has_meaningful_mtime = false; | |
158 None | |
159 }, | |
160 Some(data) => { | |
161 let (mode, size, mtime_info) = data; | |
162 let mtime = if let Some(mtime_info) = mtime_info { | |
163 let (mtime_s, mtime_ns, second_ambiguous) = mtime_info; | |
164 let timestamp = TruncatedTimestamp::new_truncate( | |
165 mtime_s, mtime_ns, second_ambiguous | |
166 ); | |
167 Some(timestamp) | |
168 } else { | |
169 has_meaningful_mtime = false; | |
170 None | |
171 }; | |
172 Some(ParentFileData { | |
173 mode_size: Some((mode, size)), | |
174 mtime, | |
175 }) | |
176 } | |
177 }; | |
178 let bytes = f.extract::<PyBytes>(py)?; | |
179 let path = HgPath::new(bytes.data(py)); | |
180 let res = self.inner(py).borrow_mut().reset_state( | |
181 path, | |
182 wc_tracked, | |
183 p1_tracked, | |
184 p2_info, | |
185 has_meaningful_mtime, | |
186 parent_file_data, | |
187 ); | |
188 res.or_else(|_| { | |
189 Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string())) | |
190 })?; | |
191 Ok(PyNone) | |
192 } | |
193 | |
144 def removefile( | 194 def removefile( |
145 &self, | 195 &self, |
146 f: PyObject, | 196 f: PyObject, |
147 in_merge: PyObject | 197 in_merge: PyObject |
148 ) -> PyResult<PyObject> { | 198 ) -> PyResult<PyObject> { |