Skip to content

Commit 965a7bc

Browse files
newrengitster
authored andcommitted
merge-ort: implement compare_pairs() and collect_renames()
Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f39d05c commit 965a7bc

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

merge-ort.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,10 @@ static int process_renames(struct merge_options *opt,
652652

653653
static int compare_pairs(const void *a_, const void *b_)
654654
{
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);
656659
}
657660

658661
/* Call diffcore_rename() to compute which files have changed on given side */
@@ -698,7 +701,35 @@ static int collect_renames(struct merge_options *opt,
698701
struct diff_queue_struct *result,
699702
unsigned side_index)
700703
{
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;
702733
}
703734

704735
static int detect_and_process_renames(struct merge_options *opt,

0 commit comments

Comments
 (0)