author | Raphaël Gomès <rgomes@octobus.net> |
Thu, 01 Oct 2020 09:48:41 +0200 | |
changeset 45646 | 1efbc787334c |
parent 45610 | 496537c9c1b4 |
child 46439 | 68a15b5a7e58 |
permissions | -rw-r--r-- |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
1 |
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
2 |
// |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
3 |
// This software may be used and distributed according to the terms of the |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
4 |
// GNU General Public License version 2 or any later version. |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
5 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
6 |
use crate::utils::hg_path::HgPath; |
42609
326fdce22fb2
rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents:
42424
diff
changeset
|
7 |
use crate::{ |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
8 |
dirstate::{CopyMap, EntryState, StateMap}, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
9 |
DirstateEntry, DirstatePackError, DirstateParents, DirstateParseError, |
42609
326fdce22fb2
rust: switch hg-core and hg-cpython to rust 2018 edition
Raphaël Gomès <rgomes@octobus.net>
parents:
42424
diff
changeset
|
10 |
}; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
11 |
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; |
44541
d880805d5442
hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
12 |
use micro_timer::timed; |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
13 |
use std::convert::{TryFrom, TryInto}; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 |
use std::io::Cursor; |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
15 |
use std::time::Duration; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
16 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
/// Parents are stored in the dirstate as byte hashes. |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
18 |
pub const PARENT_SIZE: usize = 20; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 |
/// Dirstate entries have a static part of 8 + 32 + 32 + 32 + 32 bits. |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 |
const MIN_ENTRY_SIZE: usize = 17; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
|
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
22 |
type ParseResult<'a> = ( |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
23 |
DirstateParents, |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
24 |
Vec<(&'a HgPath, DirstateEntry)>, |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
25 |
Vec<(&'a HgPath, &'a HgPath)>, |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
26 |
); |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
27 |
|
44541
d880805d5442
hg-core: add function timing information
Raphaël Gomès <rgomes@octobus.net>
parents:
43826
diff
changeset
|
28 |
#[timed] |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 |
pub fn parse_dirstate( |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 |
contents: &[u8], |
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
31 |
) -> Result<ParseResult, DirstateParseError> { |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
if contents.len() < PARENT_SIZE * 2 { |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
return Err(DirstateParseError::TooLittleData); |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
} |
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
35 |
let mut copies = vec![]; |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
36 |
let mut entries = vec![]; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
37 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
38 |
let mut curr_pos = PARENT_SIZE * 2; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
let parents = DirstateParents { |
42799
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42794
diff
changeset
|
40 |
p1: contents[..PARENT_SIZE].try_into().unwrap(), |
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42794
diff
changeset
|
41 |
p2: contents[PARENT_SIZE..curr_pos].try_into().unwrap(), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
}; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
while curr_pos < contents.len() { |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 |
if curr_pos + MIN_ENTRY_SIZE > contents.len() { |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
return Err(DirstateParseError::Overflow); |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
let entry_bytes = &contents[curr_pos..]; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
49 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
50 |
let mut cursor = Cursor::new(entry_bytes); |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
51 |
let state = EntryState::try_from(cursor.read_u8()?)?; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
52 |
let mode = cursor.read_i32::<BigEndian>()?; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
53 |
let size = cursor.read_i32::<BigEndian>()?; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 |
let mtime = cursor.read_i32::<BigEndian>()?; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
let path_len = cursor.read_i32::<BigEndian>()? as usize; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 |
if path_len > contents.len() - curr_pos { |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 |
return Err(DirstateParseError::Overflow); |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
59 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
60 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
// Slice instead of allocating a Vec needed for `read_exact` |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 |
let path = &entry_bytes[MIN_ENTRY_SIZE..MIN_ENTRY_SIZE + (path_len)]; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 |
let (path, copy) = match memchr::memchr(0, path) { |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 |
None => (path, None), |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
Some(i) => (&path[..i], Some(&path[(i + 1)..])), |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 |
}; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
68 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
69 |
if let Some(copy_path) = copy { |
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
70 |
copies.push((HgPath::new(path), HgPath::new(copy_path))); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
}; |
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
72 |
entries.push(( |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
73 |
HgPath::new(path), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
74 |
DirstateEntry { |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
75 |
state, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
76 |
mode, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 |
size, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
mtime, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
}, |
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
80 |
)); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 |
curr_pos = curr_pos + MIN_ENTRY_SIZE + (path_len); |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 |
} |
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
83 |
Ok((parents, entries, copies)) |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 |
|
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
86 |
/// `now` is the duration in seconds since the Unix epoch |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
87 |
#[cfg(not(feature = "dirstate-tree"))] |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 |
pub fn pack_dirstate( |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
89 |
state_map: &mut StateMap, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
90 |
copy_map: &CopyMap, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 |
parents: DirstateParents, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
92 |
now: Duration, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
93 |
) -> Result<Vec<u8>, DirstatePackError> { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
94 |
// TODO move away from i32 before 2038. |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
95 |
let now: i32 = now.as_secs().try_into().expect("time overflow"); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
|
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
97 |
let expected_size: usize = state_map |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 |
.iter() |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
99 |
.map(|(filename, _)| { |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 |
let mut length = MIN_ENTRY_SIZE + filename.len(); |
42794
cc424cc16704
rust-dirstate: remove unneeded "ref"
Yuya Nishihara <yuya@tcha.org>
parents:
42749
diff
changeset
|
101 |
if let Some(copy) = copy_map.get(filename) { |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 |
length += copy.len() + 1; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
104 |
length |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
}) |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 |
.sum(); |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
107 |
let expected_size = expected_size + PARENT_SIZE * 2; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
108 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 |
let mut packed = Vec::with_capacity(expected_size); |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 |
|
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
111 |
packed.extend(&parents.p1); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
112 |
packed.extend(&parents.p2); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
113 |
|
45646
1efbc787334c
rust-parsers: use in-place mutation instead of allocating a new `Vec`
Raphaël Gomès <rgomes@octobus.net>
parents:
45610
diff
changeset
|
114 |
for (filename, entry) in state_map.iter_mut() { |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
115 |
let new_filename = filename.to_owned(); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 |
let mut new_mtime: i32 = entry.mtime; |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
117 |
if entry.state == EntryState::Normal && entry.mtime == now { |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 |
// The file was last modified "simultaneously" with the current |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 |
// write to dirstate (i.e. within the same second for file- |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 |
// systems with a granularity of 1 sec). This commonly happens |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 |
// for at least a couple of files on 'update'. |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
122 |
// The user could change the file without changing its size |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
123 |
// within the same second. Invalidate the file's mtime in |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
124 |
// dirstate, forcing future 'status' calls to compare the |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 |
// contents of the file if the size is the same. This prevents |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 |
// mistakenly treating such files as clean. |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
new_mtime = -1; |
45646
1efbc787334c
rust-parsers: use in-place mutation instead of allocating a new `Vec`
Raphaël Gomès <rgomes@octobus.net>
parents:
45610
diff
changeset
|
128 |
*entry = DirstateEntry { |
1efbc787334c
rust-parsers: use in-place mutation instead of allocating a new `Vec`
Raphaël Gomès <rgomes@octobus.net>
parents:
45610
diff
changeset
|
129 |
mtime: new_mtime, |
1efbc787334c
rust-parsers: use in-place mutation instead of allocating a new `Vec`
Raphaël Gomès <rgomes@octobus.net>
parents:
45610
diff
changeset
|
130 |
..*entry |
1efbc787334c
rust-parsers: use in-place mutation instead of allocating a new `Vec`
Raphaël Gomès <rgomes@octobus.net>
parents:
45610
diff
changeset
|
131 |
}; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 |
} |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
133 |
let mut new_filename = new_filename.into_vec(); |
42794
cc424cc16704
rust-dirstate: remove unneeded "ref"
Yuya Nishihara <yuya@tcha.org>
parents:
42749
diff
changeset
|
134 |
if let Some(copy) = copy_map.get(filename) { |
44973
26114bd6ec60
rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents:
44541
diff
changeset
|
135 |
new_filename.push(b'\0'); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
136 |
new_filename.extend(copy.bytes()); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 |
|
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
139 |
packed.write_u8(entry.state.into())?; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 |
packed.write_i32::<BigEndian>(entry.mode)?; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 |
packed.write_i32::<BigEndian>(entry.size)?; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 |
packed.write_i32::<BigEndian>(new_mtime)?; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
143 |
packed.write_i32::<BigEndian>(new_filename.len() as i32)?; |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
144 |
packed.extend(new_filename) |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
145 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
146 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
147 |
if packed.len() != expected_size { |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
148 |
return Err(DirstatePackError::BadSize(expected_size, packed.len())); |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
149 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
150 |
|
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
151 |
Ok(packed) |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
152 |
} |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
153 |
/// `now` is the duration in seconds since the Unix epoch |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
154 |
#[cfg(feature = "dirstate-tree")] |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
155 |
pub fn pack_dirstate( |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
156 |
state_map: &mut StateMap, |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
157 |
copy_map: &CopyMap, |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
158 |
parents: DirstateParents, |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
159 |
now: Duration, |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
160 |
) -> Result<Vec<u8>, DirstatePackError> { |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
161 |
// TODO move away from i32 before 2038. |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
162 |
let now: i32 = now.as_secs().try_into().expect("time overflow"); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
163 |
|
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
164 |
let expected_size: usize = state_map |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
165 |
.iter() |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
166 |
.map(|(filename, _)| { |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
167 |
let mut length = MIN_ENTRY_SIZE + filename.len(); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
168 |
if let Some(copy) = copy_map.get(&filename) { |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
169 |
length += copy.len() + 1; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
170 |
} |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
171 |
length |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
172 |
}) |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
173 |
.sum(); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
174 |
let expected_size = expected_size + PARENT_SIZE * 2; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
175 |
|
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
176 |
let mut packed = Vec::with_capacity(expected_size); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
177 |
let mut new_state_map = vec![]; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
178 |
|
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
179 |
packed.extend(&parents.p1); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
180 |
packed.extend(&parents.p2); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
181 |
|
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
182 |
for (filename, entry) in state_map.iter() { |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
183 |
let new_filename = filename.to_owned(); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
184 |
let mut new_mtime: i32 = entry.mtime; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
185 |
if entry.state == EntryState::Normal && entry.mtime == now { |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
186 |
// The file was last modified "simultaneously" with the current |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
187 |
// write to dirstate (i.e. within the same second for file- |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
188 |
// systems with a granularity of 1 sec). This commonly happens |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
189 |
// for at least a couple of files on 'update'. |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
190 |
// The user could change the file without changing its size |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
191 |
// within the same second. Invalidate the file's mtime in |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
192 |
// dirstate, forcing future 'status' calls to compare the |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
193 |
// contents of the file if the size is the same. This prevents |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
194 |
// mistakenly treating such files as clean. |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
195 |
new_mtime = -1; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
196 |
new_state_map.push(( |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
197 |
filename.to_owned(), |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
198 |
DirstateEntry { |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
199 |
mtime: new_mtime, |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
200 |
..entry |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
201 |
}, |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
202 |
)); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
203 |
} |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
204 |
let mut new_filename = new_filename.into_vec(); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
205 |
if let Some(copy) = copy_map.get(&filename) { |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
206 |
new_filename.push(b'\0'); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
207 |
new_filename.extend(copy.bytes()); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
208 |
} |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
209 |
|
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
210 |
packed.write_u8(entry.state.into())?; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
211 |
packed.write_i32::<BigEndian>(entry.mode)?; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
212 |
packed.write_i32::<BigEndian>(entry.size)?; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
213 |
packed.write_i32::<BigEndian>(new_mtime)?; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
214 |
packed.write_i32::<BigEndian>(new_filename.len() as i32)?; |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
215 |
packed.extend(new_filename) |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
216 |
} |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
217 |
|
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
218 |
if packed.len() != expected_size { |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
219 |
return Err(DirstatePackError::BadSize(expected_size, packed.len())); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
220 |
} |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
221 |
|
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
222 |
state_map.extend(new_state_map); |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
223 |
|
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
224 |
Ok(packed) |
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
225 |
} |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
227 |
#[cfg(test)] |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
228 |
mod tests { |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
229 |
use super::*; |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
230 |
use crate::{utils::hg_path::HgPathBuf, FastHashMap}; |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
231 |
use pretty_assertions::assert_eq; |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
232 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
233 |
#[test] |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
234 |
fn test_pack_dirstate_empty() { |
45610
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45357
diff
changeset
|
235 |
let mut state_map = StateMap::default(); |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
236 |
let copymap = FastHashMap::default(); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 |
let parents = DirstateParents { |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
238 |
p1: *b"12345678910111213141", |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
239 |
p2: *b"00000000000000000000", |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
240 |
}; |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
241 |
let now = Duration::new(15000000, 0); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
242 |
let expected = b"1234567891011121314100000000000000000000".to_vec(); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 |
assert_eq!( |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 |
expected, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
246 |
pack_dirstate(&mut state_map, ©map, parents, now).unwrap() |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 |
); |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
248 |
|
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
249 |
assert!(state_map.is_empty()) |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
251 |
#[test] |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 |
fn test_pack_dirstate_one_entry() { |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
253 |
let expected_state_map: StateMap = [( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
254 |
HgPathBuf::from_bytes(b"f1"), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
255 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
256 |
state: EntryState::Normal, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 |
mode: 0o644, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 |
size: 0, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
259 |
mtime: 791231220, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 |
}, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
261 |
)] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
262 |
.iter() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
263 |
.cloned() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
264 |
.collect(); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
265 |
let mut state_map = expected_state_map.clone(); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
266 |
|
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
267 |
let copymap = FastHashMap::default(); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
268 |
let parents = DirstateParents { |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
269 |
p1: *b"12345678910111213141", |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
270 |
p2: *b"00000000000000000000", |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 |
}; |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
272 |
let now = Duration::new(15000000, 0); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
273 |
let expected = [ |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
274 |
49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
275 |
51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
276 |
48, 48, 48, 48, 48, 48, 48, 48, 110, 0, 0, 1, 164, 0, 0, 0, 0, 47, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
277 |
41, 58, 244, 0, 0, 0, 2, 102, 49, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
278 |
] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
279 |
.to_vec(); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
280 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
281 |
assert_eq!( |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
282 |
expected, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
283 |
pack_dirstate(&mut state_map, ©map, parents, now).unwrap() |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
284 |
); |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 |
|
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
286 |
assert_eq!(expected_state_map, state_map); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
287 |
} |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 |
#[test] |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
289 |
fn test_pack_dirstate_one_entry_with_copy() { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
290 |
let expected_state_map: StateMap = [( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
291 |
HgPathBuf::from_bytes(b"f1"), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
292 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
293 |
state: EntryState::Normal, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 |
mode: 0o644, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 |
size: 0, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
296 |
mtime: 791231220, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 |
}, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
298 |
)] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
299 |
.iter() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
300 |
.cloned() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
301 |
.collect(); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
302 |
let mut state_map = expected_state_map.clone(); |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
303 |
let mut copymap = FastHashMap::default(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
304 |
copymap.insert( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
305 |
HgPathBuf::from_bytes(b"f1"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
306 |
HgPathBuf::from_bytes(b"copyname"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
307 |
); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
308 |
let parents = DirstateParents { |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
309 |
p1: *b"12345678910111213141", |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
310 |
p2: *b"00000000000000000000", |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
311 |
}; |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
312 |
let now = Duration::new(15000000, 0); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
313 |
let expected = [ |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
314 |
49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
315 |
51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
316 |
48, 48, 48, 48, 48, 48, 48, 48, 110, 0, 0, 1, 164, 0, 0, 0, 0, 47, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
317 |
41, 58, 244, 0, 0, 0, 11, 102, 49, 0, 99, 111, 112, 121, 110, 97, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
318 |
109, 101, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
319 |
] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
320 |
.to_vec(); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
321 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 |
assert_eq!( |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
323 |
expected, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
324 |
pack_dirstate(&mut state_map, ©map, parents, now).unwrap() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
325 |
); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
326 |
assert_eq!(expected_state_map, state_map); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
327 |
} |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
328 |
|
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
329 |
#[test] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
330 |
fn test_parse_pack_one_entry_with_copy() { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
331 |
let mut state_map: StateMap = [( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
332 |
HgPathBuf::from_bytes(b"f1"), |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
333 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
334 |
state: EntryState::Normal, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
335 |
mode: 0o644, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
336 |
size: 0, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
337 |
mtime: 791231220, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
338 |
}, |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
339 |
)] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
340 |
.iter() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
341 |
.cloned() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
342 |
.collect(); |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
343 |
let mut copymap = FastHashMap::default(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
344 |
copymap.insert( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
345 |
HgPathBuf::from_bytes(b"f1"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
346 |
HgPathBuf::from_bytes(b"copyname"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
347 |
); |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
348 |
let parents = DirstateParents { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
349 |
p1: *b"12345678910111213141", |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
350 |
p2: *b"00000000000000000000", |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
351 |
}; |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
352 |
let now = Duration::new(15000000, 0); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
353 |
let result = |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
354 |
pack_dirstate(&mut state_map, ©map, parents.clone(), now) |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
355 |
.unwrap(); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
356 |
|
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
357 |
let (new_parents, entries, copies) = |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
358 |
parse_dirstate(result.as_slice()).unwrap(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
359 |
let new_state_map: StateMap = entries |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
360 |
.into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
361 |
.map(|(path, entry)| (path.to_owned(), entry)) |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
362 |
.collect(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
363 |
let new_copy_map: CopyMap = copies |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
364 |
.into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
365 |
.map(|(path, copy)| (path.to_owned(), copy.to_owned())) |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
366 |
.collect(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
367 |
|
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
368 |
assert_eq!( |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
369 |
(parents, state_map, copymap), |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
370 |
(new_parents, new_state_map, new_copy_map) |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
371 |
) |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
372 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
373 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
374 |
#[test] |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
375 |
fn test_parse_pack_multiple_entries_with_copy() { |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
376 |
let mut state_map: StateMap = [ |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
377 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
378 |
HgPathBuf::from_bytes(b"f1"), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
379 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
380 |
state: EntryState::Normal, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 |
mode: 0o644, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 |
size: 0, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
383 |
mtime: 791231220, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
384 |
}, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
385 |
), |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
386 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
387 |
HgPathBuf::from_bytes(b"f2"), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
388 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
389 |
state: EntryState::Merged, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
390 |
mode: 0o777, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
391 |
size: 1000, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
392 |
mtime: 791231220, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
393 |
}, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
394 |
), |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
395 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
396 |
HgPathBuf::from_bytes(b"f3"), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
397 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
398 |
state: EntryState::Removed, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
399 |
mode: 0o644, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
400 |
size: 234553, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
401 |
mtime: 791231220, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
402 |
}, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
403 |
), |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
404 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
405 |
HgPathBuf::from_bytes(b"f4\xF6"), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
406 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
407 |
state: EntryState::Added, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
408 |
mode: 0o644, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 |
size: -1, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 |
mtime: -1, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 |
}, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
412 |
), |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
413 |
] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
414 |
.iter() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
415 |
.cloned() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
416 |
.collect(); |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
417 |
let mut copymap = FastHashMap::default(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
418 |
copymap.insert( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
419 |
HgPathBuf::from_bytes(b"f1"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
420 |
HgPathBuf::from_bytes(b"copyname"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
421 |
); |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
422 |
copymap.insert( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
423 |
HgPathBuf::from_bytes(b"f4\xF6"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
424 |
HgPathBuf::from_bytes(b"copyname2"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
425 |
); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
426 |
let parents = DirstateParents { |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
427 |
p1: *b"12345678910111213141", |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
428 |
p2: *b"00000000000000000000", |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
429 |
}; |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
430 |
let now = Duration::new(15000000, 0); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
431 |
let result = |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
432 |
pack_dirstate(&mut state_map, ©map, parents.clone(), now) |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
433 |
.unwrap(); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
434 |
|
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
435 |
let (new_parents, entries, copies) = |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
436 |
parse_dirstate(result.as_slice()).unwrap(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
437 |
let new_state_map: StateMap = entries |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
438 |
.into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
439 |
.map(|(path, entry)| (path.to_owned(), entry)) |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
440 |
.collect(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
441 |
let new_copy_map: CopyMap = copies |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
442 |
.into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
443 |
.map(|(path, copy)| (path.to_owned(), copy.to_owned())) |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
444 |
.collect(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
445 |
|
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
446 |
assert_eq!( |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
447 |
(parents, state_map, copymap), |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
448 |
(new_parents, new_state_map, new_copy_map) |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
449 |
) |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
450 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
451 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
452 |
#[test] |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
453 |
/// https://www.mercurial-scm.org/repo/hg/rev/af3f26b6bba4 |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
454 |
fn test_parse_pack_one_entry_with_copy_and_time_conflict() { |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
455 |
let mut state_map: StateMap = [( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
456 |
HgPathBuf::from_bytes(b"f1"), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
457 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
458 |
state: EntryState::Normal, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
459 |
mode: 0o644, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
460 |
size: 0, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
461 |
mtime: 15000000, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
462 |
}, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
463 |
)] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
464 |
.iter() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
465 |
.cloned() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
466 |
.collect(); |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
467 |
let mut copymap = FastHashMap::default(); |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
468 |
copymap.insert( |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
469 |
HgPathBuf::from_bytes(b"f1"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
470 |
HgPathBuf::from_bytes(b"copyname"), |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
471 |
); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
472 |
let parents = DirstateParents { |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
473 |
p1: *b"12345678910111213141", |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
474 |
p2: *b"00000000000000000000", |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
475 |
}; |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
476 |
let now = Duration::new(15000000, 0); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
477 |
let result = |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
478 |
pack_dirstate(&mut state_map, ©map, parents.clone(), now) |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
479 |
.unwrap(); |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
480 |
|
45357
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
481 |
let (new_parents, entries, copies) = |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
482 |
parse_dirstate(result.as_slice()).unwrap(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
483 |
let new_state_map: StateMap = entries |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
484 |
.into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
485 |
.map(|(path, entry)| (path.to_owned(), entry)) |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
486 |
.collect(); |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
487 |
let new_copy_map: CopyMap = copies |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
488 |
.into_iter() |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
489 |
.map(|(path, copy)| (path.to_owned(), copy.to_owned())) |
27424779c5b8
hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44973
diff
changeset
|
490 |
.collect(); |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
491 |
|
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
492 |
assert_eq!( |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
493 |
( |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
494 |
parents, |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
495 |
[( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42799
diff
changeset
|
496 |
HgPathBuf::from_bytes(b"f1"), |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
497 |
DirstateEntry { |
42749
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42748
diff
changeset
|
498 |
state: EntryState::Normal, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
499 |
mode: 0o644, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
500 |
size: 0, |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
501 |
mtime: -1 |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
502 |
} |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
503 |
)] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
504 |
.iter() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
505 |
.cloned() |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
506 |
.collect::<StateMap>(), |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
507 |
copymap, |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
508 |
), |
42748
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
509 |
(new_parents, new_state_map, new_copy_map) |
42302
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
510 |
) |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
511 |
} |
d1786c1d34fa
rust-dirstate: add rust implementation of `parse_dirstate` and `pack_dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
512 |
} |