##// END OF EJS Templates
rust-dirstate: introduce intermediate struct for dirstate-v2 data...
Raphaël Gomès -
r49991:38e5bb14 default
parent child Browse files
Show More
@@ -248,23 +248,35 b' pub const SIZE_FROM_OTHER_PARENT: i32 = '
248 248 /// dirstate v1 format.
249 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 262 impl DirstateEntry {
252 pub fn from_v2_data(
253 wdir_tracked: bool,
254 p1_tracked: bool,
255 p2_info: bool,
256 mode_size: Option<(u32, u32)>,
257 mtime: Option<TruncatedTimestamp>,
258 fallback_exec: Option<bool>,
259 fallback_symlink: Option<bool>,
260 ) -> Self {
263 pub fn from_v2_data(v2_data: DirstateV2Data) -> Self {
264 let DirstateV2Data {
265 wc_tracked,
266 p1_tracked,
267 p2_info,
268 mode_size,
269 mtime,
270 fallback_exec,
271 fallback_symlink,
272 } = v2_data;
261 273 if let Some((mode, size)) = mode_size {
262 274 // TODO: return an error for out of range values?
263 275 assert!(mode & !RANGE_MASK_31BIT == 0);
264 276 assert!(size & !RANGE_MASK_31BIT == 0);
265 277 }
266 278 let mut flags = Flags::empty();
267 flags.set(Flags::WDIR_TRACKED, wdir_tracked);
279 flags.set(Flags::WDIR_TRACKED, wc_tracked);
268 280 flags.set(Flags::P1_TRACKED, p1_tracked);
269 281 flags.set(Flags::P2_INFO, p2_info);
270 282 if let Some(exec) = fallback_exec {
@@ -368,7 +380,11 b' impl DirstateEntry {'
368 380 }
369 381
370 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 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)`
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 ) {
432 pub(crate) fn v2_data(&self) -> DirstateV2Data {
428 433 if !self.any_tracked() {
429 434 // TODO: return an Option instead?
430 435 panic!("Accessing v2_data of an untracked DirstateEntry")
431 436 }
432 let wdir_tracked = self.flags.contains(Flags::WDIR_TRACKED);
437 let wc_tracked = self.flags.contains(Flags::WDIR_TRACKED);
433 438 let p1_tracked = self.flags.contains(Flags::P1_TRACKED);
434 439 let p2_info = self.flags.contains(Flags::P2_INFO);
435 440 let mode_size = self.mode_size;
436 441 let mtime = self.mtime;
437 (
438 wdir_tracked,
442 DirstateV2Data {
443 wc_tracked,
439 444 p1_tracked,
440 445 p2_info,
441 446 mode_size,
442 447 mtime,
443 self.get_fallback_exec(),
444 self.get_fallback_symlink(),
445 )
448 fallback_exec: self.get_fallback_exec(),
449 fallback_symlink: self.get_fallback_symlink(),
450 }
446 451 }
447 452
448 453 fn v1_state(&self) -> EntryState {
@@ -2,7 +2,7 b''
2 2 //!
3 3 //! See `mercurial/helptext/internals/dirstate-v2.txt`
4 4
5 use crate::dirstate::TruncatedTimestamp;
5 use crate::dirstate::{DirstateV2Data, TruncatedTimestamp};
6 6 use crate::dirstate_tree::dirstate_map::{self, DirstateMap, NodeRef};
7 7 use crate::dirstate_tree::path_with_basename::WithBasename;
8 8 use crate::errors::HgError;
@@ -412,7 +412,7 b' impl Node {'
412 412
413 413 fn assume_entry(&self) -> Result<DirstateEntry, DirstateV2ParseError> {
414 414 // TODO: convert through raw bits instead?
415 let wdir_tracked = self.flags().contains(Flags::WDIR_TRACKED);
415 let wc_tracked = self.flags().contains(Flags::WDIR_TRACKED);
416 416 let p1_tracked = self.flags().contains(Flags::P1_TRACKED);
417 417 let p2_info = self.flags().contains(Flags::P2_INFO);
418 418 let mode_size = if self.flags().contains(Flags::HAS_MODE_AND_SIZE)
@@ -442,15 +442,15 b' impl Node {'
442 442 } else {
443 443 None
444 444 };
445 Ok(DirstateEntry::from_v2_data(
446 wdir_tracked,
445 Ok(DirstateEntry::from_v2_data(DirstateV2Data {
446 wc_tracked,
447 447 p1_tracked,
448 448 p2_info,
449 449 mode_size,
450 450 mtime,
451 451 fallback_exec,
452 452 fallback_symlink,
453 ))
453 }))
454 454 }
455 455
456 456 pub(super) fn entry(
@@ -490,18 +490,18 b' impl Node {'
490 490 fn from_dirstate_entry(
491 491 entry: &DirstateEntry,
492 492 ) -> (Flags, U32Be, PackedTruncatedTimestamp) {
493 let (
494 wdir_tracked,
493 let DirstateV2Data {
494 wc_tracked,
495 495 p1_tracked,
496 496 p2_info,
497 mode_size_opt,
498 mtime_opt,
497 mode_size: mode_size_opt,
498 mtime: mtime_opt,
499 499 fallback_exec,
500 500 fallback_symlink,
501 ) = entry.v2_data();
502 // TODO: convert throug raw flag bits instead?
501 } = entry.v2_data();
502 // TODO: convert through raw flag bits instead?
503 503 let mut flags = Flags::empty();
504 flags.set(Flags::WDIR_TRACKED, wdir_tracked);
504 flags.set(Flags::WDIR_TRACKED, wc_tracked);
505 505 flags.set(Flags::P1_TRACKED, p1_tracked);
506 506 flags.set(Flags::P2_INFO, p2_info);
507 507 let size = if let Some((m, s)) = mode_size_opt {
@@ -8,6 +8,7 b' use cpython::PyResult;'
8 8 use cpython::Python;
9 9 use cpython::PythonObject;
10 10 use hg::dirstate::DirstateEntry;
11 use hg::dirstate::DirstateV2Data;
11 12 use hg::dirstate::TruncatedTimestamp;
12 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 wc_tracked,
42 let entry = DirstateEntry::from_v2_data(DirstateV2Data {
43 wc_tracked: wc_tracked,
43 44 p1_tracked,
44 45 p2_info,
45 mode_size_opt,
46 mtime_opt,
46 mode_size: mode_size_opt,
47 mtime: mtime_opt,
47 48 fallback_exec,
48 49 fallback_symlink,
49 );
50 });
50 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