566 oracle: &mut AncestorOracle<A>, |
566 oracle: &mut AncestorOracle<A>, |
567 ) -> TimeStampedPathCopies { |
567 ) -> TimeStampedPathCopies { |
568 // This closure exist as temporary help while multiple developper are |
568 // This closure exist as temporary help while multiple developper are |
569 // actively working on this code. Feel free to re-inline it once this |
569 // actively working on this code. Feel free to re-inline it once this |
570 // code is more settled. |
570 // code is more settled. |
571 let mut cmp_value = |
571 let cmp_value = |oracle: &mut AncestorOracle<A>, |
572 |dest: &PathToken, |
572 dest: &PathToken, |
573 src_minor: &TimeStampedPathCopy, |
573 src_minor: &TimeStampedPathCopy, |
574 src_major: &TimeStampedPathCopy| { |
574 src_major: &TimeStampedPathCopy| { |
575 compare_value( |
575 compare_value( |
576 path_map, |
576 path_map, |
577 current_merge, |
577 current_merge, |
578 changes, |
578 changes, |
579 oracle, |
579 oracle, |
580 dest, |
580 dest, |
581 src_minor, |
581 src_minor, |
582 src_major, |
582 src_major, |
583 ) |
583 ) |
584 }; |
584 }; |
585 if minor.is_empty() { |
585 if minor.is_empty() { |
586 major |
586 major |
587 } else if major.is_empty() { |
587 } else if major.is_empty() { |
588 minor |
588 minor |
589 } else if minor.len() * 2 < major.len() { |
589 } else if minor.len() * 2 < major.len() { |
603 // This help performance a lot in case were a tiny |
603 // This help performance a lot in case were a tiny |
604 // TimeStampedPathCopies is merged with a much larger one. |
604 // TimeStampedPathCopies is merged with a much larger one. |
605 for (dest, src_minor) in minor { |
605 for (dest, src_minor) in minor { |
606 let src_major = major.get(&dest); |
606 let src_major = major.get(&dest); |
607 match src_major { |
607 match src_major { |
608 None => major.insert(dest, src_minor), |
608 None => { |
|
609 major.insert(dest, src_minor); |
|
610 } |
609 Some(src_major) => { |
611 Some(src_major) => { |
610 match cmp_value(&dest, &src_minor, src_major) { |
612 let (pick, overwrite) = |
611 MergePick::Any | MergePick::Major => None, |
613 cmp_value(oracle, &dest, &src_minor, src_major); |
612 MergePick::Minor => major.insert(dest, src_minor), |
614 if overwrite { |
|
615 oracle.record_overwrite(src_minor.rev, current_merge); |
|
616 oracle.record_overwrite(src_major.rev, current_merge); |
|
617 let path = match pick { |
|
618 MergePick::Major => src_major.path, |
|
619 MergePick::Minor => src_minor.path, |
|
620 MergePick::Any => src_major.path, |
|
621 }; |
|
622 let src = TimeStampedPathCopy { |
|
623 rev: current_merge, |
|
624 path, |
|
625 }; |
|
626 major.insert(dest, src); |
|
627 } else { |
|
628 match pick { |
|
629 MergePick::Any | MergePick::Major => None, |
|
630 MergePick::Minor => major.insert(dest, src_minor), |
|
631 }; |
613 } |
632 } |
614 } |
633 } |
615 }; |
634 }; |
616 } |
635 } |
617 major |
636 major |
619 // This use the same rational than the previous block. |
638 // This use the same rational than the previous block. |
620 // (Check previous block documentation for details.) |
639 // (Check previous block documentation for details.) |
621 for (dest, src_major) in major { |
640 for (dest, src_major) in major { |
622 let src_minor = minor.get(&dest); |
641 let src_minor = minor.get(&dest); |
623 match src_minor { |
642 match src_minor { |
624 None => minor.insert(dest, src_major), |
643 None => { |
|
644 minor.insert(dest, src_major); |
|
645 } |
625 Some(src_minor) => { |
646 Some(src_minor) => { |
626 match cmp_value(&dest, src_minor, &src_major) { |
647 let (pick, overwrite) = |
627 MergePick::Any | MergePick::Minor => None, |
648 cmp_value(oracle, &dest, &src_major, src_minor); |
628 MergePick::Major => minor.insert(dest, src_major), |
649 if overwrite { |
|
650 oracle.record_overwrite(src_minor.rev, current_merge); |
|
651 oracle.record_overwrite(src_major.rev, current_merge); |
|
652 let path = match pick { |
|
653 MergePick::Major => src_minor.path, |
|
654 MergePick::Minor => src_major.path, |
|
655 MergePick::Any => src_major.path, |
|
656 }; |
|
657 let src = TimeStampedPathCopy { |
|
658 rev: current_merge, |
|
659 path, |
|
660 }; |
|
661 minor.insert(dest, src); |
|
662 } else { |
|
663 match pick { |
|
664 MergePick::Any | MergePick::Major => None, |
|
665 MergePick::Minor => minor.insert(dest, src_major), |
|
666 }; |
629 } |
667 } |
630 } |
668 } |
631 }; |
669 }; |
632 } |
670 } |
633 minor |
671 minor |
661 DiffItem::Add(k, v) => to_minor(k, v), |
699 DiffItem::Add(k, v) => to_minor(k, v), |
662 DiffItem::Remove(k, v) => to_major(k, v), |
700 DiffItem::Remove(k, v) => to_major(k, v), |
663 DiffItem::Update { old, new } => { |
701 DiffItem::Update { old, new } => { |
664 let (dest, src_major) = new; |
702 let (dest, src_major) = new; |
665 let (_, src_minor) = old; |
703 let (_, src_minor) = old; |
666 match cmp_value(dest, src_minor, src_major) { |
704 let (pick, overwrite) = |
667 MergePick::Major => to_minor(dest, src_major), |
705 cmp_value(oracle, dest, src_minor, src_major); |
668 MergePick::Minor => to_major(dest, src_minor), |
706 if overwrite { |
669 // If the two entry are identical, no need to do |
707 oracle.record_overwrite(src_minor.rev, current_merge); |
670 // anything (but diff should not have yield them) |
708 oracle.record_overwrite(src_major.rev, current_merge); |
671 MergePick::Any => unreachable!(), |
709 let path = match pick { |
|
710 MergePick::Major => src_major.path, |
|
711 MergePick::Minor => src_minor.path, |
|
712 // If the two entry are identical, no need to do |
|
713 // anything (but diff should not have yield them) |
|
714 MergePick::Any => src_major.path, |
|
715 }; |
|
716 let src = TimeStampedPathCopy { |
|
717 rev: current_merge, |
|
718 path, |
|
719 }; |
|
720 to_minor(dest, &src); |
|
721 to_major(dest, &src); |
|
722 } else { |
|
723 match pick { |
|
724 MergePick::Major => to_minor(dest, src_major), |
|
725 MergePick::Minor => to_major(dest, src_minor), |
|
726 // If the two entry are identical, no need to do |
|
727 // anything (but diff should not have yield them) |
|
728 MergePick::Any => unreachable!(), |
|
729 } |
672 } |
730 } |
673 } |
731 } |
674 }; |
732 }; |
675 } |
733 } |
676 |
734 |
715 changes: &ChangedFiles, |
773 changes: &ChangedFiles, |
716 oracle: &mut AncestorOracle<A>, |
774 oracle: &mut AncestorOracle<A>, |
717 dest: &PathToken, |
775 dest: &PathToken, |
718 src_minor: &TimeStampedPathCopy, |
776 src_minor: &TimeStampedPathCopy, |
719 src_major: &TimeStampedPathCopy, |
777 src_major: &TimeStampedPathCopy, |
720 ) -> MergePick { |
778 ) -> (MergePick, bool) { |
721 if src_major.rev == current_merge { |
779 if src_major.rev == current_merge { |
722 if src_minor.rev == current_merge { |
780 if src_minor.rev == current_merge { |
723 if src_major.path.is_none() { |
781 if src_major.path.is_none() { |
724 // We cannot get different copy information for both p1 and p2 |
782 // We cannot get different copy information for both p1 and p2 |
725 // from the same revision. Unless this was a |
783 // from the same revision. Unless this was a |
726 // deletion |
784 // deletion |
727 MergePick::Any |
785 (MergePick::Any, false) |
728 } else { |
786 } else { |
729 unreachable!(); |
787 unreachable!(); |
730 } |
788 } |
731 } else { |
789 } else { |
732 // The last value comes the current merge, this value -will- win |
790 // The last value comes the current merge, this value -will- win |
733 // eventually. |
791 // eventually. |
734 oracle.record_overwrite(src_minor.rev, src_major.rev); |
792 (MergePick::Major, true) |
735 MergePick::Major |
|
736 } |
793 } |
737 } else if src_minor.rev == current_merge { |
794 } else if src_minor.rev == current_merge { |
738 // The last value comes the current merge, this value -will- win |
795 // The last value comes the current merge, this value -will- win |
739 // eventually. |
796 // eventually. |
740 oracle.record_overwrite(src_major.rev, src_minor.rev); |
797 (MergePick::Minor, true) |
741 MergePick::Minor |
|
742 } else if src_major.path == src_minor.path { |
798 } else if src_major.path == src_minor.path { |
743 // we have the same value, but from other source; |
799 // we have the same value, but from other source; |
744 if src_major.rev == src_minor.rev { |
800 if src_major.rev == src_minor.rev { |
745 // If the two entry are identical, they are both valid |
801 // If the two entry are identical, they are both valid |
746 MergePick::Any |
802 (MergePick::Any, false) |
747 } else if oracle.is_overwrite(src_major.rev, src_minor.rev) { |
803 } else if oracle.is_overwrite(src_major.rev, src_minor.rev) { |
748 MergePick::Minor |
804 (MergePick::Minor, false) |
749 } else if oracle.is_overwrite(src_minor.rev, src_major.rev) { |
805 } else if oracle.is_overwrite(src_minor.rev, src_major.rev) { |
750 MergePick::Major |
806 (MergePick::Major, false) |
751 } else { |
807 } else { |
752 MergePick::Major |
808 (MergePick::Any, true) |
753 } |
809 } |
754 } else if src_major.rev == src_minor.rev { |
810 } else if src_major.rev == src_minor.rev { |
755 // We cannot get copy information for both p1 and p2 in the |
811 // We cannot get copy information for both p1 and p2 in the |
756 // same rev. So this is the same value. |
812 // same rev. So this is the same value. |
757 unreachable!( |
813 unreachable!( |
764 && src_major.path.is_none() |
820 && src_major.path.is_none() |
765 && action == MergeCase::Salvaged |
821 && action == MergeCase::Salvaged |
766 { |
822 { |
767 // If the file is "deleted" in the major side but was |
823 // If the file is "deleted" in the major side but was |
768 // salvaged by the merge, we keep the minor side alive |
824 // salvaged by the merge, we keep the minor side alive |
769 MergePick::Minor |
825 (MergePick::Minor, true) |
770 } else if src_major.path.is_some() |
826 } else if src_major.path.is_some() |
771 && src_minor.path.is_none() |
827 && src_minor.path.is_none() |
772 && action == MergeCase::Salvaged |
828 && action == MergeCase::Salvaged |
773 { |
829 { |
774 // If the file is "deleted" in the minor side but was |
830 // If the file is "deleted" in the minor side but was |
775 // salvaged by the merge, unconditionnaly preserve the |
831 // salvaged by the merge, unconditionnaly preserve the |
776 // major side. |
832 // major side. |
777 MergePick::Major |
833 (MergePick::Major, true) |
778 } else if oracle.is_overwrite(src_minor.rev, src_major.rev) { |
834 } else if oracle.is_overwrite(src_minor.rev, src_major.rev) { |
779 // The information from the minor version are strictly older than |
835 // The information from the minor version are strictly older than |
780 // the major version |
836 // the major version |
781 if action == MergeCase::Merged { |
837 if action == MergeCase::Merged { |
782 // If the file was actively merged, its means some non-copy |
838 // If the file was actively merged, its means some non-copy |
783 // activity happened on the other branch. It |
839 // activity happened on the other branch. It |
784 // mean the older copy information are still relevant. |
840 // mean the older copy information are still relevant. |
785 // |
841 // |
786 // The major side wins such conflict. |
842 // The major side wins such conflict. |
787 MergePick::Major |
843 (MergePick::Major, true) |
788 } else { |
844 } else { |
789 // No activity on the minor branch, pick the newer one. |
845 // No activity on the minor branch, pick the newer one. |
790 MergePick::Major |
846 (MergePick::Major, false) |
791 } |
847 } |
792 } else if oracle.is_overwrite(src_major.rev, src_minor.rev) { |
848 } else if oracle.is_overwrite(src_major.rev, src_minor.rev) { |
793 if action == MergeCase::Merged { |
849 if action == MergeCase::Merged { |
794 // If the file was actively merged, its means some non-copy |
850 // If the file was actively merged, its means some non-copy |
795 // activity happened on the other branch. It |
851 // activity happened on the other branch. It |
796 // mean the older copy information are still relevant. |
852 // mean the older copy information are still relevant. |
797 // |
853 // |
798 // The major side wins such conflict. |
854 // The major side wins such conflict. |
799 MergePick::Major |
855 (MergePick::Major, true) |
800 } else { |
856 } else { |
801 // No activity on the minor branch, pick the newer one. |
857 // No activity on the minor branch, pick the newer one. |
802 MergePick::Minor |
858 (MergePick::Minor, false) |
803 } |
859 } |
804 } else if src_minor.path.is_none() { |
860 } else if src_minor.path.is_none() { |
805 // the minor side has no relevant information, pick the alive one |
861 // the minor side has no relevant information, pick the alive one |
806 MergePick::Major |
862 (MergePick::Major, true) |
807 } else if src_major.path.is_none() { |
863 } else if src_major.path.is_none() { |
808 // the major side has no relevant information, pick the alive one |
864 // the major side has no relevant information, pick the alive one |
809 MergePick::Minor |
865 (MergePick::Minor, true) |
810 } else { |
866 } else { |
811 // by default the major side wins |
867 // by default the major side wins |
812 MergePick::Major |
868 (MergePick::Major, true) |
813 } |
869 } |
814 } |
870 } |
815 } |
871 } |