Show More
@@ -18,8 +18,8 b' pub enum EntryState {' | |||||
18 | #[derive(Debug, PartialEq, Copy, Clone)] |
|
18 | #[derive(Debug, PartialEq, Copy, Clone)] | |
19 | pub struct DirstateEntry { |
|
19 | pub struct DirstateEntry { | |
20 | pub(crate) flags: Flags, |
|
20 | pub(crate) flags: Flags, | |
21 |
mode_size: Option<( |
|
21 | mode_size: Option<(u32, u32)>, | |
22 |
mtime: Option< |
|
22 | mtime: Option<u32>, | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | bitflags! { |
|
25 | bitflags! { | |
@@ -153,9 +153,17 b' impl DirstateEntry {' | |||||
153 | wdir_tracked: bool, |
|
153 | wdir_tracked: bool, | |
154 | p1_tracked: bool, |
|
154 | p1_tracked: bool, | |
155 | p2_info: bool, |
|
155 | p2_info: bool, | |
156 |
mode_size: Option<( |
|
156 | mode_size: Option<(u32, u32)>, | |
157 |
mtime: Option< |
|
157 | mtime: Option<u32>, | |
158 | ) -> Self { |
|
158 | ) -> Self { | |
|
159 | if let Some((mode, size)) = mode_size { | |||
|
160 | // TODO: return an error for out of range values? | |||
|
161 | assert!(mode & !RANGE_MASK_31BIT == 0); | |||
|
162 | assert!(size & !RANGE_MASK_31BIT == 0); | |||
|
163 | } | |||
|
164 | if let Some(mtime) = mtime { | |||
|
165 | assert!(mtime & !RANGE_MASK_31BIT == 0); | |||
|
166 | } | |||
159 | let mut flags = Flags::empty(); |
|
167 | let mut flags = Flags::empty(); | |
160 | flags.set(Flags::WDIR_TRACKED, wdir_tracked); |
|
168 | flags.set(Flags::WDIR_TRACKED, wdir_tracked); | |
161 | flags.set(Flags::P1_TRACKED, p1_tracked); |
|
169 | flags.set(Flags::P1_TRACKED, p1_tracked); | |
@@ -189,12 +197,19 b' impl DirstateEntry {' | |||||
189 | mtime: None, |
|
197 | mtime: None, | |
190 | } |
|
198 | } | |
191 | } else if mtime == MTIME_UNSET { |
|
199 | } else if mtime == MTIME_UNSET { | |
|
200 | // TODO: return an error for negative values? | |||
|
201 | let mode = u32::try_from(mode).unwrap(); | |||
|
202 | let size = u32::try_from(size).unwrap(); | |||
192 | Self { |
|
203 | Self { | |
193 | flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, |
|
204 | flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, | |
194 | mode_size: Some((mode, size)), |
|
205 | mode_size: Some((mode, size)), | |
195 | mtime: None, |
|
206 | mtime: None, | |
196 | } |
|
207 | } | |
197 | } else { |
|
208 | } else { | |
|
209 | // TODO: return an error for negative values? | |||
|
210 | let mode = u32::try_from(mode).unwrap(); | |||
|
211 | let size = u32::try_from(size).unwrap(); | |||
|
212 | let mtime = u32::try_from(mtime).unwrap(); | |||
198 | Self { |
|
213 | Self { | |
199 | flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, |
|
214 | flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, | |
200 | mode_size: Some((mode, size)), |
|
215 | mode_size: Some((mode, size)), | |
@@ -282,7 +297,7 b' impl DirstateEntry {' | |||||
282 | /// Returns `(wdir_tracked, p1_tracked, p2_info, mode_size, mtime)` |
|
297 | /// Returns `(wdir_tracked, p1_tracked, p2_info, mode_size, mtime)` | |
283 | pub(crate) fn v2_data( |
|
298 | pub(crate) fn v2_data( | |
284 | &self, |
|
299 | &self, | |
285 |
) -> (bool, bool, bool, Option<( |
|
300 | ) -> (bool, bool, bool, Option<(u32, u32)>, Option<u32>) { | |
286 | if !self.any_tracked() { |
|
301 | if !self.any_tracked() { | |
287 | // TODO: return an Option instead? |
|
302 | // TODO: return an Option instead? | |
288 | panic!("Accessing v1_state of an untracked DirstateEntry") |
|
303 | panic!("Accessing v1_state of an untracked DirstateEntry") | |
@@ -316,7 +331,7 b' impl DirstateEntry {' | |||||
316 |
|
331 | |||
317 | fn v1_mode(&self) -> i32 { |
|
332 | fn v1_mode(&self) -> i32 { | |
318 | if let Some((mode, _size)) = self.mode_size { |
|
333 | if let Some((mode, _size)) = self.mode_size { | |
319 | mode |
|
334 | i32::try_from(mode).unwrap() | |
320 | } else { |
|
335 | } else { | |
321 | 0 |
|
336 | 0 | |
322 | } |
|
337 | } | |
@@ -338,7 +353,7 b' impl DirstateEntry {' | |||||
338 | } else if self.added() { |
|
353 | } else if self.added() { | |
339 | SIZE_NON_NORMAL |
|
354 | SIZE_NON_NORMAL | |
340 | } else if let Some((_mode, size)) = self.mode_size { |
|
355 | } else if let Some((_mode, size)) = self.mode_size { | |
341 | size |
|
356 | i32::try_from(size).unwrap() | |
342 | } else { |
|
357 | } else { | |
343 | SIZE_NON_NORMAL |
|
358 | SIZE_NON_NORMAL | |
344 | } |
|
359 | } | |
@@ -355,8 +370,10 b' impl DirstateEntry {' | |||||
355 | MTIME_UNSET |
|
370 | MTIME_UNSET | |
356 | } else if !self.flags.contains(Flags::P1_TRACKED) { |
|
371 | } else if !self.flags.contains(Flags::P1_TRACKED) { | |
357 | MTIME_UNSET |
|
372 | MTIME_UNSET | |
|
373 | } else if let Some(mtime) = self.mtime { | |||
|
374 | i32::try_from(mtime).unwrap() | |||
358 | } else { |
|
375 | } else { | |
359 |
|
|
376 | MTIME_UNSET | |
360 | } |
|
377 | } | |
361 | } |
|
378 | } | |
362 |
|
379 | |||
@@ -392,7 +409,9 b' impl DirstateEntry {' | |||||
392 | self.mtime = None |
|
409 | self.mtime = None | |
393 | } |
|
410 | } | |
394 |
|
411 | |||
395 |
pub fn set_clean(&mut self, mode: |
|
412 | pub fn set_clean(&mut self, mode: u32, size: u32, mtime: u32) { | |
|
413 | let size = size & RANGE_MASK_31BIT; | |||
|
414 | let mtime = mtime & RANGE_MASK_31BIT; | |||
396 | self.flags.insert(Flags::WDIR_TRACKED | Flags::P1_TRACKED); |
|
415 | self.flags.insert(Flags::WDIR_TRACKED | Flags::P1_TRACKED); | |
397 | self.mode_size = Some((mode, size)); |
|
416 | self.mode_size = Some((mode, size)); | |
398 | self.mtime = Some(mtime); |
|
417 | self.mtime = Some(mtime); |
@@ -11,7 +11,7 b' use crate::DirstateEntry;' | |||||
11 | use crate::DirstateError; |
|
11 | use crate::DirstateError; | |
12 | use crate::DirstateParents; |
|
12 | use crate::DirstateParents; | |
13 | use bitflags::bitflags; |
|
13 | use bitflags::bitflags; | |
14 |
use bytes_cast::unaligned::{ |
|
14 | use bytes_cast::unaligned::{U16Be, U32Be}; | |
15 | use bytes_cast::BytesCast; |
|
15 | use bytes_cast::BytesCast; | |
16 | use format_bytes::format_bytes; |
|
16 | use format_bytes::format_bytes; | |
17 | use std::borrow::Cow; |
|
17 | use std::borrow::Cow; | |
@@ -113,9 +113,9 b' bitflags! {' | |||||
113 | #[derive(BytesCast, Copy, Clone, Debug)] |
|
113 | #[derive(BytesCast, Copy, Clone, Debug)] | |
114 | #[repr(C)] |
|
114 | #[repr(C)] | |
115 | struct Entry { |
|
115 | struct Entry { | |
116 |
mode: |
|
116 | mode: U32Be, | |
117 |
size: |
|
117 | size: U32Be, | |
118 |
mtime: |
|
118 | mtime: U32Be, | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | /// Duration since the Unix epoch |
|
121 | /// Duration since the Unix epoch |
@@ -21,7 +21,7 b' py_class!(pub class DirstateItem |py| {' | |||||
21 | p2_info: bool = false, |
|
21 | p2_info: bool = false, | |
22 | has_meaningful_data: bool = true, |
|
22 | has_meaningful_data: bool = true, | |
23 | has_meaningful_mtime: bool = true, |
|
23 | has_meaningful_mtime: bool = true, | |
24 |
parentfiledata: Option<( |
|
24 | parentfiledata: Option<(u32, u32, u32)> = None, | |
25 |
|
25 | |||
26 | ) -> PyResult<DirstateItem> { |
|
26 | ) -> PyResult<DirstateItem> { | |
27 | let mut mode_size_opt = None; |
|
27 | let mut mode_size_opt = None; | |
@@ -145,9 +145,9 b' py_class!(pub class DirstateItem |py| {' | |||||
145 |
|
145 | |||
146 | def set_clean( |
|
146 | def set_clean( | |
147 | &self, |
|
147 | &self, | |
148 |
mode: |
|
148 | mode: u32, | |
149 |
size: |
|
149 | size: u32, | |
150 |
mtime: |
|
150 | mtime: u32, | |
151 | ) -> PyResult<PyNone> { |
|
151 | ) -> PyResult<PyNone> { | |
152 | self.update(py, |entry| entry.set_clean(mode, size, mtime)); |
|
152 | self.update(py, |entry| entry.set_clean(mode, size, mtime)); | |
153 | Ok(PyNone) |
|
153 | Ok(PyNone) |
General Comments 0
You need to be logged in to leave comments.
Login now