[PATCH 04/11] merge-ort: implement compare_pairs() and collect_renames()
From: Elijah Newren <newren@gmail.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
merge-ort.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/merge-ort.c b/merge-ort.c
index 1ff637e57af..3cdf8124b85 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -625,7 +625,13 @@ static int process_renames(struct merge_options *opt,
static int compare_pairs(const void *a_, const void *b_)
{
- die("Not yet implemented.");
+ const struct diff_filepair *a = *((const struct diff_filepair **)a_);
+ const struct diff_filepair *b = *((const struct diff_filepair **)b_);
+
+ int cmp = strcmp(a->one->path, b->one->path);
+ if (cmp)
+ return cmp;
+ return a->score - b->score;
}
/* Call diffcore_rename() to compute which files have changed on given side */
@@ -671,7 +677,24 @@ static int collect_renames(struct merge_options *opt,
struct diff_queue_struct *result,
unsigned side_index)
{
- die("Not yet implemented.");
+ int i, clean = 1;
+ struct diff_queue_struct *side_pairs;
+ struct rename_info *renames = opt->priv->renames;
+
+ side_pairs = &renames->pairs[side_index];
+
+ for (i = 0; i < side_pairs->nr; ++i) {
+ struct diff_filepair *p = side_pairs->queue[i];
+
+ if (p->status != 'R') {
+ diff_free_filepair(p);
+ continue;
+ }
+ p->score = side_index;
+ result->queue[result->nr++] = p;
+ }
+
+ return clean;
}
static int detect_and_process_renames(struct merge_options *opt,
--
gitgitgadget