Mercurial > hg-stable
diff rust/hg-core/src/dirstate.rs @ 42764:7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Both `parse_dirstate` and `pack_dirstate` can operate directly on the data
they're passed, which prevents the creation of intermediate data structures,
simplifies the function signatures and reduces boilerplate. They are exposed
directly to the Python for now, but a later patch will make use of them inside
`hg-core`.
Differential Revision: https://phab.mercurial-scm.org/D6628
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Tue, 09 Jul 2019 11:49:49 +0200 |
parents | 326fdce22fb2 |
children | 7ceded4419a3 |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate.rs Wed Jul 10 10:16:28 2019 +0200 +++ b/rust/hg-core/src/dirstate.rs Tue Jul 09 11:49:49 2019 +0200 @@ -1,16 +1,25 @@ +// dirstate module +// +// 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. + +use std::collections::HashMap; + pub mod dirs_multiset; pub mod parsers; -#[derive(Debug, PartialEq, Copy, Clone)] -pub struct DirstateParents<'a> { - pub p1: &'a [u8], - pub p2: &'a [u8], +#[derive(Debug, PartialEq, Clone)] +pub struct DirstateParents { + pub p1: [u8; 20], + pub p2: [u8; 20], } /// The C implementation uses all signed types. This will be an issue /// either when 4GB+ source files are commonplace or in 2038, whichever /// comes first. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Copy, Clone)] pub struct DirstateEntry { pub state: i8, pub mode: i32, @@ -18,19 +27,12 @@ pub size: i32, } -pub type DirstateVec = Vec<(Vec<u8>, DirstateEntry)>; - -#[derive(Debug, PartialEq)] -pub struct CopyVecEntry<'a> { - pub path: &'a [u8], - pub copy_path: &'a [u8], -} - -pub type CopyVec<'a> = Vec<CopyVecEntry<'a>>; +pub type StateMap = HashMap<Vec<u8>, DirstateEntry>; +pub type CopyMap = HashMap<Vec<u8>, Vec<u8>>; /// The Python implementation passes either a mapping (dirstate) or a flat /// iterable (manifest) -pub enum DirsIterable { - Dirstate(DirstateVec), - Manifest(Vec<Vec<u8>>), +pub enum DirsIterable<'a> { + Dirstate(&'a HashMap<Vec<u8>, DirstateEntry>), + Manifest(&'a Vec<Vec<u8>>), }