Skip to content

Commit e510ab8

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2435856 commit e510ab8

File tree

10 files changed

+31
-92
lines changed

10 files changed

+31
-92
lines changed

builtin/fmt-merge-msg.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
536536
static void find_merge_parents(struct merge_parents *result,
537537
struct strbuf *in, unsigned char *head)
538538
{
539-
struct commit_list *parents, *next;
539+
struct commit_list *parents;
540540
struct commit *head_commit;
541541
int pos = 0, i, j;
542542

@@ -575,13 +575,10 @@ static void find_merge_parents(struct merge_parents *result,
575575
parents = reduce_heads(parents);
576576

577577
while (parents) {
578+
struct commit *cmit = pop_commit(&parents);
578579
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))
581581
result->item[i].used = 1;
582-
next = parents->next;
583-
free(parents);
584-
parents = next;
585582
}
586583

587584
for (i = j = 0; i < result->nr; i++) {

builtin/merge.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ static struct commit_list *reduce_parents(struct commit *head_commit,
10191019
int *head_subsumed,
10201020
struct commit_list *remoteheads)
10211021
{
1022-
struct commit_list *parents, *next, **remotes = &remoteheads;
1022+
struct commit_list *parents, **remotes;
10231023

10241024
/*
10251025
* Is the current HEAD reachable from another commit being
@@ -1033,16 +1033,14 @@ static struct commit_list *reduce_parents(struct commit *head_commit,
10331033
/* Find what parents to record by checking independent ones. */
10341034
parents = reduce_heads(remoteheads);
10351035

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);
10411040
if (commit == head_commit)
10421041
*head_subsumed = 0;
10431042
else
10441043
remotes = &commit_list_insert(commit, remotes)->next;
1045-
free(parents);
10461044
}
10471045
return remoteheads;
10481046
}

builtin/reflog.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ static int keep_entry(struct commit **it, unsigned char *sha1)
216216
*/
217217
static void mark_reachable(struct expire_reflog_policy_cb *cb)
218218
{
219-
struct commit *commit;
220219
struct commit_list *pending;
221220
unsigned long expire_limit = cb->mark_limit;
222221
struct commit_list *leftover = NULL;
@@ -226,11 +225,8 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)
226225

227226
pending = cb->mark_list;
228227
while (pending) {
229-
struct commit_list *entry = pending;
230228
struct commit_list *parent;
231-
pending = entry->next;
232-
commit = entry->item;
233-
free(entry);
229+
struct commit *commit = pop_commit(&pending);
234230
if (commit->object.flags & REACHABLE)
235231
continue;
236232
if (parse_commit(commit))

builtin/rev-parse.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,8 @@ static int try_difference(const char *arg)
281281
b = lookup_commit_reference(end);
282282
exclude = get_merge_bases(a, b);
283283
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);
289286
}
290287
}
291288
*dotdot = '.';

builtin/show-branch.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ static struct commit *interesting(struct commit_list *list)
5353
return NULL;
5454
}
5555

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-
6756
struct commit_name {
6857
const char *head_name; /* which head's ancestor? */
6958
int generation; /* how many parents away from head_name */
@@ -213,7 +202,7 @@ static void join_revs(struct commit_list **list_p,
213202
while (*list_p) {
214203
struct commit_list *parents;
215204
int still_interesting = !!interesting(*list_p);
216-
struct commit *commit = pop_one_commit(list_p);
205+
struct commit *commit = pop_commit(list_p);
217206
int flags = commit->object.flags & all_mask;
218207

219208
if (!still_interesting && extra <= 0)
@@ -504,7 +493,7 @@ static int show_merge_base(struct commit_list *seen, int num_rev)
504493
int exit_status = 1;
505494

506495
while (seen) {
507-
struct commit *commit = pop_one_commit(&seen);
496+
struct commit *commit = pop_commit(&seen);
508497
int flags = commit->object.flags & all_mask;
509498
if (!(flags & UNINTERESTING) &&
510499
((flags & all_revs) == all_revs)) {
@@ -926,7 +915,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
926915
all_revs = all_mask & ~((1u << REV_SHIFT) - 1);
927916

928917
while (seen) {
929-
struct commit *commit = pop_one_commit(&seen);
918+
struct commit *commit = pop_commit(&seen);
930919
int this_flag = commit->object.flags;
931920
int is_merge_point = ((this_flag & all_revs) == all_revs);
932921

commit.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,8 @@ struct commit_list *copy_commit_list(struct commit_list *list)
443443

444444
void free_commit_list(struct commit_list *list)
445445
{
446-
while (list) {
447-
struct commit_list *temp = list;
448-
list = temp->next;
449-
free(temp);
450-
}
446+
while (list)
447+
pop_commit(&list);
451448
}
452449

453450
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)
493490
struct commit *pop_most_recent_commit(struct commit_list **list,
494491
unsigned int mark)
495492
{
496-
struct commit *ret = (*list)->item;
493+
struct commit *ret = pop_commit(list);
497494
struct commit_list *parents = ret->parents;
498-
struct commit_list *old = *list;
499-
500-
*list = (*list)->next;
501-
free(old);
502495

503496
while (parents) {
504497
struct commit *commit = parents->item;
@@ -849,11 +842,9 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
849842
list = paint_down_to_common(one, n, twos);
850843

851844
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);
857848
}
858849
return result;
859850
}
@@ -1543,13 +1534,9 @@ int commit_tree_extended(const char *msg, size_t msg_len,
15431534
* if everything else stays the same.
15441535
*/
15451536
while (parents) {
1546-
struct commit_list *next = parents->next;
1547-
struct commit *parent = parents->item;
1548-
1537+
struct commit *parent = pop_commit(&parents);
15491538
strbuf_addf(&buffer, "parent %s\n",
15501539
sha1_to_hex(parent->object.sha1));
1551-
free(parents);
1552-
parents = next;
15531540
}
15541541

15551542
/* Person/date information */

remote.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,10 +1975,8 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)
19751975
static void unmark_and_free(struct commit_list *list, unsigned int mark)
19761976
{
19771977
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;
19821980
}
19831981
}
19841982

revision.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ void mark_parents_uninteresting(struct commit *commit)
149149
commit_list_insert(l->item, &parents);
150150

151151
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);
156153

157154
while (commit) {
158155
/*
@@ -1098,14 +1095,10 @@ static int limit_list(struct rev_info *revs)
10981095
}
10991096

11001097
while (list) {
1101-
struct commit_list *entry = list;
1102-
struct commit *commit = list->item;
1098+
struct commit *commit = pop_commit(&list);
11031099
struct object *obj = &commit->object;
11041100
show_early_output_fn_t show;
11051101

1106-
list = list->next;
1107-
free(entry);
1108-
11091102
if (commit == interesting_cache)
11101103
interesting_cache = NULL;
11111104

@@ -2719,10 +2712,7 @@ static void simplify_merges(struct rev_info *revs)
27192712
yet_to_do = NULL;
27202713
tail = &yet_to_do;
27212714
while (list) {
2722-
commit = list->item;
2723-
next = list->next;
2724-
free(list);
2725-
list = next;
2715+
commit = pop_commit(&list);
27262716
tail = simplify_one(revs, commit, tail);
27272717
}
27282718
}
@@ -2734,10 +2724,7 @@ static void simplify_merges(struct rev_info *revs)
27342724
while (list) {
27352725
struct merge_simplify_state *st;
27362726

2737-
commit = list->item;
2738-
next = list->next;
2739-
free(list);
2740-
list = next;
2727+
commit = pop_commit(&list);
27412728
st = locate_simplify_state(revs, commit);
27422729
if (st->simplified == commit)
27432730
tail = &commit_list_insert(commit, tail)->next;
@@ -3111,11 +3098,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
31113098
return NULL;
31123099

31133100
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);
31193102

31203103
if (revs->reflog_info) {
31213104
save_parents(revs, commit);

shallow.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,9 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
422422
commit_list_insert(c, &head);
423423
while (head) {
424424
struct commit_list *p;
425-
struct commit *c = head->item;
425+
struct commit *c = pop_commit(&head);
426426
uint32_t **refs = ref_bitmap_at(&info->ref_bitmap, c);
427427

428-
p = head;
429-
head = head->next;
430-
free(p);
431-
432428
/* XXX check "UNINTERESTING" from pack bitmaps if available */
433429
if (c->object.flags & (SEEN | UNINTERESTING))
434430
continue;

upload-pack.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,8 @@ static int reachable(struct commit *want)
316316

317317
commit_list_insert_by_date(want, &work);
318318
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);
323321

324322
if (commit->object.flags & THEY_HAVE) {
325323
want->object.flags |= COMMON_KNOWN;

0 commit comments

Comments
 (0)