commit: move reverse_commit_list() from merge-recursive

Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Dec 16, 2020 at 22:27 UTC b0ca120554be8d8f7faf98aa3b991441de76f5cf
3 files changed +14 -11
commit.c
+11
@@ -563,6 +563,17 @@ struct commit_list *copy_commit_list(struct commit_list *list)
563 return head;
564 }
565
566 +struct commit_list *reverse_commit_list(struct commit_list *list)
567 +{
568 + struct commit_list *next = NULL, *current, *backup;
569 + for (current = list; current; current = backup) {
570 + backup = current->next;
571 + current->next = next;
572 + next = current;
573 + }
574 + return next;
575 +}
576 +
577 void free_commit_list(struct commit_list *list)
578 {
579 while (list)
commit.h
+3
@@ -177,6 +177,9 @@ void commit_list_sort_by_date(struct commit_list **list);
177 /* Shallow copy of the input list */
178 struct commit_list *copy_commit_list(struct commit_list *list);
179
180 +/* Modify list in-place to reverse it, returning new head; list will be tail */
181 +struct commit_list *reverse_commit_list(struct commit_list *list);
182 +
183 void free_commit_list(struct commit_list *list);
184
185 struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
merge-recursive.c
-11
@@ -3517,17 +3517,6 @@ static int merge_trees_internal(struct merge_options *opt,
3517 return clean;
3518 }
3519
3520 -static struct commit_list *reverse_commit_list(struct commit_list *list)
3521 -{
3522 - struct commit_list *next = NULL, *current, *backup;
3523 - for (current = list; current; current = backup) {
3524 - backup = current->next;
3525 - current->next = next;
3526 - next = current;
3527 - }
3528 - return next;
3529 -}
3530 -
3520 /*
3521 * Merge the commits h1 and h2, returning a flag (int) indicating the
3522 * cleanness of the merge. Also, if opt->priv->call_depth, create a