##// END OF EJS Templates
rust: Remove EntryState::Unknown...
Simon Sapin -
r48838:1b2ee68e default
parent child Browse files
Show More
@@ -111,17 +111,13 b' impl DirstateMap {'
111 let mode = entry.mode();
111 let mode = entry.mode();
112 let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
112 let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
113
113
114 let old_state = match self.get(filename) {
114 let old_state = self.get(filename).map(|e| e.state());
115 Some(e) => e.state(),
115 if old_state.is_none() || old_state == Some(EntryState::Removed) {
116 None => EntryState::Unknown,
117 };
118 if old_state == EntryState::Unknown || old_state == EntryState::Removed
119 {
120 if let Some(ref mut dirs) = self.dirs {
116 if let Some(ref mut dirs) = self.dirs {
121 dirs.add_path(filename)?;
117 dirs.add_path(filename)?;
122 }
118 }
123 }
119 }
124 if old_state == EntryState::Unknown {
120 if old_state.is_none() {
125 if let Some(ref mut all_dirs) = self.all_dirs {
121 if let Some(ref mut all_dirs) = self.all_dirs {
126 all_dirs.add_path(filename)?;
122 all_dirs.add_path(filename)?;
127 }
123 }
@@ -153,10 +149,7 b' impl DirstateMap {'
153 in_merge: bool,
149 in_merge: bool,
154 ) -> Result<(), DirstateError> {
150 ) -> Result<(), DirstateError> {
155 let old_entry_opt = self.get(filename);
151 let old_entry_opt = self.get(filename);
156 let old_state = match old_entry_opt {
152 let old_state = old_entry_opt.map(|e| e.state());
157 Some(e) => e.state(),
158 None => EntryState::Unknown,
159 };
160 let mut size = 0;
153 let mut size = 0;
161 if in_merge {
154 if in_merge {
162 // XXX we should not be able to have 'm' state and 'FROM_P2' if not
155 // XXX we should not be able to have 'm' state and 'FROM_P2' if not
@@ -178,13 +171,12 b' impl DirstateMap {'
178 }
171 }
179 }
172 }
180 }
173 }
181 if old_state != EntryState::Unknown && old_state != EntryState::Removed
174 if old_state.is_some() && old_state != Some(EntryState::Removed) {
182 {
183 if let Some(ref mut dirs) = self.dirs {
175 if let Some(ref mut dirs) = self.dirs {
184 dirs.delete_path(filename)?;
176 dirs.delete_path(filename)?;
185 }
177 }
186 }
178 }
187 if old_state == EntryState::Unknown {
179 if old_state.is_none() {
188 if let Some(ref mut all_dirs) = self.all_dirs {
180 if let Some(ref mut all_dirs) = self.all_dirs {
189 all_dirs.add_path(filename)?;
181 all_dirs.add_path(filename)?;
190 }
182 }
@@ -207,14 +199,11 b' impl DirstateMap {'
207 &mut self,
199 &mut self,
208 filename: &HgPath,
200 filename: &HgPath,
209 ) -> Result<bool, DirstateError> {
201 ) -> Result<bool, DirstateError> {
210 let old_state = match self.get(filename) {
202 let old_state = self.get(filename).map(|e| e.state());
211 Some(e) => e.state(),
212 None => EntryState::Unknown,
213 };
214 let exists = self.state_map.remove(filename).is_some();
203 let exists = self.state_map.remove(filename).is_some();
215
204
216 if exists {
205 if exists {
217 if old_state != EntryState::Removed {
206 if old_state != Some(EntryState::Removed) {
218 if let Some(ref mut dirs) = self.dirs {
207 if let Some(ref mut dirs) = self.dirs {
219 dirs.delete_path(filename)?;
208 dirs.delete_path(filename)?;
220 }
209 }
@@ -7,7 +7,6 b' pub enum EntryState {'
7 Added,
7 Added,
8 Removed,
8 Removed,
9 Merged,
9 Merged,
10 Unknown,
11 }
10 }
12
11
13 /// The C implementation uses all signed types. This will be an issue
12 /// The C implementation uses all signed types. This will be an issue
@@ -157,7 +156,7 b' impl EntryState {'
157 use EntryState::*;
156 use EntryState::*;
158 match self {
157 match self {
159 Normal | Added | Merged => true,
158 Normal | Added | Merged => true,
160 Removed | Unknown => false,
159 Removed => false,
161 }
160 }
162 }
161 }
163 }
162 }
@@ -171,7 +170,6 b' impl TryFrom<u8> for EntryState {'
171 b'a' => Ok(EntryState::Added),
170 b'a' => Ok(EntryState::Added),
172 b'r' => Ok(EntryState::Removed),
171 b'r' => Ok(EntryState::Removed),
173 b'm' => Ok(EntryState::Merged),
172 b'm' => Ok(EntryState::Merged),
174 b'?' => Ok(EntryState::Unknown),
175 _ => Err(HgError::CorruptedRepository(format!(
173 _ => Err(HgError::CorruptedRepository(format!(
176 "Incorrect dirstate entry state {}",
174 "Incorrect dirstate entry state {}",
177 value
175 value
@@ -187,7 +185,6 b' impl Into<u8> for EntryState {'
187 EntryState::Added => b'a',
185 EntryState::Added => b'a',
188 EntryState::Removed => b'r',
186 EntryState::Removed => b'r',
189 EntryState::Merged => b'm',
187 EntryState::Merged => b'm',
190 EntryState::Unknown => b'?',
191 }
188 }
192 }
189 }
193 }
190 }
@@ -205,7 +205,6 b' fn dispatch_found('
205 EntryState::Merged => Dispatch::Modified,
205 EntryState::Merged => Dispatch::Modified,
206 EntryState::Added => Dispatch::Added,
206 EntryState::Added => Dispatch::Added,
207 EntryState::Removed => Dispatch::Removed,
207 EntryState::Removed => Dispatch::Removed,
208 EntryState::Unknown => Dispatch::Unknown,
209 }
208 }
210 }
209 }
211
210
@@ -218,8 +217,6 b' fn dispatch_missing(state: EntryState) -'
218 }
217 }
219 // File was removed, everything is normal
218 // File was removed, everything is normal
220 EntryState::Removed => Dispatch::Removed,
219 EntryState::Removed => Dispatch::Removed,
221 // File is unknown to Mercurial, everything is normal
222 EntryState::Unknown => Dispatch::Unknown,
223 }
220 }
224 }
221 }
225
222
@@ -593,12 +593,13 b" impl<'on_disk> DirstateMap<'on_disk> {"
593 fn add_or_remove_file(
593 fn add_or_remove_file(
594 &mut self,
594 &mut self,
595 path: &HgPath,
595 path: &HgPath,
596 old_state: EntryState,
596 old_state: Option<EntryState>,
597 new_entry: DirstateEntry,
597 new_entry: DirstateEntry,
598 ) -> Result<(), DirstateV2ParseError> {
598 ) -> Result<(), DirstateV2ParseError> {
599 let had_entry = old_state != EntryState::Unknown;
599 let had_entry = old_state.is_some();
600 let was_tracked = old_state.map_or(false, |s| s.is_tracked());
600 let tracked_count_increment =
601 let tracked_count_increment =
601 match (old_state.is_tracked(), new_entry.state().is_tracked()) {
602 match (was_tracked, new_entry.state().is_tracked()) {
602 (false, true) => 1,
603 (false, true) => 1,
603 (true, false) => -1,
604 (true, false) => -1,
604 _ => 0,
605 _ => 0,
@@ -808,10 +809,7 b" impl<'on_disk> super::dispatch::Dirstate"
808 let mode = entry.mode();
809 let mode = entry.mode();
809 let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
810 let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
810
811
811 let old_state = match self.get(filename)? {
812 let old_state = self.get(filename)?.map(|e| e.state());
812 Some(e) => e.state(),
813 None => EntryState::Unknown,
814 };
815
813
816 Ok(self.add_or_remove_file(filename, old_state, entry)?)
814 Ok(self.add_or_remove_file(filename, old_state, entry)?)
817 }
815 }
@@ -822,10 +820,7 b" impl<'on_disk> super::dispatch::Dirstate"
822 in_merge: bool,
820 in_merge: bool,
823 ) -> Result<(), DirstateError> {
821 ) -> Result<(), DirstateError> {
824 let old_entry_opt = self.get(filename)?;
822 let old_entry_opt = self.get(filename)?;
825 let old_state = match old_entry_opt {
823 let old_state = old_entry_opt.map(|e| e.state());
826 Some(e) => e.state(),
827 None => EntryState::Unknown,
828 };
829 let mut size = 0;
824 let mut size = 0;
830 if in_merge {
825 if in_merge {
831 // XXX we should not be able to have 'm' state and 'FROM_P2' if not
826 // XXX we should not be able to have 'm' state and 'FROM_P2' if not
@@ -852,10 +847,9 b" impl<'on_disk> super::dispatch::Dirstate"
852 }
847 }
853
848
854 fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError> {
849 fn drop_file(&mut self, filename: &HgPath) -> Result<bool, DirstateError> {
855 let old_state = match self.get(filename)? {
850 let was_tracked = self
856 Some(e) => e.state(),
851 .get(filename)?
857 None => EntryState::Unknown,
852 .map_or(false, |e| e.state().is_tracked());
858 };
859 struct Dropped {
853 struct Dropped {
860 was_tracked: bool,
854 was_tracked: bool,
861 had_entry: bool,
855 had_entry: bool,
@@ -955,7 +949,7 b" impl<'on_disk> super::dispatch::Dirstate"
955 }
949 }
956 Ok(dropped.had_entry)
950 Ok(dropped.had_entry)
957 } else {
951 } else {
958 debug_assert!(!old_state.is_tracked());
952 debug_assert!(!was_tracked);
959 Ok(false)
953 Ok(false)
960 }
954 }
961 }
955 }
@@ -394,9 +394,6 b" impl<'a, 'tree, 'on_disk> StatusCommon<'"
394 .push(hg_path.detach_from_tree()),
394 .push(hg_path.detach_from_tree()),
395 EntryState::Normal => self
395 EntryState::Normal => self
396 .handle_normal_file(&dirstate_node, fs_metadata)?,
396 .handle_normal_file(&dirstate_node, fs_metadata)?,
397 // This variant is not used in DirstateMap
398 // nodes
399 EntryState::Unknown => unreachable!(),
400 }
397 }
401 } else {
398 } else {
402 // `node.entry.is_none()` indicates a "directory"
399 // `node.entry.is_none()` indicates a "directory"
General Comments 0
You need to be logged in to leave comments. Login now