[PATCH 08/10] Introduce commit_list_append() in commit.c
- From
Miklos Vajna <vmiklos@frugalware.org>
- Date
- Jun 5, 2008, 20:44 UTC
- Message-ID
- <cbafb7e632b176658fe84e1eb9926f0a8d3c96b4.1212698317.git.vmiklos@frugalware.org>
- In-Reply-To
- <2e4b20178405cf993ce9e0f1ffe4ac402a96fd03.1212698317.git.vmiklos@frugalware.org>
This is like commit_list_insert() but it appends the new commit to the end of the list, rather than insert to the start of it.
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> --- commit.c | 19 +++++++++++++++++++ commit.h | 1 + 2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/commit.c b/commit.c index b45ec9b..6ba5acb 100644 --- a/commit.c +++ b/commit.c @@ -331,6 +331,25 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list * return new_list; } +struct commit_list *commit_list_append(struct commit *item, + struct commit_list **list_p) +{ + struct commit_list *i, *prev = NULL, *list = *list_p; + struct commit_list *new_list = xmalloc(sizeof(struct commit_list)); + + new_list->item = item; + new_list->next = NULL; + + if (!list) + *list_p = new_list; + else { + for (i = list; i; i = i->next) + prev = i; + prev->next = new_list; + } + return list; +} + unsigned commit_list_count(const struct commit_list *l) { unsigned c = 0; diff --git a/commit.h b/commit.h index 7f8c5ee..5d9ac43 100644 --- a/commit.h +++ b/commit.h @@ -41,6 +41,7 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size); int parse_commit(struct commit *item); struct commit_list * commit_list_insert(struct commit *item, struct commit_list **list_p); +struct commit_list *commit_list_append(struct commit *item, struct commit_list **list_p); unsigned commit_list_count(const struct commit_list *l); struct commit_list * insert_by_date(struct commit *item, struct commit_list **list);
-- 1.5.6.rc0.dirty