1
0
mirror of https://github.com/git/git synced 2024-07-07 19:39:27 +00:00

sequencer: use reverse_commit_list() helper

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>
This commit is contained in:
Jayati Shrivastava 2022-03-16 11:20:23 +00:00 committed by Junio C Hamano
parent 4c53a8c20f
commit 5327d8982a

View 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)