Show More
@@ -248,23 +248,35 b' pub const SIZE_FROM_OTHER_PARENT: i32 = ' | |||||
248 | /// dirstate v1 format. |
|
248 | /// dirstate v1 format. | |
249 | pub const SIZE_NON_NORMAL: i32 = -1; |
|
249 | pub const SIZE_NON_NORMAL: i32 = -1; | |
250 |
|
250 | |||
|
251 | #[derive(Debug, Default, Copy, Clone)] | |||
|
252 | pub struct DirstateV2Data { | |||
|
253 | pub wc_tracked: bool, | |||
|
254 | pub p1_tracked: bool, | |||
|
255 | pub p2_info: bool, | |||
|
256 | pub mode_size: Option<(u32, u32)>, | |||
|
257 | pub mtime: Option<TruncatedTimestamp>, | |||
|
258 | pub fallback_exec: Option<bool>, | |||
|
259 | pub fallback_symlink: Option<bool>, | |||
|
260 | } | |||
|
261 | ||||
251 | impl DirstateEntry { |
|
262 | impl DirstateEntry { | |
252 | pub fn from_v2_data( |
|
263 | pub fn from_v2_data(v2_data: DirstateV2Data) -> Self { | |
253 | wdir_tracked: bool, |
|
264 | let DirstateV2Data { | |
254 |
|
|
265 | wc_tracked, | |
255 | p2_info: bool, |
|
266 | p1_tracked, | |
256 | mode_size: Option<(u32, u32)>, |
|
267 | p2_info, | |
257 | mtime: Option<TruncatedTimestamp>, |
|
268 | mode_size, | |
258 | fallback_exec: Option<bool>, |
|
269 | mtime, | |
259 | fallback_symlink: Option<bool>, |
|
270 | fallback_exec, | |
260 | ) -> Self { |
|
271 | fallback_symlink, | |
|
272 | } = v2_data; | |||
261 | if let Some((mode, size)) = mode_size { |
|
273 | if let Some((mode, size)) = mode_size { | |
262 | // TODO: return an error for out of range values? |
|
274 | // TODO: return an error for out of range values? | |
263 | assert!(mode & !RANGE_MASK_31BIT == 0); |
|
275 | assert!(mode & !RANGE_MASK_31BIT == 0); | |
264 | assert!(size & !RANGE_MASK_31BIT == 0); |
|
276 | assert!(size & !RANGE_MASK_31BIT == 0); | |
265 | } |
|
277 | } | |
266 | let mut flags = Flags::empty(); |
|
278 | let mut flags = Flags::empty(); | |
267 |
flags.set(Flags::WDIR_TRACKED, w |
|
279 | flags.set(Flags::WDIR_TRACKED, wc_tracked); | |
268 | flags.set(Flags::P1_TRACKED, p1_tracked); |
|
280 | flags.set(Flags::P1_TRACKED, p1_tracked); | |
269 | flags.set(Flags::P2_INFO, p2_info); |
|
281 | flags.set(Flags::P2_INFO, p2_info); | |
270 | if let Some(exec) = fallback_exec { |
|
282 | if let Some(exec) = fallback_exec { | |
@@ -368,7 +380,11 b' impl DirstateEntry {' | |||||
368 | } |
|
380 | } | |
369 |
|
381 | |||
370 | pub fn new_tracked() -> Self { |
|
382 | pub fn new_tracked() -> Self { | |
371 | Self::from_v2_data(true, false, false, None, None, None, None) |
|
383 | let data = DirstateV2Data { | |
|
384 | wc_tracked: true, | |||
|
385 | ..Default::default() | |||
|
386 | }; | |||
|
387 | Self::from_v2_data(data) | |||
372 | } |
|
388 | } | |
373 |
|
389 | |||
374 | pub fn tracked(&self) -> bool { |
|
390 | pub fn tracked(&self) -> bool { | |
@@ -413,36 +429,25 b' impl DirstateEntry {' | |||||
413 | ) |
|
429 | ) | |
414 | } |
|
430 | } | |
415 |
|
431 | |||
416 | /// Returns `(wdir_tracked, p1_tracked, p2_info, mode_size, mtime)` |
|
432 | pub(crate) fn v2_data(&self) -> DirstateV2Data { | |
417 | pub(crate) fn v2_data( |
|
|||
418 | &self, |
|
|||
419 | ) -> ( |
|
|||
420 | bool, |
|
|||
421 | bool, |
|
|||
422 | bool, |
|
|||
423 | Option<(u32, u32)>, |
|
|||
424 | Option<TruncatedTimestamp>, |
|
|||
425 | Option<bool>, |
|
|||
426 | Option<bool>, |
|
|||
427 | ) { |
|
|||
428 | if !self.any_tracked() { |
|
433 | if !self.any_tracked() { | |
429 | // TODO: return an Option instead? |
|
434 | // TODO: return an Option instead? | |
430 | panic!("Accessing v2_data of an untracked DirstateEntry") |
|
435 | panic!("Accessing v2_data of an untracked DirstateEntry") | |
431 | } |
|
436 | } | |
432 |
let w |
|
437 | let wc_tracked = self.flags.contains(Flags::WDIR_TRACKED); | |
433 | let p1_tracked = self.flags.contains(Flags::P1_TRACKED); |
|
438 | let p1_tracked = self.flags.contains(Flags::P1_TRACKED); | |
434 | let p2_info = self.flags.contains(Flags::P2_INFO); |
|
439 | let p2_info = self.flags.contains(Flags::P2_INFO); | |
435 | let mode_size = self.mode_size; |
|
440 | let mode_size = self.mode_size; | |
436 | let mtime = self.mtime; |
|
441 | let mtime = self.mtime; | |
437 | ( |
|
442 | DirstateV2Data { | |
438 |
w |
|
443 | wc_tracked, | |
439 | p1_tracked, |
|
444 | p1_tracked, | |
440 | p2_info, |
|
445 | p2_info, | |
441 | mode_size, |
|
446 | mode_size, | |
442 | mtime, |
|
447 | mtime, | |
443 | self.get_fallback_exec(), |
|
448 | fallback_exec: self.get_fallback_exec(), | |
444 | self.get_fallback_symlink(), |
|
449 | fallback_symlink: self.get_fallback_symlink(), | |
445 |
|
|
450 | } | |
446 | } |
|
451 | } | |
447 |
|
452 | |||
448 | fn v1_state(&self) -> EntryState { |
|
453 | fn v1_state(&self) -> EntryState { |
@@ -2,7 +2,7 b'' | |||||
2 | //! |
|
2 | //! | |
3 | //! See `mercurial/helptext/internals/dirstate-v2.txt` |
|
3 | //! See `mercurial/helptext/internals/dirstate-v2.txt` | |
4 |
|
4 | |||
5 | use crate::dirstate::TruncatedTimestamp; |
|
5 | use crate::dirstate::{DirstateV2Data, TruncatedTimestamp}; | |
6 | use crate::dirstate_tree::dirstate_map::{self, DirstateMap, NodeRef}; |
|
6 | use crate::dirstate_tree::dirstate_map::{self, DirstateMap, NodeRef}; | |
7 | use crate::dirstate_tree::path_with_basename::WithBasename; |
|
7 | use crate::dirstate_tree::path_with_basename::WithBasename; | |
8 | use crate::errors::HgError; |
|
8 | use crate::errors::HgError; | |
@@ -412,7 +412,7 b' impl Node {' | |||||
412 |
|
412 | |||
413 | fn assume_entry(&self) -> Result<DirstateEntry, DirstateV2ParseError> { |
|
413 | fn assume_entry(&self) -> Result<DirstateEntry, DirstateV2ParseError> { | |
414 | // TODO: convert through raw bits instead? |
|
414 | // TODO: convert through raw bits instead? | |
415 |
let w |
|
415 | let wc_tracked = self.flags().contains(Flags::WDIR_TRACKED); | |
416 | let p1_tracked = self.flags().contains(Flags::P1_TRACKED); |
|
416 | let p1_tracked = self.flags().contains(Flags::P1_TRACKED); | |
417 | let p2_info = self.flags().contains(Flags::P2_INFO); |
|
417 | let p2_info = self.flags().contains(Flags::P2_INFO); | |
418 | let mode_size = if self.flags().contains(Flags::HAS_MODE_AND_SIZE) |
|
418 | let mode_size = if self.flags().contains(Flags::HAS_MODE_AND_SIZE) | |
@@ -442,15 +442,15 b' impl Node {' | |||||
442 | } else { |
|
442 | } else { | |
443 | None |
|
443 | None | |
444 | }; |
|
444 | }; | |
445 | Ok(DirstateEntry::from_v2_data( |
|
445 | Ok(DirstateEntry::from_v2_data(DirstateV2Data { | |
446 |
w |
|
446 | wc_tracked, | |
447 | p1_tracked, |
|
447 | p1_tracked, | |
448 | p2_info, |
|
448 | p2_info, | |
449 | mode_size, |
|
449 | mode_size, | |
450 | mtime, |
|
450 | mtime, | |
451 | fallback_exec, |
|
451 | fallback_exec, | |
452 | fallback_symlink, |
|
452 | fallback_symlink, | |
453 | )) |
|
453 | })) | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | pub(super) fn entry( |
|
456 | pub(super) fn entry( | |
@@ -490,18 +490,18 b' impl Node {' | |||||
490 | fn from_dirstate_entry( |
|
490 | fn from_dirstate_entry( | |
491 | entry: &DirstateEntry, |
|
491 | entry: &DirstateEntry, | |
492 | ) -> (Flags, U32Be, PackedTruncatedTimestamp) { |
|
492 | ) -> (Flags, U32Be, PackedTruncatedTimestamp) { | |
493 | let ( |
|
493 | let DirstateV2Data { | |
494 |
w |
|
494 | wc_tracked, | |
495 | p1_tracked, |
|
495 | p1_tracked, | |
496 | p2_info, |
|
496 | p2_info, | |
497 | mode_size_opt, |
|
497 | mode_size: mode_size_opt, | |
498 | mtime_opt, |
|
498 | mtime: mtime_opt, | |
499 | fallback_exec, |
|
499 | fallback_exec, | |
500 | fallback_symlink, |
|
500 | fallback_symlink, | |
501 |
|
|
501 | } = entry.v2_data(); | |
502 | // TODO: convert throug raw flag bits instead? |
|
502 | // TODO: convert through raw flag bits instead? | |
503 | let mut flags = Flags::empty(); |
|
503 | let mut flags = Flags::empty(); | |
504 |
flags.set(Flags::WDIR_TRACKED, w |
|
504 | flags.set(Flags::WDIR_TRACKED, wc_tracked); | |
505 | flags.set(Flags::P1_TRACKED, p1_tracked); |
|
505 | flags.set(Flags::P1_TRACKED, p1_tracked); | |
506 | flags.set(Flags::P2_INFO, p2_info); |
|
506 | flags.set(Flags::P2_INFO, p2_info); | |
507 | let size = if let Some((m, s)) = mode_size_opt { |
|
507 | let size = if let Some((m, s)) = mode_size_opt { |
@@ -8,6 +8,7 b' use cpython::PyResult;' | |||||
8 | use cpython::Python; |
|
8 | use cpython::Python; | |
9 | use cpython::PythonObject; |
|
9 | use cpython::PythonObject; | |
10 | use hg::dirstate::DirstateEntry; |
|
10 | use hg::dirstate::DirstateEntry; | |
|
11 | use hg::dirstate::DirstateV2Data; | |||
11 | use hg::dirstate::TruncatedTimestamp; |
|
12 | use hg::dirstate::TruncatedTimestamp; | |
12 | use std::cell::Cell; |
|
13 | use std::cell::Cell; | |
13 |
|
14 | |||
@@ -38,15 +39,15 b' py_class!(pub class DirstateItem |py| {' | |||||
38 | } |
|
39 | } | |
39 | } |
|
40 | } | |
40 | } |
|
41 | } | |
41 | let entry = DirstateEntry::from_v2_data( |
|
42 | let entry = DirstateEntry::from_v2_data(DirstateV2Data { | |
42 | wc_tracked, |
|
43 | wc_tracked: wc_tracked, | |
43 | p1_tracked, |
|
44 | p1_tracked, | |
44 | p2_info, |
|
45 | p2_info, | |
45 | mode_size_opt, |
|
46 | mode_size: mode_size_opt, | |
46 | mtime_opt, |
|
47 | mtime: mtime_opt, | |
47 | fallback_exec, |
|
48 | fallback_exec, | |
48 | fallback_symlink, |
|
49 | fallback_symlink, | |
49 | ); |
|
50 | }); | |
50 | DirstateItem::create_instance(py, Cell::new(entry)) |
|
51 | DirstateItem::create_instance(py, Cell::new(entry)) | |
51 | } |
|
52 | } | |
52 |
|
53 |
General Comments 0
You need to be logged in to leave comments.
Login now