20 size: i32, |
20 size: i32, |
21 mtime: i32, |
21 mtime: i32, |
22 } |
22 } |
23 |
23 |
24 bitflags! { |
24 bitflags! { |
25 struct Flags: u8 { |
25 pub struct Flags: u8 { |
26 const WDIR_TRACKED = 1 << 0; |
26 const WDIR_TRACKED = 1 << 0; |
27 const P1_TRACKED = 1 << 1; |
27 const P1_TRACKED = 1 << 1; |
28 const P2_TRACKED = 1 << 2; |
28 const P2_TRACKED = 1 << 2; |
29 const POSSIBLY_DIRTY = 1 << 3; |
29 const POSSIBLY_DIRTY = 1 << 3; |
30 const MERGED = 1 << 4; |
30 const MERGED = 1 << 4; |
45 /// A special value used for internal representation of special case in |
45 /// A special value used for internal representation of special case in |
46 /// dirstate v1 format. |
46 /// dirstate v1 format. |
47 pub const SIZE_NON_NORMAL: i32 = -1; |
47 pub const SIZE_NON_NORMAL: i32 = -1; |
48 |
48 |
49 impl DirstateEntry { |
49 impl DirstateEntry { |
|
50 pub fn new( |
|
51 flags: Flags, |
|
52 mode_size_mtime: Option<(i32, i32, i32)>, |
|
53 ) -> Self { |
|
54 let (mode, size, mtime) = |
|
55 mode_size_mtime.unwrap_or((0, SIZE_NON_NORMAL, MTIME_UNSET)); |
|
56 Self { |
|
57 flags, |
|
58 mode, |
|
59 size, |
|
60 mtime, |
|
61 } |
|
62 } |
|
63 |
50 pub fn from_v1_data( |
64 pub fn from_v1_data( |
51 state: EntryState, |
65 state: EntryState, |
52 mode: i32, |
66 mode: i32, |
53 size: i32, |
67 size: i32, |
54 mtime: i32, |
68 mtime: i32, |
153 // XXX Arbitrary default value since the value is determined later |
167 // XXX Arbitrary default value since the value is determined later |
154 let state = EntryState::Normal; |
168 let state = EntryState::Normal; |
155 Self::from_v1_data(state, mode, size, mtime) |
169 Self::from_v1_data(state, mode, size, mtime) |
156 } |
170 } |
157 |
171 |
|
172 pub fn tracked(&self) -> bool { |
|
173 self.flags.contains(Flags::WDIR_TRACKED) |
|
174 } |
|
175 |
158 fn tracked_in_any_parent(&self) -> bool { |
176 fn tracked_in_any_parent(&self) -> bool { |
159 self.flags.intersects(Flags::P1_TRACKED | Flags::P2_TRACKED) |
177 self.flags.intersects(Flags::P1_TRACKED | Flags::P2_TRACKED) |
160 } |
178 } |
161 |
179 |
162 fn removed(&self) -> bool { |
180 pub fn removed(&self) -> bool { |
163 self.tracked_in_any_parent() |
181 self.tracked_in_any_parent() |
164 && !self.flags.contains(Flags::WDIR_TRACKED) |
182 && !self.flags.contains(Flags::WDIR_TRACKED) |
165 } |
183 } |
166 |
184 |
167 fn merged_removed(&self) -> bool { |
185 pub fn merged_removed(&self) -> bool { |
168 self.removed() && self.flags.contains(Flags::MERGED) |
186 self.removed() && self.flags.contains(Flags::MERGED) |
169 } |
187 } |
170 |
188 |
171 fn from_p2_removed(&self) -> bool { |
189 pub fn from_p2_removed(&self) -> bool { |
172 self.removed() && self.flags.contains(Flags::CLEAN_P2) |
190 self.removed() && self.flags.contains(Flags::CLEAN_P2) |
173 } |
191 } |
174 |
192 |
175 fn merged(&self) -> bool { |
193 pub fn merged(&self) -> bool { |
176 self.flags.contains(Flags::WDIR_TRACKED | Flags::MERGED) |
194 self.flags.contains(Flags::WDIR_TRACKED | Flags::MERGED) |
177 } |
195 } |
178 |
196 |
179 fn added(&self) -> bool { |
197 pub fn added(&self) -> bool { |
180 self.flags.contains(Flags::WDIR_TRACKED) |
198 self.flags.contains(Flags::WDIR_TRACKED) |
181 && !self.tracked_in_any_parent() |
199 && !self.tracked_in_any_parent() |
182 } |
200 } |
183 |
201 |
184 fn from_p2(&self) -> bool { |
202 pub fn from_p2(&self) -> bool { |
185 self.flags.contains(Flags::WDIR_TRACKED | Flags::CLEAN_P2) |
203 self.flags.contains(Flags::WDIR_TRACKED | Flags::CLEAN_P2) |
186 } |
204 } |
187 |
205 |
188 pub fn state(&self) -> EntryState { |
206 pub fn state(&self) -> EntryState { |
189 if self.removed() { |
207 if self.removed() { |
235 } else { |
253 } else { |
236 self.mtime |
254 self.mtime |
237 } |
255 } |
238 } |
256 } |
239 |
257 |
|
258 pub fn set_possibly_dirty(&mut self) { |
|
259 self.flags.insert(Flags::POSSIBLY_DIRTY) |
|
260 } |
|
261 |
|
262 pub fn set_clean(&mut self, mode: i32, size: i32, mtime: i32) { |
|
263 self.flags.insert(Flags::WDIR_TRACKED | Flags::P1_TRACKED); |
|
264 self.flags.remove( |
|
265 Flags::P2_TRACKED // This might be wrong |
|
266 | Flags::MERGED |
|
267 | Flags::CLEAN_P2 |
|
268 | Flags::POSSIBLY_DIRTY, |
|
269 ); |
|
270 self.mode = mode; |
|
271 self.size = size; |
|
272 self.mtime = mtime; |
|
273 } |
|
274 |
|
275 pub fn set_tracked(&mut self) { |
|
276 self.flags |
|
277 .insert(Flags::WDIR_TRACKED | Flags::POSSIBLY_DIRTY); |
|
278 // size = None on the python size turn into size = NON_NORMAL when |
|
279 // accessed. So the next line is currently required, but a some future |
|
280 // clean up would be welcome. |
|
281 self.size = SIZE_NON_NORMAL; |
|
282 } |
|
283 |
|
284 pub fn set_untracked(&mut self) { |
|
285 self.flags.remove(Flags::WDIR_TRACKED); |
|
286 self.mode = 0; |
|
287 self.size = 0; |
|
288 self.mtime = 0; |
|
289 } |
|
290 |
240 /// Returns `(state, mode, size, mtime)` for the puprose of serialization |
291 /// Returns `(state, mode, size, mtime)` for the puprose of serialization |
241 /// in the dirstate-v1 format. |
292 /// in the dirstate-v1 format. |
242 /// |
293 /// |
243 /// This includes marker values such as `mtime == -1`. In the future we may |
294 /// This includes marker values such as `mtime == -1`. In the future we may |
244 /// want to not represent these cases that way in memory, but serialization |
295 /// want to not represent these cases that way in memory, but serialization |