Show More
@@ -5,6 +5,7 | |||||
5 | // This software may be used and distributed according to the terms of the |
|
5 | // This software may be used and distributed according to the terms of the | |
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::dirstate::parsers::Timestamp; | |||
8 | use crate::errors::HgError; |
|
9 | use crate::errors::HgError; | |
9 | use crate::revlog::node::NULL_NODE; |
|
10 | use crate::revlog::node::NULL_NODE; | |
10 | use crate::{ |
|
11 | use crate::{ | |
@@ -22,7 +23,6 use std::collections::HashSet; | |||||
22 | use std::convert::TryInto; |
|
23 | use std::convert::TryInto; | |
23 | use std::iter::FromIterator; |
|
24 | use std::iter::FromIterator; | |
24 | use std::ops::Deref; |
|
25 | use std::ops::Deref; | |
25 | use std::time::Duration; |
|
|||
26 |
|
26 | |||
27 | pub type FileFoldMap = FastHashMap<HgPathBuf, HgPathBuf>; |
|
27 | pub type FileFoldMap = FastHashMap<HgPathBuf, HgPathBuf>; | |
28 |
|
28 | |||
@@ -389,7 +389,7 impl DirstateMap { | |||||
389 | pub fn pack( |
|
389 | pub fn pack( | |
390 | &mut self, |
|
390 | &mut self, | |
391 | parents: DirstateParents, |
|
391 | parents: DirstateParents, | |
392 |
now: |
|
392 | now: Timestamp, | |
393 | ) -> Result<Vec<u8>, DirstateError> { |
|
393 | ) -> Result<Vec<u8>, DirstateError> { | |
394 | let packed = |
|
394 | let packed = | |
395 | pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?; |
|
395 | pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?; |
@@ -13,7 +13,6 use byteorder::{BigEndian, WriteBytesExt | |||||
13 | use bytes_cast::BytesCast; |
|
13 | use bytes_cast::BytesCast; | |
14 | use micro_timer::timed; |
|
14 | use micro_timer::timed; | |
15 | use std::convert::{TryFrom, TryInto}; |
|
15 | use std::convert::{TryFrom, TryInto}; | |
16 | use std::time::Duration; |
|
|||
17 |
|
16 | |||
18 | /// Parents are stored in the dirstate as byte hashes. |
|
17 | /// Parents are stored in the dirstate as byte hashes. | |
19 | pub const PARENT_SIZE: usize = 20; |
|
18 | pub const PARENT_SIZE: usize = 20; | |
@@ -83,15 +82,17 pub fn parse_dirstate_entries<'a>( | |||||
83 | Ok(parents) |
|
82 | Ok(parents) | |
84 | } |
|
83 | } | |
85 |
|
84 | |||
86 |
/// |
|
85 | /// Seconds since the Unix epoch | |
|
86 | pub struct Timestamp(pub u64); | |||
|
87 | ||||
87 | pub fn pack_dirstate( |
|
88 | pub fn pack_dirstate( | |
88 | state_map: &mut StateMap, |
|
89 | state_map: &mut StateMap, | |
89 | copy_map: &CopyMap, |
|
90 | copy_map: &CopyMap, | |
90 | parents: DirstateParents, |
|
91 | parents: DirstateParents, | |
91 | now: Duration, |
|
92 | now: Timestamp, | |
92 | ) -> Result<Vec<u8>, HgError> { |
|
93 | ) -> Result<Vec<u8>, HgError> { | |
93 | // TODO move away from i32 before 2038. |
|
94 | // TODO move away from i32 before 2038. | |
94 |
let now: i32 = now. |
|
95 | let now: i32 = now.0.try_into().expect("time overflow"); | |
95 |
|
96 | |||
96 | let expected_size: usize = state_map |
|
97 | let expected_size: usize = state_map | |
97 | .iter() |
|
98 | .iter() | |
@@ -171,7 +172,7 mod tests { | |||||
171 | p1: b"12345678910111213141".into(), |
|
172 | p1: b"12345678910111213141".into(), | |
172 | p2: b"00000000000000000000".into(), |
|
173 | p2: b"00000000000000000000".into(), | |
173 | }; |
|
174 | }; | |
174 |
let now = |
|
175 | let now = Timestamp(15000000); | |
175 | let expected = b"1234567891011121314100000000000000000000".to_vec(); |
|
176 | let expected = b"1234567891011121314100000000000000000000".to_vec(); | |
176 |
|
177 | |||
177 | assert_eq!( |
|
178 | assert_eq!( | |
@@ -202,7 +203,7 mod tests { | |||||
202 | p1: b"12345678910111213141".into(), |
|
203 | p1: b"12345678910111213141".into(), | |
203 | p2: b"00000000000000000000".into(), |
|
204 | p2: b"00000000000000000000".into(), | |
204 | }; |
|
205 | }; | |
205 |
let now = |
|
206 | let now = Timestamp(15000000); | |
206 | let expected = [ |
|
207 | let expected = [ | |
207 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49, |
|
208 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49, | |
208 | 51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, |
|
209 | 51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, | |
@@ -242,7 +243,7 mod tests { | |||||
242 | p1: b"12345678910111213141".into(), |
|
243 | p1: b"12345678910111213141".into(), | |
243 | p2: b"00000000000000000000".into(), |
|
244 | p2: b"00000000000000000000".into(), | |
244 | }; |
|
245 | }; | |
245 |
let now = |
|
246 | let now = Timestamp(15000000); | |
246 | let expected = [ |
|
247 | let expected = [ | |
247 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49, |
|
248 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49, | |
248 | 51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, |
|
249 | 51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, | |
@@ -282,7 +283,7 mod tests { | |||||
282 | p1: b"12345678910111213141".into(), |
|
283 | p1: b"12345678910111213141".into(), | |
283 | p2: b"00000000000000000000".into(), |
|
284 | p2: b"00000000000000000000".into(), | |
284 | }; |
|
285 | }; | |
285 |
let now = |
|
286 | let now = Timestamp(15000000); | |
286 | let result = |
|
287 | let result = | |
287 | pack_dirstate(&mut state_map, ©map, parents.clone(), now) |
|
288 | pack_dirstate(&mut state_map, ©map, parents.clone(), now) | |
288 | .unwrap(); |
|
289 | .unwrap(); | |
@@ -360,7 +361,7 mod tests { | |||||
360 | p1: b"12345678910111213141".into(), |
|
361 | p1: b"12345678910111213141".into(), | |
361 | p2: b"00000000000000000000".into(), |
|
362 | p2: b"00000000000000000000".into(), | |
362 | }; |
|
363 | }; | |
363 |
let now = |
|
364 | let now = Timestamp(15000000); | |
364 | let result = |
|
365 | let result = | |
365 | pack_dirstate(&mut state_map, ©map, parents.clone(), now) |
|
366 | pack_dirstate(&mut state_map, ©map, parents.clone(), now) | |
366 | .unwrap(); |
|
367 | .unwrap(); | |
@@ -406,7 +407,7 mod tests { | |||||
406 | p1: b"12345678910111213141".into(), |
|
407 | p1: b"12345678910111213141".into(), | |
407 | p2: b"00000000000000000000".into(), |
|
408 | p2: b"00000000000000000000".into(), | |
408 | }; |
|
409 | }; | |
409 |
let now = |
|
410 | let now = Timestamp(15000000); | |
410 | let result = |
|
411 | let result = | |
411 | pack_dirstate(&mut state_map, ©map, parents.clone(), now) |
|
412 | pack_dirstate(&mut state_map, ©map, parents.clone(), now) | |
412 | .unwrap(); |
|
413 | .unwrap(); |
@@ -1,10 +1,10 | |||||
1 | use std::collections::BTreeMap; |
|
1 | use std::collections::BTreeMap; | |
2 | use std::path::PathBuf; |
|
2 | use std::path::PathBuf; | |
3 | use std::time::Duration; |
|
|||
4 |
|
3 | |||
5 | use super::path_with_basename::WithBasename; |
|
4 | use super::path_with_basename::WithBasename; | |
6 | use crate::dirstate::parsers::parse_dirstate_entries; |
|
5 | use crate::dirstate::parsers::parse_dirstate_entries; | |
7 | use crate::dirstate::parsers::parse_dirstate_parents; |
|
6 | use crate::dirstate::parsers::parse_dirstate_parents; | |
|
7 | use crate::dirstate::parsers::Timestamp; | |||
8 |
|
8 | |||
9 | use crate::matchers::Matcher; |
|
9 | use crate::matchers::Matcher; | |
10 | use crate::revlog::node::NULL_NODE; |
|
10 | use crate::revlog::node::NULL_NODE; | |
@@ -328,7 +328,7 impl super::dispatch::DirstateMapMethods | |||||
328 | fn pack( |
|
328 | fn pack( | |
329 | &mut self, |
|
329 | &mut self, | |
330 | _parents: DirstateParents, |
|
330 | _parents: DirstateParents, | |
331 |
_now: |
|
331 | _now: Timestamp, | |
332 | ) -> Result<Vec<u8>, DirstateError> { |
|
332 | ) -> Result<Vec<u8>, DirstateError> { | |
333 | let _ = self.iter_node_data_mut(); |
|
333 | let _ = self.iter_node_data_mut(); | |
334 | todo!() |
|
334 | todo!() |
@@ -1,6 +1,6 | |||||
1 | use std::path::PathBuf; |
|
1 | use std::path::PathBuf; | |
2 | use std::time::Duration; |
|
|||
3 |
|
2 | |||
|
3 | use crate::dirstate::parsers::Timestamp; | |||
4 | use crate::matchers::Matcher; |
|
4 | use crate::matchers::Matcher; | |
5 | use crate::utils::hg_path::{HgPath, HgPathBuf}; |
|
5 | use crate::utils::hg_path::{HgPath, HgPathBuf}; | |
6 | use crate::CopyMapIter; |
|
6 | use crate::CopyMapIter; | |
@@ -90,7 +90,7 pub trait DirstateMapMethods { | |||||
90 | fn pack( |
|
90 | fn pack( | |
91 | &mut self, |
|
91 | &mut self, | |
92 | parents: DirstateParents, |
|
92 | parents: DirstateParents, | |
93 |
now: |
|
93 | now: Timestamp, | |
94 | ) -> Result<Vec<u8>, DirstateError>; |
|
94 | ) -> Result<Vec<u8>, DirstateError>; | |
95 |
|
95 | |||
96 | fn build_file_fold_map(&mut self) -> &FastHashMap<HgPathBuf, HgPathBuf>; |
|
96 | fn build_file_fold_map(&mut self) -> &FastHashMap<HgPathBuf, HgPathBuf>; | |
@@ -254,7 +254,7 impl DirstateMapMethods for DirstateMap | |||||
254 | fn pack( |
|
254 | fn pack( | |
255 | &mut self, |
|
255 | &mut self, | |
256 | parents: DirstateParents, |
|
256 | parents: DirstateParents, | |
257 |
now: |
|
257 | now: Timestamp, | |
258 | ) -> Result<Vec<u8>, DirstateError> { |
|
258 | ) -> Result<Vec<u8>, DirstateError> { | |
259 | self.pack(parents, now) |
|
259 | self.pack(parents, now) | |
260 | } |
|
260 | } |
@@ -8,7 +8,7 mod ancestors; | |||||
8 | pub mod dagops; |
|
8 | pub mod dagops; | |
9 | pub mod errors; |
|
9 | pub mod errors; | |
10 | pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; |
|
10 | pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; | |
11 | mod dirstate; |
|
11 | pub mod dirstate; | |
12 | pub mod dirstate_tree; |
|
12 | pub mod dirstate_tree; | |
13 | pub mod discovery; |
|
13 | pub mod discovery; | |
14 | pub mod requirements; |
|
14 | pub mod requirements; |
@@ -10,7 +10,6 | |||||
10 |
|
10 | |||
11 | use std::cell::{Ref, RefCell}; |
|
11 | use std::cell::{Ref, RefCell}; | |
12 | use std::convert::TryInto; |
|
12 | use std::convert::TryInto; | |
13 | use std::time::Duration; |
|
|||
14 |
|
13 | |||
15 | use cpython::{ |
|
14 | use cpython::{ | |
16 | exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, |
|
15 | exc, ObjectProtocol, PyBool, PyBytes, PyClone, PyDict, PyErr, PyList, | |
@@ -27,6 +26,7 use crate::{ | |||||
27 | parsers::dirstate_parents_to_pytuple, |
|
26 | parsers::dirstate_parents_to_pytuple, | |
28 | }; |
|
27 | }; | |
29 | use hg::{ |
|
28 | use hg::{ | |
|
29 | dirstate::parsers::Timestamp, | |||
30 | dirstate_tree::dispatch::DirstateMapMethods, |
|
30 | dirstate_tree::dispatch::DirstateMapMethods, | |
31 | errors::HgError, |
|
31 | errors::HgError, | |
32 | revlog::Node, |
|
32 | revlog::Node, | |
@@ -312,7 +312,7 py_class!(pub class DirstateMap |py| { | |||||
312 | p2: PyObject, |
|
312 | p2: PyObject, | |
313 | now: PyObject |
|
313 | now: PyObject | |
314 | ) -> PyResult<PyBytes> { |
|
314 | ) -> PyResult<PyBytes> { | |
315 |
let now = |
|
315 | let now = Timestamp(now.extract(py)?); | |
316 | let parents = DirstateParents { |
|
316 | let parents = DirstateParents { | |
317 | p1: extract_node_id(py, &p1)?, |
|
317 | p1: extract_node_id(py, &p1)?, | |
318 | p2: extract_node_id(py, &p2)?, |
|
318 | p2: extract_node_id(py, &p2)?, |
@@ -14,13 +14,13 use cpython::{ | |||||
14 | PythonObject, ToPyObject, |
|
14 | PythonObject, ToPyObject, | |
15 | }; |
|
15 | }; | |
16 | use hg::{ |
|
16 | use hg::{ | |
17 | pack_dirstate, parse_dirstate, utils::hg_path::HgPathBuf, DirstateEntry, |
|
17 | dirstate::parsers::Timestamp, pack_dirstate, parse_dirstate, | |
18 | DirstateParents, FastHashMap, PARENT_SIZE, |
|
18 | utils::hg_path::HgPathBuf, DirstateEntry, DirstateParents, FastHashMap, | |
|
19 | PARENT_SIZE, | |||
19 | }; |
|
20 | }; | |
20 | use std::convert::TryInto; |
|
21 | use std::convert::TryInto; | |
21 |
|
22 | |||
22 | use crate::dirstate::{extract_dirstate, make_dirstate_tuple}; |
|
23 | use crate::dirstate::{extract_dirstate, make_dirstate_tuple}; | |
23 | use std::time::Duration; |
|
|||
24 |
|
24 | |||
25 | fn parse_dirstate_wrapper( |
|
25 | fn parse_dirstate_wrapper( | |
26 | py: Python, |
|
26 | py: Python, | |
@@ -98,7 +98,7 fn pack_dirstate_wrapper( | |||||
98 | p1: p1.try_into().unwrap(), |
|
98 | p1: p1.try_into().unwrap(), | |
99 | p2: p2.try_into().unwrap(), |
|
99 | p2: p2.try_into().unwrap(), | |
100 | }, |
|
100 | }, | |
101 |
|
|
101 | Timestamp(now.as_object().extract::<u64>(py)?), | |
102 | ) { |
|
102 | ) { | |
103 | Ok(packed) => { |
|
103 | Ok(packed) => { | |
104 | for (filename, entry) in dirstate_map.iter() { |
|
104 | for (filename, entry) in dirstate_map.iter() { |
General Comments 0
You need to be logged in to leave comments.
Login now