Mercurial > hg-stable
annotate rust/hg-core/src/dirstate.rs @ 42818:2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Since skip_state only applies to dirstate, it doesn't make sense to unify
these constructors and dispatch by enum.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 17 Aug 2019 18:25:29 +0900 |
parents | fce6dc93a510 |
children | 7083ac37314f |
rev | line source |
---|---|
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
1 // dirstate module |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
2 // |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
3 // Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
4 // |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
7 |
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
8 use crate::DirstateParseError; |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
9 use std::collections::HashMap; |
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
10 use std::convert::TryFrom; |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
11 |
42543
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
42440
diff
changeset
|
12 pub mod dirs_multiset; |
42769
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
42765
diff
changeset
|
13 pub mod dirstate_map; |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
14 pub mod parsers; |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
15 |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
16 #[derive(Debug, PartialEq, Clone)] |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
17 pub struct DirstateParents { |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
18 pub p1: [u8; 20], |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
19 pub p2: [u8; 20], |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
20 } |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 /// The C implementation uses all signed types. This will be an issue |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 /// either when 4GB+ source files are commonplace or in 2038, whichever |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 /// comes first. |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
25 #[derive(Debug, PartialEq, Copy, Clone)] |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 pub struct DirstateEntry { |
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
27 pub state: EntryState, |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 pub mode: i32, |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
29 pub mtime: i32, |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
30 pub size: i32, |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 } |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
33 pub type StateMap = HashMap<Vec<u8>, DirstateEntry>; |
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
34 pub type CopyMap = HashMap<Vec<u8>, Vec<u8>>; |
42543
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
42440
diff
changeset
|
35 |
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
36 #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
37 pub enum EntryState { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
38 Normal, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
39 Added, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
40 Removed, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
41 Merged, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
42 Unknown, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
43 } |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
44 |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
45 impl TryFrom<u8> for EntryState { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
46 type Error = DirstateParseError; |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
47 |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
48 fn try_from(value: u8) -> Result<Self, Self::Error> { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
49 match value { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
50 b'n' => Ok(EntryState::Normal), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
51 b'a' => Ok(EntryState::Added), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
52 b'r' => Ok(EntryState::Removed), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
53 b'm' => Ok(EntryState::Merged), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
54 b'?' => Ok(EntryState::Unknown), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
55 _ => Err(DirstateParseError::CorruptedEntry(format!( |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
56 "Incorrect entry state {}", |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
57 value |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
58 ))), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
59 } |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
60 } |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
61 } |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
62 |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
63 impl Into<u8> for EntryState { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
64 fn into(self) -> u8 { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
65 match self { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
66 EntryState::Normal => b'n', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
67 EntryState::Added => b'a', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
68 EntryState::Removed => b'r', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
69 EntryState::Merged => b'm', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
70 EntryState::Unknown => b'?', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
71 } |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
72 } |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
73 } |