]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: use reverse_commit_list() helper
authorJayati Shrivastava <gaurijove@gmail.com>
Wed, 16 Mar 2022 11:20:23 +0000 (11:20 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Mar 2022 15:39:16 +0000 (08:39 -0700)
Instead of creating a new allocation, reverse the original list
in-place by calling the reverse_commit_list() helper.

The original code discards the list "bases" after storing its
reverse copy in a newly created list "reversed".  If the code that
followed from here used both "bases" and "reversed", the
modification would not have worked, but since the original list
"bases" gets discarded, we can simply reverse "bases" in-place with
the reverse_commit_list() helper and reuse the same variable in the
code that follows.

builtin/merge.c has been left unmodified, since in its case, the
original list is needed separately from its reverse copy by the
code.

Signed-off-by: Jayati Shrivastava <gaurijove@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c

index 5213d16e97174adbf10fc487edb0f3d3a726f7d7..80bfab83ea480854961556a12dc1a5d873d2ba86 100644 (file)
@@ -3753,7 +3753,7 @@ static int do_merge(struct repository *r,
        int run_commit_flags = 0;
        struct strbuf ref_name = STRBUF_INIT;
        struct commit *head_commit, *merge_commit, *i;
-       struct commit_list *bases, *j, *reversed = NULL;
+       struct commit_list *bases, *j;
        struct commit_list *to_merge = NULL, **tail = &to_merge;
        const char *strategy = !opts->xopts_nr &&
                (!opts->strategy ||
@@ -3988,9 +3988,7 @@ static int do_merge(struct repository *r,
                      git_path_merge_head(r), 0);
        write_message("no-ff", 5, git_path_merge_mode(r), 0);
 
-       for (j = bases; j; j = j->next)
-               commit_list_insert(j->item, &reversed);
-       free_commit_list(bases);
+       bases = reverse_commit_list(bases);
 
        repo_read_index(r);
        init_merge_options(&o, r);
@@ -4006,10 +4004,10 @@ static int do_merge(struct repository *r,
                 * update the index and working copy immediately.
                 */
                ret = merge_ort_recursive(&o,
-                                         head_commit, merge_commit, reversed,
+                                         head_commit, merge_commit, bases,
                                          &i);
        } else {
-               ret = merge_recursive(&o, head_commit, merge_commit, reversed,
+               ret = merge_recursive(&o, head_commit, merge_commit, bases,
                                      &i);
        }
        if (ret <= 0)