merge-recursive: make !o->detect_rename codepath more obvious
authorElijah Newren <newren@gmail.com>
Wed, 14 Feb 2018 18:51:52 +0000 (10:51 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Feb 2018 21:02:52 +0000 (13:02 -0800)
Previously, if !o->detect_rename then get_renames() would return an
empty string_list, and then process_renames() would have nothing to
iterate over. It seems more straightforward to simply avoid calling
either function in that case.

Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-recursive.c
index c24b8f3de4c3b28667694086359a01bbaf2bc5a9..15b2a2b9c8c210be0524cf326b81387aa88acd13 100644 (file)
@@ -1329,8 +1329,6 @@ static struct string_list *get_renames(struct merge_options *o,
        struct diff_options opts;
 
        renames = xcalloc(1, sizeof(struct string_list));
-       if (!o->detect_rename)
-               return renames;
 
        diff_setup(&opts);
        opts.flags.recursive = 1;
@@ -1648,6 +1646,12 @@ static int handle_renames(struct merge_options *o,
                          struct string_list *entries,
                          struct rename_info *ri)
 {
+       ri->head_renames = NULL;
+       ri->merge_renames = NULL;
+
+       if (!o->detect_rename)
+               return 1;
+
        ri->head_renames  = get_renames(o, head, common, head, merge, entries);
        ri->merge_renames = get_renames(o, merge, common, head, merge, entries);
        return process_renames(o, ri->head_renames, ri->merge_renames);
@@ -1658,6 +1662,9 @@ static void cleanup_rename(struct string_list *rename)
        const struct rename *re;
        int i;
 
+       if (rename == NULL)
+               return;
+
        for (i = 0; i < rename->nr; i++) {
                re = rename->items[i].util;
                diff_free_filepair(re->pair);