diff -r 7cae6bc29ff9 -r 7ceded4419a3 rust/hg-core/src/dirstate.rs --- a/rust/hg-core/src/dirstate.rs Tue Jul 09 11:49:49 2019 +0200 +++ b/rust/hg-core/src/dirstate.rs Tue Jul 09 12:15:09 2019 +0200 @@ -5,7 +5,9 @@ // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. +use crate::DirstateParseError; use std::collections::HashMap; +use std::convert::TryFrom; pub mod dirs_multiset; pub mod parsers; @@ -21,7 +23,7 @@ /// comes first. #[derive(Debug, PartialEq, Copy, Clone)] pub struct DirstateEntry { - pub state: i8, + pub state: EntryState, pub mode: i32, pub mtime: i32, pub size: i32, @@ -36,3 +38,42 @@ Dirstate(&'a HashMap, DirstateEntry>), Manifest(&'a Vec>), } + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum EntryState { + Normal, + Added, + Removed, + Merged, + Unknown, +} + +impl TryFrom for EntryState { + type Error = DirstateParseError; + + fn try_from(value: u8) -> Result { + match value { + b'n' => Ok(EntryState::Normal), + b'a' => Ok(EntryState::Added), + b'r' => Ok(EntryState::Removed), + b'm' => Ok(EntryState::Merged), + b'?' => Ok(EntryState::Unknown), + _ => Err(DirstateParseError::CorruptedEntry(format!( + "Incorrect entry state {}", + value + ))), + } + } +} + +impl Into for EntryState { + fn into(self) -> u8 { + match self { + EntryState::Normal => b'n', + EntryState::Added => b'a', + EntryState::Removed => b'r', + EntryState::Merged => b'm', + EntryState::Unknown => b'?', + } + } +}