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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 24, 2015 at 18:21 UTC e510ab898865fdaf131e9bc9fd6ab6b7c4a94c9b
10 files changed +31 -92
builtin/fmt-merge-msg.c
+3 -6
@@ -536,7 +536,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
536 static void find_merge_parents(struct merge_parents *result,
537 struct strbuf *in, unsigned char *head)
538 {
539 - struct commit_list *parents, *next;
539 + struct commit_list *parents;
540 struct commit *head_commit;
541 int pos = 0, i, j;
542
@@ -575,13 +575,10 @@ static void find_merge_parents(struct merge_parents *result,
575 parents = reduce_heads(parents);
576
577 while (parents) {
578 + struct commit *cmit = pop_commit(&parents);
579 for (i = 0; i < result->nr; i++)
579 - if (!hashcmp(result->item[i].commit,
580 - parents->item->object.sha1))
580 + if (!hashcmp(result->item[i].commit, cmit->object.sha1))
581 result->item[i].used = 1;
582 - next = parents->next;
583 - free(parents);
584 - parents = next;
582 }
583
584 for (i = j = 0; i < result->nr; i++) {
builtin/merge.c
+5 -7
@@ -1019,7 +1019,7 @@ static struct commit_list *reduce_parents(struct commit *head_commit,
1019 int *head_subsumed,
1020 struct commit_list *remoteheads)
1021 {
1022 - struct commit_list *parents, *next, **remotes = &remoteheads;
1022 + struct commit_list *parents, **remotes;
1023
1024 /*
1025 * Is the current HEAD reachable from another commit being
@@ -1033,16 +1033,14 @@ static struct commit_list *reduce_parents(struct commit *head_commit,
1033 /* Find what parents to record by checking independent ones. */
1034 parents = reduce_heads(remoteheads);
1035
1036 - for (remoteheads = NULL, remotes = &remoteheads;
1037 - parents;
1038 - parents = next) {
1039 - struct commit *commit = parents->item;
1040 - next = parents->next;
1036 + remoteheads = NULL;
1037 + remotes = &remoteheads;
1038 + while (parents) {
1039 + struct commit *commit = pop_commit(&parents);
1040 if (commit == head_commit)
1041 *head_subsumed = 0;
1042 else
1043 remotes = &commit_list_insert(commit, remotes)->next;
1045 - free(parents);
1044 }
1045 return remoteheads;
1046 }
builtin/reflog.c
+1 -5
@@ -216,7 +216,6 @@ static int keep_entry(struct commit **it, unsigned char *sha1)
216 */
217 static void mark_reachable(struct expire_reflog_policy_cb *cb)
218 {
219 - struct commit *commit;
219 struct commit_list *pending;
220 unsigned long expire_limit = cb->mark_limit;
221 struct commit_list *leftover = NULL;
@@ -226,11 +225,8 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)
225
226 pending = cb->mark_list;
227 while (pending) {
229 - struct commit_list *entry = pending;
228 struct commit_list *parent;
231 - pending = entry->next;
232 - commit = entry->item;
233 - free(entry);
229 + struct commit *commit = pop_commit(&pending);
230 if (commit->object.flags & REACHABLE)
231 continue;
232 if (parse_commit(commit))
builtin/rev-parse.c
+2 -5
@@ -281,11 +281,8 @@ static int try_difference(const char *arg)
281 b = lookup_commit_reference(end);
282 exclude = get_merge_bases(a, b);
283 while (exclude) {
284 - struct commit_list *n = exclude->next;
285 - show_rev(REVERSED,
286 - exclude->item->object.sha1,NULL);
287 - free(exclude);
288 - exclude = n;
284 + struct commit *commit = pop_commit(&exclude);
285 + show_rev(REVERSED, commit->object.sha1, NULL);
286 }
287 }
288 *dotdot = '.';
builtin/show-branch.c
+3 -14
@@ -53,17 +53,6 @@ static struct commit *interesting(struct commit_list *list)
53 return NULL;
54 }
55
56 -static struct commit *pop_one_commit(struct commit_list **list_p)
57 -{
58 - struct commit *commit;
59 - struct commit_list *list;
60 - list = *list_p;
61 - commit = list->item;
62 - *list_p = list->next;
63 - free(list);
64 - return commit;
65 -}
66 -
56 struct commit_name {
57 const char *head_name; /* which head's ancestor? */
58 int generation; /* how many parents away from head_name */
@@ -213,7 +202,7 @@ static void join_revs(struct commit_list **list_p,
202 while (*list_p) {
203 struct commit_list *parents;
204 int still_interesting = !!interesting(*list_p);
216 - struct commit *commit = pop_one_commit(list_p);
205 + struct commit *commit = pop_commit(list_p);
206 int flags = commit->object.flags & all_mask;
207
208 if (!still_interesting && extra <= 0)
@@ -504,7 +493,7 @@ static int show_merge_base(struct commit_list *seen, int num_rev)
493 int exit_status = 1;
494
495 while (seen) {
507 - struct commit *commit = pop_one_commit(&seen);
496 + struct commit *commit = pop_commit(&seen);
497 int flags = commit->object.flags & all_mask;
498 if (!(flags & UNINTERESTING) &&
499 ((flags & all_revs) == all_revs)) {
@@ -926,7 +915,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
915 all_revs = all_mask & ~((1u << REV_SHIFT) - 1);
916
917 while (seen) {
929 - struct commit *commit = pop_one_commit(&seen);
918 + struct commit *commit = pop_commit(&seen);
919 int this_flag = commit->object.flags;
920 int is_merge_point = ((this_flag & all_revs) == all_revs);
921
commit.c
+7 -20
@@ -443,11 +443,8 @@ struct commit_list *copy_commit_list(struct commit_list *list)
443
444 void free_commit_list(struct commit_list *list)
445 {
446 - while (list) {
447 - struct commit_list *temp = list;
448 - list = temp->next;
449 - free(temp);
450 - }
446 + while (list)
447 + pop_commit(&list);
448 }
449
450 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)
490 struct commit *pop_most_recent_commit(struct commit_list **list,
491 unsigned int mark)
492 {
496 - struct commit *ret = (*list)->item;
493 + struct commit *ret = pop_commit(list);
494 struct commit_list *parents = ret->parents;
498 - struct commit_list *old = *list;
499 -
500 - *list = (*list)->next;
501 - free(old);
495
496 while (parents) {
497 struct commit *commit = parents->item;
@@ -849,11 +842,9 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
842 list = paint_down_to_common(one, n, twos);
843
844 while (list) {
852 - struct commit_list *next = list->next;
853 - if (!(list->item->object.flags & STALE))
854 - commit_list_insert_by_date(list->item, &result);
855 - free(list);
856 - list = next;
845 + struct commit *commit = pop_commit(&list);
846 + if (!(commit->object.flags & STALE))
847 + commit_list_insert_by_date(commit, &result);
848 }
849 return result;
850 }
@@ -1543,13 +1534,9 @@ int commit_tree_extended(const char *msg, size_t msg_len,
1534 * if everything else stays the same.
1535 */
1536 while (parents) {
1546 - struct commit_list *next = parents->next;
1547 - struct commit *parent = parents->item;
1548 -
1537 + struct commit *parent = pop_commit(&parents);
1538 strbuf_addf(&buffer, "parent %s\n",
1539 sha1_to_hex(parent->object.sha1));
1551 - free(parents);
1552 - parents = next;
1540 }
1541
1542 /* Person/date information */
remote.c
+2 -4
@@ -1975,10 +1975,8 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)
1975 static void unmark_and_free(struct commit_list *list, unsigned int mark)
1976 {
1977 while (list) {
1978 - struct commit_list *temp = list;
1979 - temp->item->object.flags &= ~mark;
1980 - list = temp->next;
1981 - free(temp);
1978 + struct commit *commit = pop_commit(&list);
1979 + commit->object.flags &= ~mark;
1980 }
1981 }
1982
revision.c
+5 -22
@@ -149,10 +149,7 @@ void mark_parents_uninteresting(struct commit *commit)
149 commit_list_insert(l->item, &parents);
150
151 while (parents) {
152 - struct commit *commit = parents->item;
153 - l = parents;
154 - parents = parents->next;
155 - free(l);
152 + struct commit *commit = pop_commit(&parents);
153
154 while (commit) {
155 /*
@@ -1098,14 +1095,10 @@ static int limit_list(struct rev_info *revs)
1095 }
1096
1097 while (list) {
1101 - struct commit_list *entry = list;
1102 - struct commit *commit = list->item;
1098 + struct commit *commit = pop_commit(&list);
1099 struct object *obj = &commit->object;
1100 show_early_output_fn_t show;
1101
1106 - list = list->next;
1107 - free(entry);
1108 -
1102 if (commit == interesting_cache)
1103 interesting_cache = NULL;
1104
@@ -2719,10 +2712,7 @@ static void simplify_merges(struct rev_info *revs)
2712 yet_to_do = NULL;
2713 tail = &yet_to_do;
2714 while (list) {
2722 - commit = list->item;
2723 - next = list->next;
2724 - free(list);
2725 - list = next;
2715 + commit = pop_commit(&list);
2716 tail = simplify_one(revs, commit, tail);
2717 }
2718 }
@@ -2734,10 +2724,7 @@ static void simplify_merges(struct rev_info *revs)
2724 while (list) {
2725 struct merge_simplify_state *st;
2726
2737 - commit = list->item;
2738 - next = list->next;
2739 - free(list);
2740 - list = next;
2727 + commit = pop_commit(&list);
2728 st = locate_simplify_state(revs, commit);
2729 if (st->simplified == commit)
2730 tail = &commit_list_insert(commit, tail)->next;
@@ -3111,11 +3098,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
3098 return NULL;
3099
3100 do {
3114 - struct commit_list *entry = revs->commits;
3115 - struct commit *commit = entry->item;
3116 -
3117 - revs->commits = entry->next;
3118 - free(entry);
3101 + struct commit *commit = pop_commit(&revs->commits);
3102
3103 if (revs->reflog_info) {
3104 save_parents(revs, commit);
shallow.c
+1 -5
@@ -422,13 +422,9 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
422 commit_list_insert(c, &head);
423 while (head) {
424 struct commit_list *p;
425 - struct commit *c = head->item;
425 + struct commit *c = pop_commit(&head);
426 uint32_t **refs = ref_bitmap_at(&info->ref_bitmap, c);
427
428 - p = head;
429 - head = head->next;
430 - free(p);
431 -
428 /* XXX check "UNINTERESTING" from pack bitmaps if available */
429 if (c->object.flags & (SEEN | UNINTERESTING))
430 continue;
upload-pack.c
+2 -4
@@ -316,10 +316,8 @@ static int reachable(struct commit *want)
316
317 commit_list_insert_by_date(want, &work);
318 while (work) {
319 - struct commit_list *list = work->next;
320 - struct commit *commit = work->item;
321 - free(work);
322 - work = list;
319 + struct commit_list *list;
320 + struct commit *commit = pop_commit(&work);
321
322 if (commit->object.flags & THEY_HAVE) {
323 want->object.flags |= COMMON_KNOWN;