257 } |
257 } |
258 } |
258 } |
259 |
259 |
260 struct ActionsIterator<'a> { |
260 struct ActionsIterator<'a> { |
261 changes: &'a ChangedFiles<'a>, |
261 changes: &'a ChangedFiles<'a>, |
262 parent: usize, |
262 parent: Parent, |
263 current: u32, |
263 current: u32, |
264 } |
264 } |
265 |
265 |
266 impl<'a> Iterator for ActionsIterator<'a> { |
266 impl<'a> Iterator for ActionsIterator<'a> { |
267 type Item = Action<'a>; |
267 type Item = Action<'a>; |
268 |
268 |
269 fn next(&mut self) -> Option<Action<'a>> { |
269 fn next(&mut self) -> Option<Action<'a>> { |
|
270 let copy_flag = match self.parent { |
|
271 Parent::FirstParent => P1_COPY, |
|
272 Parent::SecondParent => P2_COPY, |
|
273 }; |
270 while self.current < self.changes.nb_items { |
274 while self.current < self.changes.nb_items { |
271 let (flags, file, source) = self.changes.entry(self.current); |
275 let (flags, file, source) = self.changes.entry(self.current); |
272 self.current += 1; |
276 self.current += 1; |
273 if (flags & ACTION_MASK) == REMOVED { |
277 if (flags & ACTION_MASK) == REMOVED { |
274 return Some(Action::Removed(file)); |
278 return Some(Action::Removed(file)); |
275 } |
279 } |
276 let copy = flags & COPY_MASK; |
280 let copy = flags & COPY_MASK; |
277 if self.parent == 1 && copy == P1_COPY { |
281 if copy == copy_flag { |
278 return Some(Action::Copied(file, source)); |
|
279 } |
|
280 if self.parent == 2 && copy == P2_COPY { |
|
281 return Some(Action::Copied(file, source)); |
282 return Some(Action::Copied(file, source)); |
282 } |
283 } |
283 } |
284 } |
284 return None; |
285 return None; |
285 } |
286 } |
298 pub data: Option<D>, |
299 pub data: Option<D>, |
299 } |
300 } |
300 |
301 |
301 pub type RevInfoMaker<'a, D> = |
302 pub type RevInfoMaker<'a, D> = |
302 Box<dyn for<'r> Fn(Revision, &'r mut DataHolder<D>) -> RevInfo<'r> + 'a>; |
303 Box<dyn for<'r> Fn(Revision, &'r mut DataHolder<D>) -> RevInfo<'r> + 'a>; |
|
304 |
|
305 /// enum used to carry information about the parent → child currently processed |
|
306 #[derive(Copy, Clone, Debug)] |
|
307 enum Parent { |
|
308 /// The `p1(x) → x` edge |
|
309 FirstParent, |
|
310 /// The `p2(x) → x` edge |
|
311 SecondParent, |
|
312 } |
303 |
313 |
304 /// Same as mercurial.copies._combine_changeset_copies, but in Rust. |
314 /// Same as mercurial.copies._combine_changeset_copies, but in Rust. |
305 /// |
315 /// |
306 /// Arguments are: |
316 /// Arguments are: |
307 /// |
317 /// |
343 // Creating a new PathCopies for each `rev` → `children` vertex. |
353 // Creating a new PathCopies for each `rev` → `children` vertex. |
344 let mut d: DataHolder<D> = DataHolder { data: None }; |
354 let mut d: DataHolder<D> = DataHolder { data: None }; |
345 let (p1, p2, changes) = rev_info(*child, &mut d); |
355 let (p1, p2, changes) = rev_info(*child, &mut d); |
346 |
356 |
347 let parent = if rev == p1 { |
357 let parent = if rev == p1 { |
348 1 |
358 Parent::FirstParent |
349 } else { |
359 } else { |
350 assert_eq!(rev, p2); |
360 assert_eq!(rev, p2); |
351 2 |
361 Parent::SecondParent |
352 }; |
362 }; |
353 let mut new_copies = copies.clone(); |
363 let mut new_copies = copies.clone(); |
354 |
364 |
355 for action in changes.iter_actions(parent) { |
365 for action in changes.iter_actions(parent) { |
356 match action { |
366 match action { |
404 None => { |
414 None => { |
405 all_copies.insert(child, new_copies); |
415 all_copies.insert(child, new_copies); |
406 } |
416 } |
407 Some(other_copies) => { |
417 Some(other_copies) => { |
408 let (minor, major) = match parent { |
418 let (minor, major) = match parent { |
409 1 => (other_copies, new_copies), |
419 Parent::FirstParent => (other_copies, new_copies), |
410 2 => (new_copies, other_copies), |
420 Parent::SecondParent => (new_copies, other_copies), |
411 _ => unreachable!(), |
|
412 }; |
421 }; |
413 let merged_copies = |
422 let merged_copies = |
414 merge_copies_dict(minor, major, &changes, &mut oracle); |
423 merge_copies_dict(minor, major, &changes, &mut oracle); |
415 all_copies.insert(child, merged_copies); |
424 all_copies.insert(child, merged_copies); |
416 } |
425 } |