##// END OF EJS Templates
rust-dirstatemap: cache non normal and other parent set...
Raphaël Gomès -
r44835:58c74a51 stable
parent child Browse files
Show More
@@ -34,8 +34,8 b' pub struct DirstateMap {'
34 file_fold_map: Option<FileFoldMap>,
34 file_fold_map: Option<FileFoldMap>,
35 pub dirs: Option<DirsMultiset>,
35 pub dirs: Option<DirsMultiset>,
36 pub all_dirs: Option<DirsMultiset>,
36 pub all_dirs: Option<DirsMultiset>,
37 non_normal_set: HashSet<HgPathBuf>,
37 non_normal_set: Option<HashSet<HgPathBuf>>,
38 other_parent_set: HashSet<HgPathBuf>,
38 other_parent_set: Option<HashSet<HgPathBuf>>,
39 parents: Option<DirstateParents>,
39 parents: Option<DirstateParents>,
40 dirty_parents: bool,
40 dirty_parents: bool,
41 }
41 }
@@ -69,8 +69,8 b' impl DirstateMap {'
69 self.state_map.clear();
69 self.state_map.clear();
70 self.copy_map.clear();
70 self.copy_map.clear();
71 self.file_fold_map = None;
71 self.file_fold_map = None;
72 self.non_normal_set.clear();
72 self.non_normal_set = None;
73 self.other_parent_set.clear();
73 self.other_parent_set = None;
74 self.set_parents(&DirstateParents {
74 self.set_parents(&DirstateParents {
75 p1: NULL_ID,
75 p1: NULL_ID,
76 p2: NULL_ID,
76 p2: NULL_ID,
@@ -98,11 +98,19 b' impl DirstateMap {'
98 self.state_map.insert(filename.to_owned(), entry.to_owned());
98 self.state_map.insert(filename.to_owned(), entry.to_owned());
99
99
100 if entry.state != EntryState::Normal || entry.mtime == MTIME_UNSET {
100 if entry.state != EntryState::Normal || entry.mtime == MTIME_UNSET {
101 self.non_normal_set.insert(filename.to_owned());
101 self.get_non_normal_other_parent_entries()
102 .0
103 .as_mut()
104 .unwrap()
105 .insert(filename.to_owned());
102 }
106 }
103
107
104 if entry.size == SIZE_FROM_OTHER_PARENT {
108 if entry.size == SIZE_FROM_OTHER_PARENT {
105 self.other_parent_set.insert(filename.to_owned());
109 self.get_non_normal_other_parent_entries()
110 .1
111 .as_mut()
112 .unwrap()
113 .insert(filename.to_owned());
106 }
114 }
107 Ok(())
115 Ok(())
108 }
116 }
@@ -142,7 +150,11 b' impl DirstateMap {'
142 mtime: 0,
150 mtime: 0,
143 },
151 },
144 );
152 );
145 self.non_normal_set.insert(filename.to_owned());
153 self.get_non_normal_other_parent_entries()
154 .0
155 .as_mut()
156 .unwrap()
157 .insert(filename.to_owned());
146 Ok(())
158 Ok(())
147 }
159 }
148
160
@@ -168,7 +180,11 b' impl DirstateMap {'
168 if let Some(ref mut file_fold_map) = self.file_fold_map {
180 if let Some(ref mut file_fold_map) = self.file_fold_map {
169 file_fold_map.remove(&normalize_case(filename));
181 file_fold_map.remove(&normalize_case(filename));
170 }
182 }
171 self.non_normal_set.remove(filename);
183 self.get_non_normal_other_parent_entries()
184 .0
185 .as_mut()
186 .unwrap()
187 .remove(filename);
172
188
173 Ok(exists)
189 Ok(exists)
174 }
190 }
@@ -193,14 +209,55 b' impl DirstateMap {'
193 }
209 }
194 });
210 });
195 if changed {
211 if changed {
196 self.non_normal_set.insert(filename.to_owned());
212 self.get_non_normal_other_parent_entries()
213 .0
214 .as_mut()
215 .unwrap()
216 .insert(filename.to_owned());
197 }
217 }
198 }
218 }
199 }
219 }
200
220
201 pub fn non_normal_other_parent_entries(
221 pub fn non_normal_entries_remove(
202 &self,
222 &mut self,
203 ) -> (HashSet<HgPathBuf>, HashSet<HgPathBuf>) {
223 key: impl AsRef<HgPath>,
224 ) -> bool {
225 self.get_non_normal_other_parent_entries()
226 .0
227 .as_mut()
228 .unwrap()
229 .remove(key.as_ref())
230 }
231 pub fn non_normal_entries_union(
232 &mut self,
233 other: HashSet<HgPathBuf>,
234 ) -> Vec<HgPathBuf> {
235 self.get_non_normal_other_parent_entries()
236 .0
237 .as_mut()
238 .unwrap()
239 .union(&other)
240 .map(|e| e.to_owned())
241 .collect()
242 }
243
244 pub fn get_non_normal_other_parent_entries(
245 &mut self,
246 ) -> (
247 &mut Option<HashSet<HgPathBuf>>,
248 &mut Option<HashSet<HgPathBuf>>,
249 ) {
250 self.set_non_normal_other_parent_entries(false);
251 (&mut self.non_normal_set, &mut self.other_parent_set)
252 }
253
254 pub fn set_non_normal_other_parent_entries(&mut self, force: bool) {
255 if !force
256 && self.non_normal_set.is_some()
257 && self.other_parent_set.is_some()
258 {
259 return;
260 }
204 let mut non_normal = HashSet::new();
261 let mut non_normal = HashSet::new();
205 let mut other_parent = HashSet::new();
262 let mut other_parent = HashSet::new();
206
263
@@ -219,8 +276,8 b' impl DirstateMap {'
219 other_parent.insert(filename.to_owned());
276 other_parent.insert(filename.to_owned());
220 }
277 }
221 }
278 }
222
279 self.non_normal_set = Some(non_normal);
223 (non_normal, other_parent)
280 self.other_parent_set = Some(other_parent);
224 }
281 }
225
282
226 /// Both of these setters and their uses appear to be the simplest way to
283 /// Both of these setters and their uses appear to be the simplest way to
@@ -325,9 +382,7 b' impl DirstateMap {'
325
382
326 self.dirty_parents = false;
383 self.dirty_parents = false;
327
384
328 let result = self.non_normal_other_parent_entries();
385 self.set_non_normal_other_parent_entries(true);
329 self.non_normal_set = result.0;
330 self.other_parent_set = result.1;
331 Ok(packed)
386 Ok(packed)
332 }
387 }
333
388
@@ -385,13 +440,27 b' mod tests {'
385 .unwrap();
440 .unwrap();
386
441
387 assert_eq!(1, map.len());
442 assert_eq!(1, map.len());
388 assert_eq!(0, map.non_normal_set.len());
443 assert_eq!(
389 assert_eq!(0, map.other_parent_set.len());
444 0,
445 map.get_non_normal_other_parent_entries()
446 .0
447 .as_ref()
448 .unwrap()
449 .len()
450 );
451 assert_eq!(
452 0,
453 map.get_non_normal_other_parent_entries()
454 .1
455 .as_ref()
456 .unwrap()
457 .len()
458 );
390 }
459 }
391
460
392 #[test]
461 #[test]
393 fn test_non_normal_other_parent_entries() {
462 fn test_non_normal_other_parent_entries() {
394 let map: DirstateMap = [
463 let mut map: DirstateMap = [
395 (b"f1", (EntryState::Removed, 1337, 1337, 1337)),
464 (b"f1", (EntryState::Removed, 1337, 1337, 1337)),
396 (b"f2", (EntryState::Normal, 1337, 1337, -1)),
465 (b"f2", (EntryState::Normal, 1337, 1337, -1)),
397 (b"f3", (EntryState::Normal, 1337, 1337, 1337)),
466 (b"f3", (EntryState::Normal, 1337, 1337, 1337)),
@@ -427,10 +496,11 b' mod tests {'
427
496
428 let mut other_parent = HashSet::new();
497 let mut other_parent = HashSet::new();
429 other_parent.insert(HgPathBuf::from_bytes(b"f4"));
498 other_parent.insert(HgPathBuf::from_bytes(b"f4"));
499 let entries = map.get_non_normal_other_parent_entries();
430
500
431 assert_eq!(
501 assert_eq!(
432 (non_normal, other_parent),
502 (Some(non_normal), Some(other_parent)),
433 map.non_normal_other_parent_entries()
503 (entries.0.to_owned(), entries.1.to_owned())
434 );
504 );
435 }
505 }
436 }
506 }
General Comments 0
You need to be logged in to leave comments. Login now