Show More
@@ -1,152 +1,152 b'' | |||
|
1 | 1 | // dirstate module |
|
2 | 2 | // |
|
3 | 3 | // Copyright 2019 Raphaël Gomès <rgomes@octobus.net> |
|
4 | 4 | // |
|
5 | 5 | // This software may be used and distributed according to the terms of the |
|
6 | 6 | // GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | use crate::dirstate_tree::on_disk::DirstateV2ParseError; |
|
9 | 9 | use crate::errors::HgError; |
|
10 | 10 | use crate::revlog::node::NULL_NODE; |
|
11 | 11 | use crate::revlog::Node; |
|
12 | 12 | use crate::utils::hg_path::{HgPath, HgPathBuf}; |
|
13 | 13 | use crate::FastHashMap; |
|
14 | 14 | use bytes_cast::{unaligned, BytesCast}; |
|
15 | 15 | use std::convert::TryFrom; |
|
16 | 16 | |
|
17 | 17 | pub mod dirs_multiset; |
|
18 | 18 | pub mod dirstate_map; |
|
19 | 19 | pub mod parsers; |
|
20 | 20 | pub mod status; |
|
21 | 21 | |
|
22 | 22 | #[derive(Debug, PartialEq, Clone, BytesCast)] |
|
23 | 23 | #[repr(C)] |
|
24 | 24 | pub struct DirstateParents { |
|
25 | 25 | pub p1: Node, |
|
26 | 26 | pub p2: Node, |
|
27 | 27 | } |
|
28 | 28 | |
|
29 | 29 | impl DirstateParents { |
|
30 | 30 | pub const NULL: Self = Self { |
|
31 | 31 | p1: NULL_NODE, |
|
32 | 32 | p2: NULL_NODE, |
|
33 | 33 | }; |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | /// The C implementation uses all signed types. This will be an issue |
|
37 | 37 | /// either when 4GB+ source files are commonplace or in 2038, whichever |
|
38 | 38 | /// comes first. |
|
39 | 39 | #[derive(Debug, PartialEq, Copy, Clone)] |
|
40 | 40 | pub struct DirstateEntry { |
|
41 | 41 | pub state: EntryState, |
|
42 | 42 | pub mode: i32, |
|
43 | 43 | pub mtime: i32, |
|
44 | 44 | pub size: i32, |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | impl DirstateEntry { |
|
48 | 48 | pub fn is_non_normal(&self) -> bool { |
|
49 | 49 | self.state != EntryState::Normal || self.mtime == MTIME_UNSET |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | pub fn is_from_other_parent(&self) -> bool { |
|
53 | 53 | self.state == EntryState::Normal && self.size == SIZE_FROM_OTHER_PARENT |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | // TODO: other platforms |
|
57 | 57 | #[cfg(unix)] |
|
58 | 58 | pub fn mode_changed( |
|
59 | 59 | &self, |
|
60 | 60 | filesystem_metadata: &std::fs::Metadata, |
|
61 | 61 | ) -> bool { |
|
62 | 62 | use std::os::unix::fs::MetadataExt; |
|
63 | 63 | const EXEC_BIT_MASK: u32 = 0o100; |
|
64 | 64 | let dirstate_exec_bit = (self.mode as u32) & EXEC_BIT_MASK; |
|
65 | 65 | let fs_exec_bit = filesystem_metadata.mode() & EXEC_BIT_MASK; |
|
66 | 66 | dirstate_exec_bit != fs_exec_bit |
|
67 | 67 | } |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | #[derive(BytesCast)] |
|
71 | 71 | #[repr(C)] |
|
72 | 72 | struct RawEntry { |
|
73 | 73 | state: u8, |
|
74 | 74 | mode: unaligned::I32Be, |
|
75 | 75 | size: unaligned::I32Be, |
|
76 | 76 | mtime: unaligned::I32Be, |
|
77 | 77 | length: unaligned::I32Be, |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | const MTIME_UNSET: i32 = -1; | |
|
80 | pub const MTIME_UNSET: i32 = -1; | |
|
81 | 81 | |
|
82 | 82 | /// A `DirstateEntry` with a size of `-2` means that it was merged from the |
|
83 | 83 | /// other parent. This allows revert to pick the right status back during a |
|
84 | 84 | /// merge. |
|
85 | 85 | pub const SIZE_FROM_OTHER_PARENT: i32 = -2; |
|
86 | 86 | /// A special value used for internal representation of special case in |
|
87 | 87 | /// dirstate v1 format. |
|
88 | 88 | pub const SIZE_NON_NORMAL: i32 = -1; |
|
89 | 89 | |
|
90 | 90 | pub type StateMap = FastHashMap<HgPathBuf, DirstateEntry>; |
|
91 | 91 | pub type StateMapIter<'a> = Box< |
|
92 | 92 | dyn Iterator< |
|
93 | 93 | Item = Result<(&'a HgPath, DirstateEntry), DirstateV2ParseError>, |
|
94 | 94 | > + Send |
|
95 | 95 | + 'a, |
|
96 | 96 | >; |
|
97 | 97 | |
|
98 | 98 | pub type CopyMap = FastHashMap<HgPathBuf, HgPathBuf>; |
|
99 | 99 | pub type CopyMapIter<'a> = Box< |
|
100 | 100 | dyn Iterator<Item = Result<(&'a HgPath, &'a HgPath), DirstateV2ParseError>> |
|
101 | 101 | + Send |
|
102 | 102 | + 'a, |
|
103 | 103 | >; |
|
104 | 104 | |
|
105 | 105 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
|
106 | 106 | pub enum EntryState { |
|
107 | 107 | Normal, |
|
108 | 108 | Added, |
|
109 | 109 | Removed, |
|
110 | 110 | Merged, |
|
111 | 111 | Unknown, |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | 114 | impl EntryState { |
|
115 | 115 | pub fn is_tracked(self) -> bool { |
|
116 | 116 | use EntryState::*; |
|
117 | 117 | match self { |
|
118 | 118 | Normal | Added | Merged => true, |
|
119 | 119 | Removed | Unknown => false, |
|
120 | 120 | } |
|
121 | 121 | } |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | impl TryFrom<u8> for EntryState { |
|
125 | 125 | type Error = HgError; |
|
126 | 126 | |
|
127 | 127 | fn try_from(value: u8) -> Result<Self, Self::Error> { |
|
128 | 128 | match value { |
|
129 | 129 | b'n' => Ok(EntryState::Normal), |
|
130 | 130 | b'a' => Ok(EntryState::Added), |
|
131 | 131 | b'r' => Ok(EntryState::Removed), |
|
132 | 132 | b'm' => Ok(EntryState::Merged), |
|
133 | 133 | b'?' => Ok(EntryState::Unknown), |
|
134 | 134 | _ => Err(HgError::CorruptedRepository(format!( |
|
135 | 135 | "Incorrect dirstate entry state {}", |
|
136 | 136 | value |
|
137 | 137 | ))), |
|
138 | 138 | } |
|
139 | 139 | } |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | impl Into<u8> for EntryState { |
|
143 | 143 | fn into(self) -> u8 { |
|
144 | 144 | match self { |
|
145 | 145 | EntryState::Normal => b'n', |
|
146 | 146 | EntryState::Added => b'a', |
|
147 | 147 | EntryState::Removed => b'r', |
|
148 | 148 | EntryState::Merged => b'm', |
|
149 | 149 | EntryState::Unknown => b'?', |
|
150 | 150 | } |
|
151 | 151 | } |
|
152 | 152 | } |
General Comments 0
You need to be logged in to leave comments.
Login now