merge-ort: implement compare_pairs() and collect_renames()
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
965a7bc21c6bb11fb15eb798fd472ec9deb5e3fa
1 file changed
+33
-2
merge-ort.c
+33
-2
@@ -652,7 +652,10 @@ static int process_renames(struct merge_options *opt,
652
653
static int compare_pairs(const void *a_, const void *b_)
654
{
655
- die("Not yet implemented.");
655
+ const struct diff_filepair *a = *((const struct diff_filepair **)a_);
656
+ const struct diff_filepair *b = *((const struct diff_filepair **)b_);
657
+
658
+ return strcmp(a->one->path, b->one->path);
659
}
660
661
/* Call diffcore_rename() to compute which files have changed on given side */
@@ -698,7 +701,35 @@ static int collect_renames(struct merge_options *opt,
701
struct diff_queue_struct *result,
702
unsigned side_index)
703
{
701
- die("Not yet implemented.");
704
+ int i, clean = 1;
705
+ struct diff_queue_struct *side_pairs;
706
+ struct rename_info *renames = &opt->priv->renames;
707
+
708
+ side_pairs = &renames->pairs[side_index];
709
+
710
+ for (i = 0; i < side_pairs->nr; ++i) {
711
+ struct diff_filepair *p = side_pairs->queue[i];
712
+
713
+ if (p->status != 'R') {
714
+ diff_free_filepair(p);
715
+ continue;
716
+ }
717
+
718
+ /*
719
+ * p->score comes back from diffcore_rename_extended() with
720
+ * the similarity of the renamed file. The similarity is
721
+ * was used to determine that the two files were related
722
+ * and are a rename, which we have already used, but beyond
723
+ * that we have no use for the similarity. So p->score is
724
+ * now irrelevant. However, process_renames() will need to
725
+ * know which side of the merge this rename was associated
726
+ * with, so overwrite p->score with that value.
727
+ */
728
+ p->score = side_index;
729
+ result->queue[result->nr++] = p;
730
+ }
731
+
732
+ return clean;
733
}
734
735
static int detect_and_process_renames(struct merge_options *opt,