sequencer: export commit_list_append()

This function can be used in other parts of git. Give it a new home in commit.c. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Apr 25, 2012 at 22:35 UTC 89b5f1d9c5e64c9e232fa1ebe0ea407c8773b79a
3 files changed +29 -27
commit.c
+27
@@ -1214,3 +1214,30 @@ struct commit *get_merge_parent(const char *name)
1214 }
1215 return commit;
1216 }
1217 +
1218 +/*
1219 + * Append a commit to the end of the commit_list.
1220 + *
1221 + * next starts by pointing to the variable that holds the head of an
1222 + * empty commit_list, and is updated to point to the "next" field of
1223 + * the last item on the list as new commits are appended.
1224 + *
1225 + * Usage example:
1226 + *
1227 + * struct commit_list *list;
1228 + * struct commit_list **next = &list;
1229 + *
1230 + * next = commit_list_append(c1, next);
1231 + * next = commit_list_append(c2, next);
1232 + * assert(commit_list_count(list) == 2);
1233 + * return list;
1234 + */
1235 +struct commit_list **commit_list_append(struct commit *commit,
1236 + struct commit_list **next)
1237 +{
1238 + struct commit_list *new = xmalloc(sizeof(struct commit_list));
1239 + new->item = commit;
1240 + *next = new;
1241 + new->next = NULL;
1242 + return &new->next;
1243 +}
commit.h
+2
@@ -53,6 +53,8 @@ int find_commit_subject(const char *commit_buffer, const char **subject);
53
54 struct commit_list *commit_list_insert(struct commit *item,
55 struct commit_list **list);
56 +struct commit_list **commit_list_append(struct commit *commit,
57 + struct commit_list **next);
58 unsigned commit_list_count(const struct commit_list *l);
59 struct commit_list *commit_list_insert_by_date(struct commit *item,
60 struct commit_list **list);
sequencer.c
-27
@@ -468,33 +468,6 @@ static void read_and_refresh_cache(struct replay_opts *opts)
468 rollback_lock_file(&index_lock);
469 }
470
471 -/*
472 - * Append a commit to the end of the commit_list.
473 - *
474 - * next starts by pointing to the variable that holds the head of an
475 - * empty commit_list, and is updated to point to the "next" field of
476 - * the last item on the list as new commits are appended.
477 - *
478 - * Usage example:
479 - *
480 - * struct commit_list *list;
481 - * struct commit_list **next = &list;
482 - *
483 - * next = commit_list_append(c1, next);
484 - * next = commit_list_append(c2, next);
485 - * assert(commit_list_count(list) == 2);
486 - * return list;
487 - */
488 -static struct commit_list **commit_list_append(struct commit *commit,
489 - struct commit_list **next)
490 -{
491 - struct commit_list *new = xmalloc(sizeof(struct commit_list));
492 - new->item = commit;
493 - *next = new;
494 - new->next = NULL;
495 - return &new->next;
496 -}
497 -
471 static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
472 struct replay_opts *opts)
473 {