3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
4 // |
4 // |
5 // This software may be used and distributed according to the terms of the |
5 // This software may be used and distributed according to the terms of the |
6 // GNU General Public License version 2 or any later version. |
6 // GNU General Public License version 2 or any later version. |
7 |
7 |
|
8 use crate::DirstateParseError; |
8 use std::collections::HashMap; |
9 use std::collections::HashMap; |
|
10 use std::convert::TryFrom; |
9 |
11 |
10 pub mod dirs_multiset; |
12 pub mod dirs_multiset; |
11 pub mod parsers; |
13 pub mod parsers; |
12 |
14 |
13 #[derive(Debug, PartialEq, Clone)] |
15 #[derive(Debug, PartialEq, Clone)] |
19 /// The C implementation uses all signed types. This will be an issue |
21 /// The C implementation uses all signed types. This will be an issue |
20 /// either when 4GB+ source files are commonplace or in 2038, whichever |
22 /// either when 4GB+ source files are commonplace or in 2038, whichever |
21 /// comes first. |
23 /// comes first. |
22 #[derive(Debug, PartialEq, Copy, Clone)] |
24 #[derive(Debug, PartialEq, Copy, Clone)] |
23 pub struct DirstateEntry { |
25 pub struct DirstateEntry { |
24 pub state: i8, |
26 pub state: EntryState, |
25 pub mode: i32, |
27 pub mode: i32, |
26 pub mtime: i32, |
28 pub mtime: i32, |
27 pub size: i32, |
29 pub size: i32, |
28 } |
30 } |
29 |
31 |
34 /// iterable (manifest) |
36 /// iterable (manifest) |
35 pub enum DirsIterable<'a> { |
37 pub enum DirsIterable<'a> { |
36 Dirstate(&'a HashMap<Vec<u8>, DirstateEntry>), |
38 Dirstate(&'a HashMap<Vec<u8>, DirstateEntry>), |
37 Manifest(&'a Vec<Vec<u8>>), |
39 Manifest(&'a Vec<Vec<u8>>), |
38 } |
40 } |
|
41 |
|
42 #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
|
43 pub enum EntryState { |
|
44 Normal, |
|
45 Added, |
|
46 Removed, |
|
47 Merged, |
|
48 Unknown, |
|
49 } |
|
50 |
|
51 impl TryFrom<u8> for EntryState { |
|
52 type Error = DirstateParseError; |
|
53 |
|
54 fn try_from(value: u8) -> Result<Self, Self::Error> { |
|
55 match value { |
|
56 b'n' => Ok(EntryState::Normal), |
|
57 b'a' => Ok(EntryState::Added), |
|
58 b'r' => Ok(EntryState::Removed), |
|
59 b'm' => Ok(EntryState::Merged), |
|
60 b'?' => Ok(EntryState::Unknown), |
|
61 _ => Err(DirstateParseError::CorruptedEntry(format!( |
|
62 "Incorrect entry state {}", |
|
63 value |
|
64 ))), |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 impl Into<u8> for EntryState { |
|
70 fn into(self) -> u8 { |
|
71 match self { |
|
72 EntryState::Normal => b'n', |
|
73 EntryState::Added => b'a', |
|
74 EntryState::Removed => b'r', |
|
75 EntryState::Merged => b'm', |
|
76 EntryState::Unknown => b'?', |
|
77 } |
|
78 } |
|
79 } |