merge-ort: add initial outline for basic rename detection

Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Dec 14, 2020 at 16:21 UTC e1a124e8dc3d21afedc80cc2842d705c1d5a90c9
1 file changed +60 -8
merge-ort.c
+60 -8
@@ -644,20 +644,72 @@ static int handle_content_merge(struct merge_options *opt,
644
645 /*** Function Grouping: functions related to regular rename detection ***/
646
647 +static int process_renames(struct merge_options *opt,
648 + struct diff_queue_struct *renames)
649 +{
650 + die("Not yet implemented.");
651 +}
652 +
653 +static int compare_pairs(const void *a_, const void *b_)
654 +{
655 + die("Not yet implemented.");
656 +}
657 +
658 +/* Call diffcore_rename() to compute which files have changed on given side */
659 +static void detect_regular_renames(struct merge_options *opt,
660 + struct tree *merge_base,
661 + struct tree *side,
662 + unsigned side_index)
663 +{
664 + die("Not yet implemented.");
665 +}
666 +
667 +/*
668 + * Get information of all renames which occurred in 'side_pairs', discarding
669 + * non-renames.
670 + */
671 +static int collect_renames(struct merge_options *opt,
672 + struct diff_queue_struct *result,
673 + unsigned side_index)
674 +{
675 + die("Not yet implemented.");
676 +}
677 +
678 static int detect_and_process_renames(struct merge_options *opt,
679 struct tree *merge_base,
680 struct tree *side1,
681 struct tree *side2)
682 {
652 - int clean = 1;
683 + struct diff_queue_struct combined;
684 + struct rename_info *renames = &opt->priv->renames;
685 + int s, clean = 1;
686 +
687 + memset(&combined, 0, sizeof(combined));
688 +
689 + detect_regular_renames(opt, merge_base, side1, MERGE_SIDE1);
690 + detect_regular_renames(opt, merge_base, side2, MERGE_SIDE2);
691 +
692 + ALLOC_GROW(combined.queue,
693 + renames->pairs[1].nr + renames->pairs[2].nr,
694 + combined.alloc);
695 + clean &= collect_renames(opt, &combined, MERGE_SIDE1);
696 + clean &= collect_renames(opt, &combined, MERGE_SIDE2);
697 + QSORT(combined.queue, combined.nr, compare_pairs);
698 +
699 + clean &= process_renames(opt, &combined);
700 +
701 + /* Free memory for renames->pairs[] and combined */
702 + for (s = MERGE_SIDE1; s <= MERGE_SIDE2; s++) {
703 + free(renames->pairs[s].queue);
704 + DIFF_QUEUE_CLEAR(&renames->pairs[s]);
705 + }
706 + if (combined.nr) {
707 + int i;
708 + for (i = 0; i < combined.nr; i++)
709 + diff_free_filepair(combined.queue[i]);
710 + free(combined.queue);
711 + }
712
654 - /*
655 - * Rename detection works by detecting file similarity. Here we use
656 - * a really easy-to-implement scheme: files are similar IFF they have
657 - * the same filename. Therefore, by this scheme, there are no renames.
658 - *
659 - * TODO: Actually implement a real rename detection scheme.
660 - */
713 return clean;
714 }
715