Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/dirstate.rs @ 46594:f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Differential Revision: https://phab.mercurial-scm.org/D10005
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 17 Feb 2021 12:06:56 +0100 |
parents | 776b97179c06 |
children | 98a455a62699 |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate.rs Mon Feb 15 20:13:09 2021 +0100 +++ b/rust/hg-core/src/dirstate.rs Wed Feb 17 12:06:56 2021 +0100 @@ -7,6 +7,7 @@ use crate::errors::HgError; use crate::{utils::hg_path::HgPathBuf, FastHashMap}; +use bytes_cast::{unaligned, BytesCast}; use std::collections::hash_map; use std::convert::TryFrom; @@ -17,7 +18,8 @@ pub mod parsers; pub mod status; -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, BytesCast)] +#[repr(C)] pub struct DirstateParents { pub p1: [u8; 20], pub p2: [u8; 20], @@ -34,6 +36,16 @@ pub size: i32, } +#[derive(BytesCast)] +#[repr(C)] +struct RawEntry { + state: u8, + mode: unaligned::I32Be, + size: unaligned::I32Be, + mtime: unaligned::I32Be, + length: unaligned::I32Be, +} + /// A `DirstateEntry` with a size of `-2` means that it was merged from the /// other parent. This allows revert to pick the right status back during a /// merge.