##// END OF EJS Templates
copies-rust: pass closures and iterators instead of `&ChangedFiles`...
Simon Sapin -
r47356:80f7567a default
parent child Browse files
Show More
@@ -387,6 +387,21 b' impl CombineChangesetCopies {'
387 p2: Revision,
387 p2: Revision,
388 changes: ChangedFiles<'_>,
388 changes: ChangedFiles<'_>,
389 ) {
389 ) {
390 self.add_revision_inner(rev, p1, p2, changes.iter_actions(), |path| {
391 changes.get_merge_case(path)
392 })
393 }
394
395 /// Separated out from `add_revsion` so that unit tests can call this
396 /// without synthetizing a `ChangedFiles` in binary format.
397 fn add_revision_inner<'a>(
398 &mut self,
399 rev: Revision,
400 p1: Revision,
401 p2: Revision,
402 copy_actions: impl Iterator<Item = Action<'a>>,
403 get_merge_case: impl Fn(&HgPath) -> MergeCase + Copy,
404 ) {
390 // Retrieve data computed in a previous iteration
405 // Retrieve data computed in a previous iteration
391 let p1_copies = match p1 {
406 let p1_copies = match p1 {
392 NULL_REVISION => None,
407 NULL_REVISION => None,
@@ -409,7 +424,7 b' impl CombineChangesetCopies {'
409 &mut self.path_map,
424 &mut self.path_map,
410 p1_copies,
425 p1_copies,
411 p2_copies,
426 p2_copies,
412 &changes,
427 copy_actions,
413 rev,
428 rev,
414 );
429 );
415 let copies = match (p1_copies, p2_copies) {
430 let copies = match (p1_copies, p2_copies) {
@@ -421,7 +436,7 b' impl CombineChangesetCopies {'
421 rev,
436 rev,
422 p2_copies,
437 p2_copies,
423 p1_copies,
438 p1_copies,
424 &changes,
439 get_merge_case,
425 )),
440 )),
426 };
441 };
427 if let Some(c) = copies {
442 if let Some(c) = copies {
@@ -476,11 +491,11 b' fn get_and_clean_parent_copies('
476
491
477 /// Combine ChangedFiles with some existing PathCopies information and return
492 /// Combine ChangedFiles with some existing PathCopies information and return
478 /// the result
493 /// the result
479 fn chain_changes(
494 fn chain_changes<'a>(
480 path_map: &mut TwoWayPathMap,
495 path_map: &mut TwoWayPathMap,
481 base_p1_copies: Option<InternalPathCopies>,
496 base_p1_copies: Option<InternalPathCopies>,
482 base_p2_copies: Option<InternalPathCopies>,
497 base_p2_copies: Option<InternalPathCopies>,
483 changes: &ChangedFiles,
498 copy_actions: impl Iterator<Item = Action<'a>>,
484 current_rev: Revision,
499 current_rev: Revision,
485 ) -> (Option<InternalPathCopies>, Option<InternalPathCopies>) {
500 ) -> (Option<InternalPathCopies>, Option<InternalPathCopies>) {
486 // Fast path the "nothing to do" case.
501 // Fast path the "nothing to do" case.
@@ -490,7 +505,7 b' fn chain_changes('
490
505
491 let mut p1_copies = base_p1_copies.clone();
506 let mut p1_copies = base_p1_copies.clone();
492 let mut p2_copies = base_p2_copies.clone();
507 let mut p2_copies = base_p2_copies.clone();
493 for action in changes.iter_actions() {
508 for action in copy_actions {
494 match action {
509 match action {
495 Action::CopiedFromP1(path_dest, path_source) => {
510 Action::CopiedFromP1(path_dest, path_source) => {
496 match &mut p1_copies {
511 match &mut p1_copies {
@@ -613,16 +628,14 b' fn merge_copies_dict('
613 current_merge: Revision,
628 current_merge: Revision,
614 minor: InternalPathCopies,
629 minor: InternalPathCopies,
615 major: InternalPathCopies,
630 major: InternalPathCopies,
616 changes: &ChangedFiles,
631 get_merge_case: impl Fn(&HgPath) -> MergeCase + Copy,
617 ) -> InternalPathCopies {
632 ) -> InternalPathCopies {
618 use crate::utils::{ordmap_union_with_merge, MergeResult};
633 use crate::utils::{ordmap_union_with_merge, MergeResult};
619
634
620 ordmap_union_with_merge(minor, major, |&dest, src_minor, src_major| {
635 ordmap_union_with_merge(minor, major, |&dest, src_minor, src_major| {
621 let (pick, overwrite) = compare_value(
636 let (pick, overwrite) = compare_value(
622 path_map,
623 current_merge,
637 current_merge,
624 changes,
638 || get_merge_case(path_map.untokenize(dest)),
625 dest,
626 src_minor,
639 src_minor,
627 src_major,
640 src_major,
628 );
641 );
@@ -649,6 +662,7 b' fn merge_copies_dict('
649
662
650 /// represent the side that should prevail when merging two
663 /// represent the side that should prevail when merging two
651 /// InternalPathCopies
664 /// InternalPathCopies
665 #[derive(Debug, PartialEq)]
652 enum MergePick {
666 enum MergePick {
653 /// The "major" (p1) side prevails
667 /// The "major" (p1) side prevails
654 Major,
668 Major,
@@ -661,10 +675,8 b' enum MergePick {'
661 /// decide which side prevails in case of conflicting values
675 /// decide which side prevails in case of conflicting values
662 #[allow(clippy::if_same_then_else)]
676 #[allow(clippy::if_same_then_else)]
663 fn compare_value(
677 fn compare_value(
664 path_map: &TwoWayPathMap,
665 current_merge: Revision,
678 current_merge: Revision,
666 changes: &ChangedFiles,
679 merge_case_for_dest: impl Fn() -> MergeCase,
667 dest: PathToken,
668 src_minor: &CopySource,
680 src_minor: &CopySource,
669 src_major: &CopySource,
681 src_major: &CopySource,
670 ) -> (MergePick, bool) {
682 ) -> (MergePick, bool) {
@@ -693,8 +705,7 b' fn compare_value('
693 }
705 }
694 } else {
706 } else {
695 debug_assert!(src_major.rev != src_major.rev);
707 debug_assert!(src_major.rev != src_major.rev);
696 let dest_path = path_map.untokenize(dest);
708 let action = merge_case_for_dest();
697 let action = changes.get_merge_case(dest_path);
698 if src_minor.path.is_some()
709 if src_minor.path.is_some()
699 && src_major.path.is_none()
710 && src_major.path.is_none()
700 && action == MergeCase::Salvaged
711 && action == MergeCase::Salvaged
General Comments 0
You need to be logged in to leave comments. Login now