Skip to content

Commit 5327d89

Browse files
victorphoenix3gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c53a8c commit 5327d89

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

sequencer.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,7 +3753,7 @@ static int do_merge(struct repository *r,
37533753
int run_commit_flags = 0;
37543754
struct strbuf ref_name = STRBUF_INIT;
37553755
struct commit *head_commit, *merge_commit, *i;
3756-
struct commit_list *bases, *j, *reversed = NULL;
3756+
struct commit_list *bases, *j;
37573757
struct commit_list *to_merge = NULL, **tail = &to_merge;
37583758
const char *strategy = !opts->xopts_nr &&
37593759
(!opts->strategy ||
@@ -3988,9 +3988,7 @@ static int do_merge(struct repository *r,
39883988
git_path_merge_head(r), 0);
39893989
write_message("no-ff", 5, git_path_merge_mode(r), 0);
39903990

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);
39943992

39953993
repo_read_index(r);
39963994
init_merge_options(&o, r);
@@ -4006,10 +4004,10 @@ static int do_merge(struct repository *r,
40064004
* update the index and working copy immediately.
40074005
*/
40084006
ret = merge_ort_recursive(&o,
4009-
head_commit, merge_commit, reversed,
4007+
head_commit, merge_commit, bases,
40104008
&i);
40114009
} else {
4012-
ret = merge_recursive(&o, head_commit, merge_commit, reversed,
4010+
ret = merge_recursive(&o, head_commit, merge_commit, bases,
40134011
&i);
40144012
}
40154013
if (ret <= 0)

0 commit comments

Comments
 (0)