6 // GNU General Public License version 2 or any later version. |
6 // GNU General Public License version 2 or any later version. |
7 |
7 |
8 use crate::dirstate::parsers::Timestamp; |
8 use crate::dirstate::parsers::Timestamp; |
9 use crate::{ |
9 use crate::{ |
10 dirstate::EntryState, |
10 dirstate::EntryState, |
11 dirstate::MTIME_UNSET, |
|
12 dirstate::SIZE_FROM_OTHER_PARENT, |
11 dirstate::SIZE_FROM_OTHER_PARENT, |
13 dirstate::SIZE_NON_NORMAL, |
12 dirstate::SIZE_NON_NORMAL, |
14 dirstate::V1_RANGEMASK, |
|
15 pack_dirstate, parse_dirstate, |
13 pack_dirstate, parse_dirstate, |
16 utils::hg_path::{HgPath, HgPathBuf}, |
14 utils::hg_path::{HgPath, HgPathBuf}, |
17 CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents, |
15 CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents, |
18 StateMap, |
16 StateMap, |
19 }; |
17 }; |
71 /// Add a tracked file to the dirstate |
69 /// Add a tracked file to the dirstate |
72 pub fn add_file( |
70 pub fn add_file( |
73 &mut self, |
71 &mut self, |
74 filename: &HgPath, |
72 filename: &HgPath, |
75 entry: DirstateEntry, |
73 entry: DirstateEntry, |
76 // XXX once the dust settle this should probably become an enum |
|
77 added: bool, |
|
78 merged: bool, |
|
79 from_p2: bool, |
|
80 possibly_dirty: bool, |
|
81 ) -> Result<(), DirstateError> { |
74 ) -> Result<(), DirstateError> { |
82 let state; |
|
83 let size; |
|
84 let mtime; |
|
85 if added { |
|
86 assert!(!possibly_dirty); |
|
87 assert!(!from_p2); |
|
88 state = EntryState::Added; |
|
89 size = SIZE_NON_NORMAL; |
|
90 mtime = MTIME_UNSET; |
|
91 } else if merged { |
|
92 assert!(!possibly_dirty); |
|
93 assert!(!from_p2); |
|
94 state = EntryState::Merged; |
|
95 size = SIZE_FROM_OTHER_PARENT; |
|
96 mtime = MTIME_UNSET; |
|
97 } else if from_p2 { |
|
98 assert!(!possibly_dirty); |
|
99 state = EntryState::Normal; |
|
100 size = SIZE_FROM_OTHER_PARENT; |
|
101 mtime = MTIME_UNSET; |
|
102 } else if possibly_dirty { |
|
103 state = EntryState::Normal; |
|
104 size = SIZE_NON_NORMAL; |
|
105 mtime = MTIME_UNSET; |
|
106 } else { |
|
107 state = EntryState::Normal; |
|
108 size = entry.size() & V1_RANGEMASK; |
|
109 mtime = entry.mtime() & V1_RANGEMASK; |
|
110 } |
|
111 let mode = entry.mode(); |
|
112 let entry = DirstateEntry::from_v1_data(state, mode, size, mtime); |
|
113 |
|
114 let old_state = self.get(filename).map(|e| e.state()); |
75 let old_state = self.get(filename).map(|e| e.state()); |
115 if old_state.is_none() || old_state == Some(EntryState::Removed) { |
76 if old_state.is_none() || old_state == Some(EntryState::Removed) { |
116 if let Some(ref mut dirs) = self.dirs { |
77 if let Some(ref mut dirs) = self.dirs { |
117 dirs.add_path(filename)?; |
78 dirs.add_path(filename)?; |
118 } |
79 } |
415 assert_eq!(0, map.len()); |
376 assert_eq!(0, map.len()); |
416 |
377 |
417 map.add_file( |
378 map.add_file( |
418 HgPath::new(b"meh"), |
379 HgPath::new(b"meh"), |
419 DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337), |
380 DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337), |
420 false, |
|
421 false, |
|
422 false, |
|
423 false, |
|
424 ) |
381 ) |
425 .unwrap(); |
382 .unwrap(); |
426 |
383 |
427 assert_eq!(1, map.len()); |
384 assert_eq!(1, map.len()); |
428 assert_eq!(0, map.get_non_normal_other_parent_entries().0.len()); |
385 assert_eq!(0, map.get_non_normal_other_parent_entries().0.len()); |