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
Apr 19, 2018 at 10:57 UTC
9ba915577ff8bd0ef4677d7d6b5de857be52a108
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,
@@ -1390,6 +1321,76 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
1321
return ret;
1322
}
1323
1324
+/*
1325
+ * Get information of all renames which occurred between 'o_tree' and
1326
+ * 'tree'. We need the three trees in the merge ('o_tree', 'a_tree' and
1327
+ * 'b_tree') to be able to associate the correct cache entries with
1328
+ * the rename information. 'tree' is always equal to either a_tree or b_tree.
1329
+ */
1330
+static struct string_list *get_renames(struct merge_options *o,
1331
+ struct tree *tree,
1332
+ struct tree *o_tree,
1333
+ struct tree *a_tree,
1334
+ struct tree *b_tree,
1335
+ struct string_list *entries)
1336
+{
1337
+ int i;
1338
+ struct string_list *renames;
1339
+ struct diff_options opts;
1340
+
1341
+ renames = xcalloc(1, sizeof(struct string_list));
1342
+ if (!o->detect_rename)
1343
+ return renames;
1344
+
1345
+ diff_setup(&opts);
1346
+ opts.flags.recursive = 1;
1347
+ opts.flags.rename_empty = 0;
1348
+ opts.detect_rename = DIFF_DETECT_RENAME;
1349
+ opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit :
1350
+ o->diff_rename_limit >= 0 ? o->diff_rename_limit :
1351
+ 1000;
1352
+ opts.rename_score = o->rename_score;
1353
+ opts.show_rename_progress = o->show_rename_progress;
1354
+ opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1355
+ diff_setup_done(&opts);
1356
+ diff_tree_oid(&o_tree->object.oid, &tree->object.oid, "", &opts);
1357
+ diffcore_std(&opts);
1358
+ if (opts.needed_rename_limit > o->needed_rename_limit)
1359
+ o->needed_rename_limit = opts.needed_rename_limit;
1360
+ for (i = 0; i < diff_queued_diff.nr; ++i) {
1361
+ struct string_list_item *item;
1362
+ struct rename *re;
1363
+ struct diff_filepair *pair = diff_queued_diff.queue[i];
1364
+
1365
+ if (pair->status != 'R') {
1366
+ diff_free_filepair(pair);
1367
+ continue;
1368
+ }
1369
+ re = xmalloc(sizeof(*re));
1370
+ re->processed = 0;
1371
+ re->pair = pair;
1372
+ item = string_list_lookup(entries, re->pair->one->path);
1373
+ if (!item)
1374
+ re->src_entry = insert_stage_data(re->pair->one->path,
1375
+ o_tree, a_tree, b_tree, entries);
1376
+ else
1377
+ re->src_entry = item->util;
1378
+
1379
+ item = string_list_lookup(entries, re->pair->two->path);
1380
+ if (!item)
1381
+ re->dst_entry = insert_stage_data(re->pair->two->path,
1382
+ o_tree, a_tree, b_tree, entries);
1383
+ else
1384
+ re->dst_entry = item->util;
1385
+ item = string_list_insert(renames, pair->one->path);
1386
+ item->util = re;
1387
+ }
1388
+ opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1389
+ diff_queued_diff.nr = 0;
1390
+ diff_flush(&opts);
1391
+ return renames;
1392
+}
1393
+
1394
static int process_renames(struct merge_options *o,
1395
struct string_list *a_renames,
1396
struct string_list *b_renames)