author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Sat, 10 Jul 2021 14:06:46 +0200 | |
changeset 47630 | 8e5192e41e0b |
parent 47521 | abed645b8e96 |
child 47683 | 284a20269a97 |
permissions | -rw-r--r-- |
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 |
|
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
8 |
use crate::dirstate_tree::on_disk::DirstateV2ParseError; |
46508
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
45613
diff
changeset
|
9 |
use crate::errors::HgError; |
47380
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
10 |
use crate::revlog::node::NULL_NODE; |
46634
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46633
diff
changeset
|
11 |
use crate::revlog::Node; |
47138
cd8ca38fccff
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47127
diff
changeset
|
12 |
use crate::utils::hg_path::{HgPath, HgPathBuf}; |
cd8ca38fccff
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs
Simon Sapin <simon.sapin@octobus.net>
parents:
47127
diff
changeset
|
13 |
use crate::FastHashMap; |
46633
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
14 |
use bytes_cast::{unaligned, BytesCast}; |
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
15 |
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
|
16 |
|
42543
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
42440
diff
changeset
|
17 |
pub mod dirs_multiset; |
42769
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
42765
diff
changeset
|
18 |
pub mod dirstate_map; |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
19 |
pub mod parsers; |
43271
99394e6c5d12
rust-dirstate-status: add first Rust implementation of `dirstate.status`
Raphaël Gomès <rgomes@octobus.net>
parents:
42960
diff
changeset
|
20 |
pub mod status; |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
|
46633
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
22 |
#[derive(Debug, PartialEq, Clone, BytesCast)] |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
23 |
#[repr(C)] |
42764
7cae6bc29ff9
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop
Raphaël Gomès <rgomes@octobus.net>
parents:
42609
diff
changeset
|
24 |
pub struct DirstateParents { |
46634
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46633
diff
changeset
|
25 |
pub p1: Node, |
98a455a62699
rust: Make `DirstateParents`’s fields typed `Node`s
Simon Sapin <simon.sapin@octobus.net>
parents:
46633
diff
changeset
|
26 |
pub p2: Node, |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
27 |
} |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
|
47380
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
29 |
impl DirstateParents { |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
30 |
pub const NULL: Self = Self { |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
31 |
p1: NULL_NODE, |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
32 |
p2: NULL_NODE, |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
33 |
}; |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
34 |
} |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47343
diff
changeset
|
35 |
|
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
/// 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
|
37 |
/// 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
|
38 |
/// 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
|
39 |
#[derive(Debug, PartialEq, Copy, Clone)] |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
pub struct DirstateEntry { |
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
41 |
pub state: EntryState, |
42440
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
42 |
pub mode: i32, |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
43 |
pub mtime: i32, |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
44 |
pub size: i32, |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 |
} |
d3b5cbe311d9
rust-dirstate: create dirstate submodule
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
|
47122
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
47 |
impl DirstateEntry { |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
48 |
pub fn is_non_normal(&self) -> bool { |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
49 |
self.state != EntryState::Normal || self.mtime == MTIME_UNSET |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
50 |
} |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
51 |
|
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
52 |
pub fn is_from_other_parent(&self) -> bool { |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
53 |
self.state == EntryState::Normal && self.size == SIZE_FROM_OTHER_PARENT |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
54 |
} |
47127
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
55 |
|
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
56 |
// TODO: other platforms |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
57 |
#[cfg(unix)] |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
58 |
pub fn mode_changed( |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
59 |
&self, |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
60 |
filesystem_metadata: &std::fs::Metadata, |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
61 |
) -> bool { |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
62 |
use std::os::unix::fs::MetadataExt; |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
63 |
const EXEC_BIT_MASK: u32 = 0o100; |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
64 |
let dirstate_exec_bit = (self.mode as u32) & EXEC_BIT_MASK; |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
65 |
let fs_exec_bit = filesystem_metadata.mode() & EXEC_BIT_MASK; |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
66 |
dirstate_exec_bit != fs_exec_bit |
be579775c2d9
dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents:
47122
diff
changeset
|
67 |
} |
47122
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
68 |
} |
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
69 |
|
46633
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
70 |
#[derive(BytesCast)] |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
71 |
#[repr(C)] |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
72 |
struct RawEntry { |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
73 |
state: u8, |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
74 |
mode: unaligned::I32Be, |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
75 |
size: unaligned::I32Be, |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
76 |
mtime: unaligned::I32Be, |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
77 |
length: unaligned::I32Be, |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
78 |
} |
f88e8ae0aa8f
rust: Rewrite dirstate parsing usin the `bytes-cast` crate
Simon Sapin <simon.sapin@octobus.net>
parents:
46508
diff
changeset
|
79 |
|
47521
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47519
diff
changeset
|
80 |
pub const V1_RANGEMASK: i32 = 0x7FFFFFFF; |
abed645b8e96
dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47519
diff
changeset
|
81 |
|
47519
b68d61af85a9
rust-dirstate: make the MTIME_UNSET public
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47511
diff
changeset
|
82 |
pub const MTIME_UNSET: i32 = -1; |
47122
e3cebe96c0fc
dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents:
47120
diff
changeset
|
83 |
|
43649
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43271
diff
changeset
|
84 |
/// A `DirstateEntry` with a size of `-2` means that it was merged from the |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43271
diff
changeset
|
85 |
/// other parent. This allows revert to pick the right status back during a |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43271
diff
changeset
|
86 |
/// merge. |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43271
diff
changeset
|
87 |
pub const SIZE_FROM_OTHER_PARENT: i32 = -2; |
47511
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47380
diff
changeset
|
88 |
/// A special value used for internal representation of special case in |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47380
diff
changeset
|
89 |
/// dirstate v1 format. |
eaae39894312
dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47380
diff
changeset
|
90 |
pub const SIZE_NON_NORMAL: i32 = -1; |
43649
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
43271
diff
changeset
|
91 |
|
43844
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43649
diff
changeset
|
92 |
pub type StateMap = FastHashMap<HgPathBuf, DirstateEntry>; |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
93 |
pub type StateMapIter<'a> = Box< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
94 |
dyn Iterator< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
95 |
Item = Result<(&'a HgPath, DirstateEntry), DirstateV2ParseError>, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
96 |
> + Send |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
97 |
+ 'a, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
98 |
>; |
45613
496537c9c1b4
rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents:
45612
diff
changeset
|
99 |
|
43844
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43649
diff
changeset
|
100 |
pub type CopyMap = FastHashMap<HgPathBuf, HgPathBuf>; |
47343
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
101 |
pub type CopyMapIter<'a> = Box< |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
102 |
dyn Iterator<Item = Result<(&'a HgPath, &'a HgPath), DirstateV2ParseError>> |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
103 |
+ Send |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
104 |
+ 'a, |
ed1583a845d2
dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents:
47340
diff
changeset
|
105 |
>; |
42543
2dcee6497b0b
rust-dirstate: add "dirs" Rust implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
42440
diff
changeset
|
106 |
|
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
107 |
#[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
|
108 |
pub enum EntryState { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
109 |
Normal, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
110 |
Added, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
111 |
Removed, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
112 |
Merged, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
113 |
Unknown, |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
114 |
} |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
115 |
|
47120
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
116 |
impl EntryState { |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
117 |
pub fn is_tracked(self) -> bool { |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
118 |
use EntryState::*; |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
119 |
match self { |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
120 |
Normal | Added | Merged => true, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
121 |
Removed | Unknown => false, |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
122 |
} |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
123 |
} |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
124 |
} |
52906934b775
dirstate-tree: Add has_dir and has_tracked_dir
Simon Sapin <simon.sapin@octobus.net>
parents:
47107
diff
changeset
|
125 |
|
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
126 |
impl TryFrom<u8> for EntryState { |
46508
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
45613
diff
changeset
|
127 |
type Error = HgError; |
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
128 |
|
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
129 |
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
|
130 |
match value { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
b'?' => Ok(EntryState::Unknown), |
46508
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
45613
diff
changeset
|
136 |
_ => Err(HgError::CorruptedRepository(format!( |
776b97179c06
rust: Remove DirstateParseError and ListDirstateTrackedFilesError
Simon Sapin <simon.sapin@octobus.net>
parents:
45613
diff
changeset
|
137 |
"Incorrect dirstate entry state {}", |
42765
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
138 |
value |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
139 |
))), |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
140 |
} |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
141 |
} |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
142 |
} |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
143 |
|
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
144 |
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
|
145 |
fn into(self) -> u8 { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
146 |
match self { |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
147 |
EntryState::Normal => b'n', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
148 |
EntryState::Added => b'a', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
149 |
EntryState::Removed => b'r', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
150 |
EntryState::Merged => b'm', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
151 |
EntryState::Unknown => b'?', |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
152 |
} |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
153 |
} |
7ceded4419a3
rust-dirstate: use EntryState enum instead of literals
Raphaël Gomès <rgomes@octobus.net>
parents:
42764
diff
changeset
|
154 |
} |