merge-recursive: move the get_renames() function
Move this function so it can re-use some others (without either moving all of them or adding an annoying split between function declarations and definitions). Cheat slightly by adding a blank line for readability, and in order to silence checkpatch.pl. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Feb 14, 2018 at 10:51 UTC
a706e8f6fc19c5f94108fd2253993b7e4e9b34d8
1 file changed
+70
-69
merge-recursive.c
+70
-69
@@ -537,75 +537,6 @@ struct rename {
537
unsigned processed:1;
538
};
539
540
-/*
541
- * Get information of all renames which occurred between 'o_tree' and
542
- * 'tree'. We need the three trees in the merge ('o_tree', 'a_tree' and
543
- * 'b_tree') to be able to associate the correct cache entries with
544
- * the rename information. 'tree' is always equal to either a_tree or b_tree.
545
- */
546
-static struct string_list *get_renames(struct merge_options *o,
547
- struct tree *tree,
548
- struct tree *o_tree,
549
- struct tree *a_tree,
550
- struct tree *b_tree,
551
- struct string_list *entries)
552
-{
553
- int i;
554
- struct string_list *renames;
555
- struct diff_options opts;
556
-
557
- renames = xcalloc(1, sizeof(struct string_list));
558
- if (!o->detect_rename)
559
- return renames;
560
-
561
- diff_setup(&opts);
562
- opts.flags.recursive = 1;
563
- opts.flags.rename_empty = 0;
564
- opts.detect_rename = DIFF_DETECT_RENAME;
565
- opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit :
566
- o->diff_rename_limit >= 0 ? o->diff_rename_limit :
567
- 1000;
568
- opts.rename_score = o->rename_score;
569
- opts.show_rename_progress = o->show_rename_progress;
570
- opts.output_format = DIFF_FORMAT_NO_OUTPUT;
571
- diff_setup_done(&opts);
572
- diff_tree_oid(&o_tree->object.oid, &tree->object.oid, "", &opts);
573
- diffcore_std(&opts);
574
- if (opts.needed_rename_limit > o->needed_rename_limit)
575
- o->needed_rename_limit = opts.needed_rename_limit;
576
- for (i = 0; i < diff_queued_diff.nr; ++i) {
577
- struct string_list_item *item;
578
- struct rename *re;
579
- struct diff_filepair *pair = diff_queued_diff.queue[i];
580
- if (pair->status != 'R') {
581
- diff_free_filepair(pair);
582
- continue;
583
- }
584
- re = xmalloc(sizeof(*re));
585
- re->processed = 0;
586
- re->pair = pair;
587
- item = string_list_lookup(entries, re->pair->one->path);
588
- if (!item)
589
- re->src_entry = insert_stage_data(re->pair->one->path,
590
- o_tree, a_tree, b_tree, entries);
591
- else
592
- re->src_entry = item->util;
593
-
594
- item = string_list_lookup(entries, re->pair->two->path);
595
- if (!item)
596
- re->dst_entry = insert_stage_data(re->pair->two->path,
597
- o_tree, a_tree, b_tree, entries);
598
- else
599
- re->dst_entry = item->util;
600
- item = string_list_insert(renames, pair->one->path);
601
- item->util = re;
602
- }
603
- opts.output_format = DIFF_FORMAT_NO_OUTPUT;
604
- diff_queued_diff.nr = 0;
605
- diff_flush(&opts);
606
- return renames;
607
-}
608
-
540
static int update_stages(struct merge_options *opt, const char *path,
541
const struct diff_filespec *o,
542
const struct diff_filespec *a,
@@ -1380,6 +1311,76 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
1311
return ret;
1312
}
1313
1314
+/*
1315
+ * Get information of all renames which occurred between 'o_tree' and
1316
+ * 'tree'. We need the three trees in the merge ('o_tree', 'a_tree' and
1317
+ * 'b_tree') to be able to associate the correct cache entries with
1318
+ * the rename information. 'tree' is always equal to either a_tree or b_tree.
1319
+ */
1320
+static struct string_list *get_renames(struct merge_options *o,
1321
+ struct tree *tree,
1322
+ struct tree *o_tree,
1323
+ struct tree *a_tree,
1324
+ struct tree *b_tree,
1325
+ struct string_list *entries)
1326
+{
1327
+ int i;
1328
+ struct string_list *renames;
1329
+ struct diff_options opts;
1330
+
1331
+ renames = xcalloc(1, sizeof(struct string_list));
1332
+ if (!o->detect_rename)
1333
+ return renames;
1334
+
1335
+ diff_setup(&opts);
1336
+ opts.flags.recursive = 1;
1337
+ opts.flags.rename_empty = 0;
1338
+ opts.detect_rename = DIFF_DETECT_RENAME;
1339
+ opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit :
1340
+ o->diff_rename_limit >= 0 ? o->diff_rename_limit :
1341
+ 1000;
1342
+ opts.rename_score = o->rename_score;
1343
+ opts.show_rename_progress = o->show_rename_progress;
1344
+ opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1345
+ diff_setup_done(&opts);
1346
+ diff_tree_oid(&o_tree->object.oid, &tree->object.oid, "", &opts);
1347
+ diffcore_std(&opts);
1348
+ if (opts.needed_rename_limit > o->needed_rename_limit)
1349
+ o->needed_rename_limit = opts.needed_rename_limit;
1350
+ for (i = 0; i < diff_queued_diff.nr; ++i) {
1351
+ struct string_list_item *item;
1352
+ struct rename *re;
1353
+ struct diff_filepair *pair = diff_queued_diff.queue[i];
1354
+
1355
+ if (pair->status != 'R') {
1356
+ diff_free_filepair(pair);
1357
+ continue;
1358
+ }
1359
+ re = xmalloc(sizeof(*re));
1360
+ re->processed = 0;
1361
+ re->pair = pair;
1362
+ item = string_list_lookup(entries, re->pair->one->path);
1363
+ if (!item)
1364
+ re->src_entry = insert_stage_data(re->pair->one->path,
1365
+ o_tree, a_tree, b_tree, entries);
1366
+ else
1367
+ re->src_entry = item->util;
1368
+
1369
+ item = string_list_lookup(entries, re->pair->two->path);
1370
+ if (!item)
1371
+ re->dst_entry = insert_stage_data(re->pair->two->path,
1372
+ o_tree, a_tree, b_tree, entries);
1373
+ else
1374
+ re->dst_entry = item->util;
1375
+ item = string_list_insert(renames, pair->one->path);
1376
+ item->util = re;
1377
+ }
1378
+ opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1379
+ diff_queued_diff.nr = 0;
1380
+ diff_flush(&opts);
1381
+ return renames;
1382
+}
1383
+
1384
static int process_renames(struct merge_options *o,
1385
struct string_list *a_renames,
1386
struct string_list *b_renames)