diff options
author | Jayati Shrivastava <gaurijove@gmail.com> | 2022-03-16 11:20:23 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-03-16 15:39:16 (GMT) |
commit | 5327d8982a467c0043d2900d2afcfc21ef14820e (patch) | |
tree | 89d341968461b0aee96e0b80956de1bbe0768ed0 /sequencer.c | |
parent | 4c53a8c20f8984adb226293a3ffd7b88c3f4ac1a (diff) | |
download | git-5327d8982a467c0043d2900d2afcfc21ef14820e.zip git-5327d8982a467c0043d2900d2afcfc21ef14820e.tar.gz git-5327d8982a467c0043d2900d2afcfc21ef14820e.tar.bz2 |
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>
Diffstat (limited to 'sequencer.c')
-rw-r--r-- | sequencer.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/sequencer.c b/sequencer.c index 5213d16..80bfab8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -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) |