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>

Jayati Shrivastava committed Mar 16, 2022 at 11:20 UTC 5327d8982a467c0043d2900d2afcfc21ef14820e
1 file changed +4 -6
sequencer.c
+4 -6
@@ -3753,7 +3753,7 @@ static int do_merge(struct repository *r,
3753 int run_commit_flags = 0;
3754 struct strbuf ref_name = STRBUF_INIT;
3755 struct commit *head_commit, *merge_commit, *i;
3756 - struct commit_list *bases, *j, *reversed = NULL;
3756 + struct commit_list *bases, *j;
3757 struct commit_list *to_merge = NULL, **tail = &to_merge;
3758 const char *strategy = !opts->xopts_nr &&
3759 (!opts->strategy ||
@@ -3988,9 +3988,7 @@ static int do_merge(struct repository *r,
3988 git_path_merge_head(r), 0);
3989 write_message("no-ff", 5, git_path_merge_mode(r), 0);
3990
3991 - for (j = bases; j; j = j->next)
3992 - commit_list_insert(j->item, &reversed);
3993 - free_commit_list(bases);
3991 + bases = reverse_commit_list(bases);
3992
3993 repo_read_index(r);
3994 init_merge_options(&o, r);
@@ -4006,10 +4004,10 @@ static int do_merge(struct repository *r,
4004 * update the index and working copy immediately.
4005 */
4006 ret = merge_ort_recursive(&o,
4009 - head_commit, merge_commit, reversed,
4007 + head_commit, merge_commit, bases,
4008 &i);
4009 } else {
4012 - ret = merge_recursive(&o, head_commit, merge_commit, reversed,
4010 + ret = merge_recursive(&o, head_commit, merge_commit, bases,
4011 &i);
4012 }
4013 if (ret <= 0)