##// END OF EJS Templates
dirstate: Replace dropfile with drop_item_and_copy_source...
dirstate: Replace dropfile with drop_item_and_copy_source Those removing a DirstateItem and a copy source are always done together Differential Revision: https://phab.mercurial-scm.org/D11493

File last commit:

r48834:f2a9db29 default
r48864:2ac0e6b2 default
Show More
parsers.rs
468 lines | 14.0 KiB | application/rls-services+xml | RustLexer
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
Simon Sapin
rust: Replace DirstatePackError with HgError...
r47168 use crate::errors::HgError;
Simon Sapin
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs...
r47894 use crate::utils::hg_path::HgPath;
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 use crate::{
Simon Sapin
rust: Move DirstateEntry to its own module...
r48830 dirstate::{CopyMap, EntryState, StateMap},
Simon Sapin
rust: Remove DirstateParseError and ListDirstateTrackedFilesError...
r47169 DirstateEntry, DirstateParents,
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 };
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 use byteorder::{BigEndian, WriteBytesExt};
Simon Sapin
rust: Move DirstateEntry to its own module...
r48830 use bytes_cast::{unaligned, BytesCast};
Raphaël Gomès
hg-core: add function timing information...
r45028 use micro_timer::timed;
Raphaël Gomès
rust-dirstate: use EntryState enum instead of literals...
r42994 use std::convert::{TryFrom, TryInto};
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
/// Parents are stored in the dirstate as byte hashes.
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 pub const PARENT_SIZE: usize = 20;
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 /// Dirstate entries have a static part of 8 + 32 + 32 + 32 + 32 bits.
const MIN_ENTRY_SIZE: usize = 17;
Antoine Cezar
hg-core: make parse_dirstate return references rather than update hashmaps...
r45916 type ParseResult<'a> = (
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 &'a DirstateParents,
Antoine Cezar
hg-core: make parse_dirstate return references rather than update hashmaps...
r45916 Vec<(&'a HgPath, DirstateEntry)>,
Vec<(&'a HgPath, &'a HgPath)>,
);
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993
Simon Sapin
rhg: Add support for the blackbox extension...
r47343 pub fn parse_dirstate_parents(
contents: &[u8],
) -> Result<&DirstateParents, HgError> {
let (parents, _rest) = DirstateParents::from_bytes(contents)
.map_err(|_| HgError::corrupted("Too little data for dirstate."))?;
Ok(parents)
}
Raphaël Gomès
hg-core: add function timing information...
r45028 #[timed]
Simon Sapin
dirstate-tree: Implement DirstateMap::read...
r47867 pub fn parse_dirstate(contents: &[u8]) -> Result<ParseResult, HgError> {
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 let mut copies = Vec::new();
let mut entries = Vec::new();
Simon Sapin
dirstate-tree: Implement DirstateMap::read...
r47867 let parents =
parse_dirstate_entries(contents, |path, entry, copy_source| {
if let Some(source) = copy_source {
copies.push((path, source));
}
entries.push((path, *entry));
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 Ok(())
Simon Sapin
dirstate-tree: Implement DirstateMap::read...
r47867 })?;
Ok((parents, entries, copies))
}
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
Simon Sapin
rust: Move DirstateEntry to its own module...
r48830 #[derive(BytesCast)]
#[repr(C)]
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 struct RawEntry {
Simon Sapin
rust: Move DirstateEntry to its own module...
r48830 state: u8,
mode: unaligned::I32Be,
size: unaligned::I32Be,
mtime: unaligned::I32Be,
length: unaligned::I32Be,
}
Simon Sapin
dirstate-tree: Implement DirstateMap::read...
r47867 pub fn parse_dirstate_entries<'a>(
mut contents: &'a [u8],
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 mut each_entry: impl FnMut(
&'a HgPath,
&DirstateEntry,
Option<&'a HgPath>,
) -> Result<(), HgError>,
Simon Sapin
dirstate-tree: Implement DirstateMap::read...
r47867 ) -> Result<&'a DirstateParents, HgError> {
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 let (parents, rest) = DirstateParents::from_bytes(contents)
.map_err(|_| HgError::corrupted("Too little data for dirstate."))?;
contents = rest;
while !contents.is_empty() {
let (raw_entry, rest) = RawEntry::from_bytes(contents)
.map_err(|_| HgError::corrupted("Overflow in dirstate."))?;
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 let entry = DirstateEntry::from_v1_data(
EntryState::try_from(raw_entry.state)?,
raw_entry.mode.get(),
raw_entry.size.get(),
raw_entry.mtime.get(),
);
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 let (paths, rest) =
u8::slice_from_bytes(rest, raw_entry.length.get() as usize)
.map_err(|_| HgError::corrupted("Overflow in dirstate."))?;
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 // `paths` is either a single path, or two paths separated by a NULL
// byte
let mut iter = paths.splitn(2, |&byte| byte == b'\0');
let path = HgPath::new(
iter.next().expect("splitn always yields at least one item"),
);
Simon Sapin
dirstate-tree: Implement DirstateMap::read...
r47867 let copy_source = iter.next().map(HgPath::new);
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 each_entry(path, &entry, copy_source)?;
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 contents = rest;
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 }
Simon Sapin
dirstate-tree: Implement DirstateMap::read...
r47867 Ok(parents)
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 }
Simon Sapin
dirstate-tree: Serialize to disk...
r47872 fn packed_filename_and_copy_source_size(
Simon Sapin
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs...
r47894 filename: &HgPath,
copy_source: Option<&HgPath>,
Simon Sapin
dirstate-tree: Serialize to disk...
r47872 ) -> usize {
filename.len()
+ if let Some(source) = copy_source {
b"\0".len() + source.len()
} else {
0
}
}
pub fn packed_entry_size(
Simon Sapin
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs...
r47894 filename: &HgPath,
copy_source: Option<&HgPath>,
Simon Sapin
dirstate-tree: Serialize to disk...
r47872 ) -> usize {
MIN_ENTRY_SIZE
+ packed_filename_and_copy_source_size(filename, copy_source)
}
pub fn pack_entry(
Simon Sapin
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs...
r47894 filename: &HgPath,
Simon Sapin
dirstate-tree: Serialize to disk...
r47872 entry: &DirstateEntry,
Simon Sapin
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs...
r47894 copy_source: Option<&HgPath>,
Simon Sapin
dirstate-tree: Serialize to disk...
r47872 packed: &mut Vec<u8>,
) {
let length = packed_filename_and_copy_source_size(filename, copy_source);
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 let (state, mode, size, mtime) = entry.v1_data();
Simon Sapin
dirstate-tree: Serialize to disk...
r47872
// Unwrapping because `impl std::io::Write for Vec<u8>` never errors
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 packed.write_u8(state).unwrap();
packed.write_i32::<BigEndian>(mode).unwrap();
packed.write_i32::<BigEndian>(size).unwrap();
packed.write_i32::<BigEndian>(mtime).unwrap();
Simon Sapin
dirstate-tree: Serialize to disk...
r47872 packed.write_i32::<BigEndian>(length as i32).unwrap();
packed.extend(filename.as_bytes());
if let Some(source) = copy_source {
packed.push(b'\0');
packed.extend(source.as_bytes());
}
}
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 /// Seconds since the Unix epoch
Simon Sapin
dirstate-v2: Add --dirs to debugdirstate command...
r48140 pub struct Timestamp(pub i64);
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 pub fn pack_dirstate(
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 state_map: &mut StateMap,
copy_map: &CopyMap,
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 parents: DirstateParents,
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 now: Timestamp,
Simon Sapin
rust: Replace DirstatePackError with HgError...
r47168 ) -> Result<Vec<u8>, HgError> {
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 // TODO move away from i32 before 2038.
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 let now: i32 = now.0.try_into().expect("time overflow");
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let expected_size: usize = state_map
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 .iter()
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 .map(|(filename, _)| {
Simon Sapin
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs...
r47894 packed_entry_size(filename, copy_map.get(filename).map(|p| &**p))
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 })
.sum();
let expected_size = expected_size + PARENT_SIZE * 2;
let mut packed = Vec::with_capacity(expected_size);
Simon Sapin
rust: Make `DirstateParents`’s fields typed `Node`s...
r47337 packed.extend(parents.p1.as_bytes());
packed.extend(parents.p2.as_bytes());
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
Raphaël Gomès
rust-parsers: use in-place mutation instead of allocating a new `Vec`...
r46223 for (filename, entry) in state_map.iter_mut() {
Simon Sapin
dirstate-tree: Remove DirstateMap::iter_node_data_mut...
r48121 entry.clear_ambiguous_mtime(now);
Simon Sapin
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs...
r47894 pack_entry(
filename,
entry,
copy_map.get(filename).map(|p| &**p),
&mut packed,
)
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 }
if packed.len() != expected_size {
Simon Sapin
rust: Replace DirstatePackError with HgError...
r47168 return Err(HgError::CorruptedRepository(format!(
"bad dirstate size: {} != {}",
expected_size,
packed.len()
)));
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 }
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 Ok(packed)
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 }
#[cfg(test)]
mod tests {
use super::*;
Raphaël Gomès
rust-performance: introduce FastHashMap type alias for HashMap...
r44278 use crate::{utils::hg_path::HgPathBuf, FastHashMap};
Raphaël Gomès
rust: start plugging the dirstate tree behind a feature gate...
r46185 use pretty_assertions::assert_eq;
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
#[test]
fn test_pack_dirstate_empty() {
Raphaël Gomès
rust: start plugging the dirstate tree behind a feature gate...
r46185 let mut state_map = StateMap::default();
Raphaël Gomès
rust-performance: introduce FastHashMap type alias for HashMap...
r44278 let copymap = FastHashMap::default();
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 let parents = DirstateParents {
Simon Sapin
rust: Make `DirstateParents`’s fields typed `Node`s...
r47337 p1: b"12345678910111213141".into(),
p2: b"00000000000000000000".into(),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 };
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 let now = Timestamp(15000000);
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let expected = b"1234567891011121314100000000000000000000".to_vec();
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
assert_eq!(
expected,
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 );
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993
assert!(state_map.is_empty())
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 }
#[test]
fn test_pack_dirstate_one_entry() {
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let expected_state_map: StateMap = [(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f1"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(
EntryState::Normal,
0o644,
0,
791231220,
),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 )]
.iter()
.cloned()
.collect();
let mut state_map = expected_state_map.clone();
Raphaël Gomès
rust-performance: introduce FastHashMap type alias for HashMap...
r44278 let copymap = FastHashMap::default();
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 let parents = DirstateParents {
Simon Sapin
rust: Make `DirstateParents`’s fields typed `Node`s...
r47337 p1: b"12345678910111213141".into(),
p2: b"00000000000000000000".into(),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 };
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 let now = Timestamp(15000000);
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let expected = [
49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49,
51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 110, 0, 0, 1, 164, 0, 0, 0, 0, 47,
41, 58, 244, 0, 0, 0, 2, 102, 49,
]
.to_vec();
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
assert_eq!(
expected,
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 );
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 assert_eq!(expected_state_map, state_map);
}
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 #[test]
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 fn test_pack_dirstate_one_entry_with_copy() {
let expected_state_map: StateMap = [(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f1"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(
EntryState::Normal,
0o644,
0,
791231220,
),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 )]
.iter()
.cloned()
.collect();
let mut state_map = expected_state_map.clone();
Raphaël Gomès
rust-performance: introduce FastHashMap type alias for HashMap...
r44278 let mut copymap = FastHashMap::default();
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 copymap.insert(
HgPathBuf::from_bytes(b"f1"),
HgPathBuf::from_bytes(b"copyname"),
);
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 let parents = DirstateParents {
Simon Sapin
rust: Make `DirstateParents`’s fields typed `Node`s...
r47337 p1: b"12345678910111213141".into(),
p2: b"00000000000000000000".into(),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 };
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 let now = Timestamp(15000000);
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let expected = [
49, 50, 51, 52, 53, 54, 55, 56, 57, 49, 48, 49, 49, 49, 50, 49,
51, 49, 52, 49, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 110, 0, 0, 1, 164, 0, 0, 0, 0, 47,
41, 58, 244, 0, 0, 0, 11, 102, 49, 0, 99, 111, 112, 121, 110, 97,
109, 101,
]
.to_vec();
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
assert_eq!(
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 expected,
pack_dirstate(&mut state_map, &copymap, parents, now).unwrap()
);
assert_eq!(expected_state_map, state_map);
}
#[test]
fn test_parse_pack_one_entry_with_copy() {
let mut state_map: StateMap = [(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f1"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(
EntryState::Normal,
0o644,
0,
791231220,
),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 )]
.iter()
.cloned()
.collect();
Raphaël Gomès
rust-performance: introduce FastHashMap type alias for HashMap...
r44278 let mut copymap = FastHashMap::default();
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 copymap.insert(
HgPathBuf::from_bytes(b"f1"),
HgPathBuf::from_bytes(b"copyname"),
);
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let parents = DirstateParents {
Simon Sapin
rust: Make `DirstateParents`’s fields typed `Node`s...
r47337 p1: b"12345678910111213141".into(),
p2: b"00000000000000000000".into(),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 };
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 let now = Timestamp(15000000);
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let result =
pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
.unwrap();
Antoine Cezar
hg-core: make parse_dirstate return references rather than update hashmaps...
r45916 let (new_parents, entries, copies) =
parse_dirstate(result.as_slice()).unwrap();
let new_state_map: StateMap = entries
.into_iter()
.map(|(path, entry)| (path.to_owned(), entry))
.collect();
let new_copy_map: CopyMap = copies
.into_iter()
.map(|(path, copy)| (path.to_owned(), copy.to_owned()))
.collect();
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 assert_eq!(
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 (&parents, state_map, copymap),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 (new_parents, new_state_map, new_copy_map)
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 )
}
#[test]
fn test_parse_pack_multiple_entries_with_copy() {
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let mut state_map: StateMap = [
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 (
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f1"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(
EntryState::Normal,
0o644,
0,
791231220,
),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 ),
(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f2"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(
EntryState::Merged,
0o777,
1000,
791231220,
),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 ),
(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f3"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(
EntryState::Removed,
0o644,
234553,
791231220,
),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 ),
(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f4\xF6"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(EntryState::Added, 0o644, -1, -1),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 ),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 ]
.iter()
.cloned()
.collect();
Raphaël Gomès
rust-performance: introduce FastHashMap type alias for HashMap...
r44278 let mut copymap = FastHashMap::default();
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 copymap.insert(
HgPathBuf::from_bytes(b"f1"),
HgPathBuf::from_bytes(b"copyname"),
);
copymap.insert(
HgPathBuf::from_bytes(b"f4\xF6"),
HgPathBuf::from_bytes(b"copyname2"),
);
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 let parents = DirstateParents {
Simon Sapin
rust: Make `DirstateParents`’s fields typed `Node`s...
r47337 p1: b"12345678910111213141".into(),
p2: b"00000000000000000000".into(),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 };
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 let now = Timestamp(15000000);
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 let result =
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
.unwrap();
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
Antoine Cezar
hg-core: make parse_dirstate return references rather than update hashmaps...
r45916 let (new_parents, entries, copies) =
parse_dirstate(result.as_slice()).unwrap();
let new_state_map: StateMap = entries
.into_iter()
.map(|(path, entry)| (path.to_owned(), entry))
.collect();
let new_copy_map: CopyMap = copies
.into_iter()
.map(|(path, copy)| (path.to_owned(), copy.to_owned()))
.collect();
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 assert_eq!(
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 (&parents, state_map, copymap),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 (new_parents, new_state_map, new_copy_map)
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 )
}
#[test]
/// https://www.mercurial-scm.org/repo/hg/rev/af3f26b6bba4
fn test_parse_pack_one_entry_with_copy_and_time_conflict() {
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 let mut state_map: StateMap = [(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f1"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(
EntryState::Normal,
0o644,
0,
15000000,
),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 )]
.iter()
.cloned()
.collect();
Raphaël Gomès
rust-performance: introduce FastHashMap type alias for HashMap...
r44278 let mut copymap = FastHashMap::default();
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 copymap.insert(
HgPathBuf::from_bytes(b"f1"),
HgPathBuf::from_bytes(b"copyname"),
);
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 let parents = DirstateParents {
Simon Sapin
rust: Make `DirstateParents`’s fields typed `Node`s...
r47337 p1: b"12345678910111213141".into(),
p2: b"00000000000000000000".into(),
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 };
Simon Sapin
rust: Add a Timestamp struct instead of abusing Duration...
r47871 let now = Timestamp(15000000);
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 let result =
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 pack_dirstate(&mut state_map, &copymap, parents.clone(), now)
.unwrap();
Antoine Cezar
hg-core: make parse_dirstate return references rather than update hashmaps...
r45916 let (new_parents, entries, copies) =
parse_dirstate(result.as_slice()).unwrap();
let new_state_map: StateMap = entries
.into_iter()
.map(|(path, entry)| (path.to_owned(), entry))
.collect();
let new_copy_map: CopyMap = copies
.into_iter()
.map(|(path, copy)| (path.to_owned(), copy.to_owned()))
.collect();
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617
assert_eq!(
(
Simon Sapin
rust: Rewrite dirstate parsing usin the `bytes-cast` crate...
r47336 &parents,
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 [(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPathBuf::from_bytes(b"f1"),
Simon Sapin
rust: Make the fields of DirstateEntry private...
r48834 DirstateEntry::from_v1_data(
EntryState::Normal,
0o644,
0,
-1
)
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 )]
.iter()
.cloned()
.collect::<StateMap>(),
copymap,
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 ),
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 (new_parents, new_state_map, new_copy_map)
Raphaël Gomès
rust-dirstate: create dirstate submodule...
r42617 )
}
}