From e510ab898865fdaf131e9bc9fd6ab6b7c4a94c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 24 Oct 2015 18:21:31 +0200 Subject: use pop_commit() for consuming the first entry of a struct commit_list Instead of open-coding the function pop_commit() just call it. This makes the intent clearer and reduces code size. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- commit.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 6e2103cef6..1ab4ff220b 100644 --- a/commit.c +++ b/commit.c @@ -443,11 +443,8 @@ struct commit_list *copy_commit_list(struct commit_list *list) void free_commit_list(struct commit_list *list) { - while (list) { - struct commit_list *temp = list; - list = temp->next; - free(temp); - } + while (list) + pop_commit(&list); } struct commit_list * commit_list_insert_by_date(struct commit *item, struct commit_list **list) @@ -493,12 +490,8 @@ void commit_list_sort_by_date(struct commit_list **list) struct commit *pop_most_recent_commit(struct commit_list **list, unsigned int mark) { - struct commit *ret = (*list)->item; + struct commit *ret = pop_commit(list); struct commit_list *parents = ret->parents; - struct commit_list *old = *list; - - *list = (*list)->next; - free(old); while (parents) { struct commit *commit = parents->item; @@ -849,11 +842,9 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co list = paint_down_to_common(one, n, twos); while (list) { - struct commit_list *next = list->next; - if (!(list->item->object.flags & STALE)) - commit_list_insert_by_date(list->item, &result); - free(list); - list = next; + struct commit *commit = pop_commit(&list); + if (!(commit->object.flags & STALE)) + commit_list_insert_by_date(commit, &result); } return result; } @@ -1543,13 +1534,9 @@ int commit_tree_extended(const char *msg, size_t msg_len, * if everything else stays the same. */ while (parents) { - struct commit_list *next = parents->next; - struct commit *parent = parents->item; - + struct commit *parent = pop_commit(&parents); strbuf_addf(&buffer, "parent %s\n", sha1_to_hex(parent->object.sha1)); - free(parents); - parents = next; } /* Person/date information */ -- cgit v1.2.3