Show More
@@ -6,6 +6,7 b'' | |||||
6 | // GNU General Public License version 2 or any later version. |
|
6 | // GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | use crate::errors::HgError; |
|
8 | use crate::errors::HgError; | |
|
9 | use crate::revlog::Node; | |||
9 | use crate::{utils::hg_path::HgPathBuf, FastHashMap}; |
|
10 | use crate::{utils::hg_path::HgPathBuf, FastHashMap}; | |
10 | use bytes_cast::{unaligned, BytesCast}; |
|
11 | use bytes_cast::{unaligned, BytesCast}; | |
11 | use std::collections::hash_map; |
|
12 | use std::collections::hash_map; | |
@@ -21,8 +22,8 b' pub mod status;' | |||||
21 | #[derive(Debug, PartialEq, Clone, BytesCast)] |
|
22 | #[derive(Debug, PartialEq, Clone, BytesCast)] | |
22 | #[repr(C)] |
|
23 | #[repr(C)] | |
23 | pub struct DirstateParents { |
|
24 | pub struct DirstateParents { | |
24 |
pub p1: |
|
25 | pub p1: Node, | |
25 |
pub p2: |
|
26 | pub p2: Node, | |
26 | } |
|
27 | } | |
27 |
|
28 | |||
28 | /// The C implementation uses all signed types. This will be an issue |
|
29 | /// The C implementation uses all signed types. This will be an issue |
@@ -6,7 +6,7 b'' | |||||
6 | // GNU General Public License version 2 or any later version. |
|
6 | // GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | use crate::errors::HgError; |
|
8 | use crate::errors::HgError; | |
9 |
use crate::revlog::node::NULL_NODE |
|
9 | use crate::revlog::node::NULL_NODE; | |
10 | use crate::{ |
|
10 | use crate::{ | |
11 | dirstate::{parsers::PARENT_SIZE, EntryState, SIZE_FROM_OTHER_PARENT}, |
|
11 | dirstate::{parsers::PARENT_SIZE, EntryState, SIZE_FROM_OTHER_PARENT}, | |
12 | pack_dirstate, parse_dirstate, |
|
12 | pack_dirstate, parse_dirstate, | |
@@ -73,8 +73,8 b' impl DirstateMap {' | |||||
73 | self.non_normal_set = None; |
|
73 | self.non_normal_set = None; | |
74 | self.other_parent_set = None; |
|
74 | self.other_parent_set = None; | |
75 | self.set_parents(&DirstateParents { |
|
75 | self.set_parents(&DirstateParents { | |
76 |
p1: NULL_NODE |
|
76 | p1: NULL_NODE, | |
77 |
p2: NULL_NODE |
|
77 | p2: NULL_NODE, | |
78 | }) |
|
78 | }) | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
@@ -367,8 +367,8 b' impl DirstateMap {' | |||||
367 | }; |
|
367 | }; | |
368 | } else if file_contents.is_empty() { |
|
368 | } else if file_contents.is_empty() { | |
369 | parents = DirstateParents { |
|
369 | parents = DirstateParents { | |
370 |
p1: NULL_NODE |
|
370 | p1: NULL_NODE, | |
371 |
p2: NULL_NODE |
|
371 | p2: NULL_NODE, | |
372 | }; |
|
372 | }; | |
373 | } else { |
|
373 | } else { | |
374 | return Err( |
|
374 | return Err( |
@@ -89,8 +89,8 b' pub fn pack_dirstate(' | |||||
89 |
|
89 | |||
90 | let mut packed = Vec::with_capacity(expected_size); |
|
90 | let mut packed = Vec::with_capacity(expected_size); | |
91 |
|
91 | |||
92 |
packed.extend( |
|
92 | packed.extend(parents.p1.as_bytes()); | |
93 |
packed.extend( |
|
93 | packed.extend(parents.p2.as_bytes()); | |
94 |
|
94 | |||
95 | for (filename, entry) in state_map.iter_mut() { |
|
95 | for (filename, entry) in state_map.iter_mut() { | |
96 | let new_filename = filename.to_owned(); |
|
96 | let new_filename = filename.to_owned(); | |
@@ -223,8 +223,8 b' mod tests {' | |||||
223 | let mut state_map = StateMap::default(); |
|
223 | let mut state_map = StateMap::default(); | |
224 | let copymap = FastHashMap::default(); |
|
224 | let copymap = FastHashMap::default(); | |
225 | let parents = DirstateParents { |
|
225 | let parents = DirstateParents { | |
226 |
p1: |
|
226 | p1: b"12345678910111213141".into(), | |
227 |
p2: |
|
227 | p2: b"00000000000000000000".into(), | |
228 | }; |
|
228 | }; | |
229 | let now = Duration::new(15000000, 0); |
|
229 | let now = Duration::new(15000000, 0); | |
230 | let expected = b"1234567891011121314100000000000000000000".to_vec(); |
|
230 | let expected = b"1234567891011121314100000000000000000000".to_vec(); | |
@@ -254,8 +254,8 b' mod tests {' | |||||
254 |
|
254 | |||
255 | let copymap = FastHashMap::default(); |
|
255 | let copymap = FastHashMap::default(); | |
256 | let parents = DirstateParents { |
|
256 | let parents = DirstateParents { | |
257 |
p1: |
|
257 | p1: b"12345678910111213141".into(), | |
258 |
p2: |
|
258 | p2: b"00000000000000000000".into(), | |
259 | }; |
|
259 | }; | |
260 | let now = Duration::new(15000000, 0); |
|
260 | let now = Duration::new(15000000, 0); | |
261 | let expected = [ |
|
261 | let expected = [ | |
@@ -294,8 +294,8 b' mod tests {' | |||||
294 | HgPathBuf::from_bytes(b"copyname"), |
|
294 | HgPathBuf::from_bytes(b"copyname"), | |
295 | ); |
|
295 | ); | |
296 | let parents = DirstateParents { |
|
296 | let parents = DirstateParents { | |
297 |
p1: |
|
297 | p1: b"12345678910111213141".into(), | |
298 |
p2: |
|
298 | p2: b"00000000000000000000".into(), | |
299 | }; |
|
299 | }; | |
300 | let now = Duration::new(15000000, 0); |
|
300 | let now = Duration::new(15000000, 0); | |
301 | let expected = [ |
|
301 | let expected = [ | |
@@ -334,8 +334,8 b' mod tests {' | |||||
334 | HgPathBuf::from_bytes(b"copyname"), |
|
334 | HgPathBuf::from_bytes(b"copyname"), | |
335 | ); |
|
335 | ); | |
336 | let parents = DirstateParents { |
|
336 | let parents = DirstateParents { | |
337 |
p1: |
|
337 | p1: b"12345678910111213141".into(), | |
338 |
p2: |
|
338 | p2: b"00000000000000000000".into(), | |
339 | }; |
|
339 | }; | |
340 | let now = Duration::new(15000000, 0); |
|
340 | let now = Duration::new(15000000, 0); | |
341 | let result = |
|
341 | let result = | |
@@ -412,8 +412,8 b' mod tests {' | |||||
412 | HgPathBuf::from_bytes(b"copyname2"), |
|
412 | HgPathBuf::from_bytes(b"copyname2"), | |
413 | ); |
|
413 | ); | |
414 | let parents = DirstateParents { |
|
414 | let parents = DirstateParents { | |
415 |
p1: |
|
415 | p1: b"12345678910111213141".into(), | |
416 |
p2: |
|
416 | p2: b"00000000000000000000".into(), | |
417 | }; |
|
417 | }; | |
418 | let now = Duration::new(15000000, 0); |
|
418 | let now = Duration::new(15000000, 0); | |
419 | let result = |
|
419 | let result = | |
@@ -458,8 +458,8 b' mod tests {' | |||||
458 | HgPathBuf::from_bytes(b"copyname"), |
|
458 | HgPathBuf::from_bytes(b"copyname"), | |
459 | ); |
|
459 | ); | |
460 | let parents = DirstateParents { |
|
460 | let parents = DirstateParents { | |
461 |
p1: |
|
461 | p1: b"12345678910111213141".into(), | |
462 |
p2: |
|
462 | p2: b"00000000000000000000".into(), | |
463 | }; |
|
463 | }; | |
464 | let now = Duration::new(15000000, 0); |
|
464 | let now = Duration::new(15000000, 0); | |
465 | let result = |
|
465 | let result = |
@@ -85,6 +85,13 b" impl TryFrom<&'_ [u8]> for Node {" | |||||
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
|
88 | impl From<&'_ NodeData> for Node { | |||
|
89 | #[inline] | |||
|
90 | fn from(data: &'_ NodeData) -> Self { | |||
|
91 | Self { data: *data } | |||
|
92 | } | |||
|
93 | } | |||
|
94 | ||||
88 | impl fmt::LowerHex for Node { |
|
95 | impl fmt::LowerHex for Node { | |
89 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
96 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
90 | for &byte in &self.data { |
|
97 | for &byte in &self.data { |
@@ -24,12 +24,14 b' use crate::{' | |||||
24 | NonNormalEntries, NonNormalEntriesIterator, |
|
24 | NonNormalEntries, NonNormalEntriesIterator, | |
25 | }, |
|
25 | }, | |
26 | dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, |
|
26 | dirstate::{dirs_multiset::Dirs, make_dirstate_tuple}, | |
|
27 | parsers::dirstate_parents_to_pytuple, | |||
27 | }; |
|
28 | }; | |
28 | use hg::{ |
|
29 | use hg::{ | |
29 | errors::HgError, |
|
30 | errors::HgError, | |
|
31 | revlog::Node, | |||
30 | utils::hg_path::{HgPath, HgPathBuf}, |
|
32 | utils::hg_path::{HgPath, HgPathBuf}, | |
31 | DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, |
|
33 | DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, | |
32 |
DirstateMapError, DirstateParents, EntryState, StateMapIter, |
|
34 | DirstateMapError, DirstateParents, EntryState, StateMapIter, | |
33 | }; |
|
35 | }; | |
34 |
|
36 | |||
35 | // TODO |
|
37 | // TODO | |
@@ -285,10 +287,7 b' py_class!(pub class DirstateMap |py| {' | |||||
285 | def parents(&self, st: PyObject) -> PyResult<PyTuple> { |
|
287 | def parents(&self, st: PyObject) -> PyResult<PyTuple> { | |
286 | self.inner(py).borrow_mut() |
|
288 | self.inner(py).borrow_mut() | |
287 | .parents(st.extract::<PyBytes>(py)?.data(py)) |
|
289 | .parents(st.extract::<PyBytes>(py)?.data(py)) | |
288 | .and_then(|d| { |
|
290 | .map(|parents| dirstate_parents_to_pytuple(py, parents)) | |
289 | Ok((PyBytes::new(py, &d.p1), PyBytes::new(py, &d.p2)) |
|
|||
290 | .to_py_object(py)) |
|
|||
291 | }) |
|
|||
292 | .or_else(|_| { |
|
291 | .or_else(|_| { | |
293 | Err(PyErr::new::<exc::OSError, _>( |
|
292 | Err(PyErr::new::<exc::OSError, _>( | |
294 | py, |
|
293 | py, | |
@@ -311,9 +310,8 b' py_class!(pub class DirstateMap |py| {' | |||||
311 | .read(st.extract::<PyBytes>(py)?.data(py)) |
|
310 | .read(st.extract::<PyBytes>(py)?.data(py)) | |
312 | { |
|
311 | { | |
313 | Ok(Some(parents)) => Ok(Some( |
|
312 | Ok(Some(parents)) => Ok(Some( | |
314 |
|
|
313 | dirstate_parents_to_pytuple(py, parents) | |
315 |
.to |
|
314 | .into_object() | |
316 | .into_object(), |
|
|||
317 | )), |
|
315 | )), | |
318 | Ok(None) => Ok(Some(py.None())), |
|
316 | Ok(None) => Ok(Some(py.None())), | |
319 | Err(_) => Err(PyErr::new::<exc::OSError, _>( |
|
317 | Err(_) => Err(PyErr::new::<exc::OSError, _>( | |
@@ -601,7 +599,7 b' py_shared_iterator!(' | |||||
601 | Option<(PyBytes, PyObject)> |
|
599 | Option<(PyBytes, PyObject)> | |
602 | ); |
|
600 | ); | |
603 |
|
601 | |||
604 |
fn extract_node_id(py: Python, obj: &PyObject) -> PyResult< |
|
602 | fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<Node> { | |
605 | let bytes = obj.extract::<PyBytes>(py)?; |
|
603 | let bytes = obj.extract::<PyBytes>(py)?; | |
606 | match bytes.data(py).try_into() { |
|
604 | match bytes.data(py).try_into() { | |
607 | Ok(s) => Ok(s), |
|
605 | Ok(s) => Ok(s), |
@@ -53,10 +53,7 b' fn parse_dirstate_wrapper(' | |||||
53 | PyBytes::new(py, copy_path.as_bytes()), |
|
53 | PyBytes::new(py, copy_path.as_bytes()), | |
54 | )?; |
|
54 | )?; | |
55 | } |
|
55 | } | |
56 | Ok( |
|
56 | Ok(dirstate_parents_to_pytuple(py, parents)) | |
57 | (PyBytes::new(py, &parents.p1), PyBytes::new(py, &parents.p2)) |
|
|||
58 | .to_py_object(py), |
|
|||
59 | ) |
|
|||
60 | } |
|
57 | } | |
61 | Err(e) => Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())), |
|
58 | Err(e) => Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())), | |
62 | } |
|
59 | } | |
@@ -155,3 +152,12 b' pub fn init_parsers_module(py: Python, p' | |||||
155 |
|
152 | |||
156 | Ok(m) |
|
153 | Ok(m) | |
157 | } |
|
154 | } | |
|
155 | ||||
|
156 | pub(crate) fn dirstate_parents_to_pytuple( | |||
|
157 | py: Python, | |||
|
158 | parents: &DirstateParents, | |||
|
159 | ) -> PyTuple { | |||
|
160 | let p1 = PyBytes::new(py, parents.p1.as_bytes()); | |||
|
161 | let p2 = PyBytes::new(py, parents.p2.as_bytes()); | |||
|
162 | (p1, p2).to_py_object(py) | |||
|
163 | } |
General Comments 0
You need to be logged in to leave comments.
Login now