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>
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 05f4c26..46c92c1 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -536,7 +536,7 @@
 static void find_merge_parents(struct merge_parents *result,
 			       struct strbuf *in, unsigned char *head)
 {
-	struct commit_list *parents, *next;
+	struct commit_list *parents;
 	struct commit *head_commit;
 	int pos = 0, i, j;
 
@@ -575,13 +575,10 @@
 	parents = reduce_heads(parents);
 
 	while (parents) {
+		struct commit *cmit = pop_commit(&parents);
 		for (i = 0; i < result->nr; i++)
-			if (!hashcmp(result->item[i].commit,
-				     parents->item->object.sha1))
+			if (!hashcmp(result->item[i].commit, cmit->object.sha1))
 				result->item[i].used = 1;
-		next = parents->next;
-		free(parents);
-		parents = next;
 	}
 
 	for (i = j = 0; i < result->nr; i++) {
diff --git a/builtin/merge.c b/builtin/merge.c
index 85c54dc..63563b9 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1019,7 +1019,7 @@
 					  int *head_subsumed,
 					  struct commit_list *remoteheads)
 {
-	struct commit_list *parents, *next, **remotes = &remoteheads;
+	struct commit_list *parents, **remotes;
 
 	/*
 	 * Is the current HEAD reachable from another commit being
@@ -1033,16 +1033,14 @@
 	/* Find what parents to record by checking independent ones. */
 	parents = reduce_heads(remoteheads);
 
-	for (remoteheads = NULL, remotes = &remoteheads;
-	     parents;
-	     parents = next) {
-		struct commit *commit = parents->item;
-		next = parents->next;
+	remoteheads = NULL;
+	remotes = &remoteheads;
+	while (parents) {
+		struct commit *commit = pop_commit(&parents);
 		if (commit == head_commit)
 			*head_subsumed = 0;
 		else
 			remotes = &commit_list_insert(commit, remotes)->next;
-		free(parents);
 	}
 	return remoteheads;
 }
diff --git a/builtin/reflog.c b/builtin/reflog.c
index c2eb8ff..fa841b5 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -216,7 +216,6 @@
  */
 static void mark_reachable(struct expire_reflog_policy_cb *cb)
 {
-	struct commit *commit;
 	struct commit_list *pending;
 	unsigned long expire_limit = cb->mark_limit;
 	struct commit_list *leftover = NULL;
@@ -226,11 +225,8 @@
 
 	pending = cb->mark_list;
 	while (pending) {
-		struct commit_list *entry = pending;
 		struct commit_list *parent;
-		pending = entry->next;
-		commit = entry->item;
-		free(entry);
+		struct commit *commit = pop_commit(&pending);
 		if (commit->object.flags & REACHABLE)
 			continue;
 		if (parse_commit(commit))
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 02d747d..e92a782 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -281,11 +281,8 @@
 			b = lookup_commit_reference(end);
 			exclude = get_merge_bases(a, b);
 			while (exclude) {
-				struct commit_list *n = exclude->next;
-				show_rev(REVERSED,
-					 exclude->item->object.sha1,NULL);
-				free(exclude);
-				exclude = n;
+				struct commit *commit = pop_commit(&exclude);
+				show_rev(REVERSED, commit->object.sha1, NULL);
 			}
 		}
 		*dotdot = '.';
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 344ae4c..5cc6ad1 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -53,17 +53,6 @@
 	return NULL;
 }
 
-static struct commit *pop_one_commit(struct commit_list **list_p)
-{
-	struct commit *commit;
-	struct commit_list *list;
-	list = *list_p;
-	commit = list->item;
-	*list_p = list->next;
-	free(list);
-	return commit;
-}
-
 struct commit_name {
 	const char *head_name; /* which head's ancestor? */
 	int generation; /* how many parents away from head_name */
@@ -213,7 +202,7 @@
 	while (*list_p) {
 		struct commit_list *parents;
 		int still_interesting = !!interesting(*list_p);
-		struct commit *commit = pop_one_commit(list_p);
+		struct commit *commit = pop_commit(list_p);
 		int flags = commit->object.flags & all_mask;
 
 		if (!still_interesting && extra <= 0)
@@ -504,7 +493,7 @@
 	int exit_status = 1;
 
 	while (seen) {
-		struct commit *commit = pop_one_commit(&seen);
+		struct commit *commit = pop_commit(&seen);
 		int flags = commit->object.flags & all_mask;
 		if (!(flags & UNINTERESTING) &&
 		    ((flags & all_revs) == all_revs)) {
@@ -926,7 +915,7 @@
 	all_revs = all_mask & ~((1u << REV_SHIFT) - 1);
 
 	while (seen) {
-		struct commit *commit = pop_one_commit(&seen);
+		struct commit *commit = pop_commit(&seen);
 		int this_flag = commit->object.flags;
 		int is_merge_point = ((this_flag & all_revs) == all_revs);
 
diff --git a/commit.c b/commit.c
index 6e2103c..1ab4ff2 100644
--- a/commit.c
+++ b/commit.c
@@ -443,11 +443,8 @@
 
 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 @@
 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 @@
 	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 @@
 	 * 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 */
diff --git a/remote.c b/remote.c
index 26504b7..ee6edfa 100644
--- a/remote.c
+++ b/remote.c
@@ -1975,10 +1975,8 @@
 static void unmark_and_free(struct commit_list *list, unsigned int mark)
 {
 	while (list) {
-		struct commit_list *temp = list;
-		temp->item->object.flags &= ~mark;
-		list = temp->next;
-		free(temp);
+		struct commit *commit = pop_commit(&list);
+		commit->object.flags &= ~mark;
 	}
 }
 
diff --git a/revision.c b/revision.c
index 9b9d77d..3f65614 100644
--- a/revision.c
+++ b/revision.c
@@ -149,10 +149,7 @@
 		commit_list_insert(l->item, &parents);
 
 	while (parents) {
-		struct commit *commit = parents->item;
-		l = parents;
-		parents = parents->next;
-		free(l);
+		struct commit *commit = pop_commit(&parents);
 
 		while (commit) {
 			/*
@@ -1098,14 +1095,10 @@
 	}
 
 	while (list) {
-		struct commit_list *entry = list;
-		struct commit *commit = list->item;
+		struct commit *commit = pop_commit(&list);
 		struct object *obj = &commit->object;
 		show_early_output_fn_t show;
 
-		list = list->next;
-		free(entry);
-
 		if (commit == interesting_cache)
 			interesting_cache = NULL;
 
@@ -2719,10 +2712,7 @@
 		yet_to_do = NULL;
 		tail = &yet_to_do;
 		while (list) {
-			commit = list->item;
-			next = list->next;
-			free(list);
-			list = next;
+			commit = pop_commit(&list);
 			tail = simplify_one(revs, commit, tail);
 		}
 	}
@@ -2734,10 +2724,7 @@
 	while (list) {
 		struct merge_simplify_state *st;
 
-		commit = list->item;
-		next = list->next;
-		free(list);
-		list = next;
+		commit = pop_commit(&list);
 		st = locate_simplify_state(revs, commit);
 		if (st->simplified == commit)
 			tail = &commit_list_insert(commit, tail)->next;
@@ -3111,11 +3098,7 @@
 		return NULL;
 
 	do {
-		struct commit_list *entry = revs->commits;
-		struct commit *commit = entry->item;
-
-		revs->commits = entry->next;
-		free(entry);
+		struct commit *commit = pop_commit(&revs->commits);
 
 		if (revs->reflog_info) {
 			save_parents(revs, commit);
diff --git a/shallow.c b/shallow.c
index 257d811..889fad9 100644
--- a/shallow.c
+++ b/shallow.c
@@ -422,13 +422,9 @@
 	commit_list_insert(c, &head);
 	while (head) {
 		struct commit_list *p;
-		struct commit *c = head->item;
+		struct commit *c = pop_commit(&head);
 		uint32_t **refs = ref_bitmap_at(&info->ref_bitmap, c);
 
-		p = head;
-		head = head->next;
-		free(p);
-
 		/* XXX check "UNINTERESTING" from pack bitmaps if available */
 		if (c->object.flags & (SEEN | UNINTERESTING))
 			continue;
diff --git a/upload-pack.c b/upload-pack.c
index 89e832b..d0bc3ca 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -316,10 +316,8 @@
 
 	commit_list_insert_by_date(want, &work);
 	while (work) {
-		struct commit_list *list = work->next;
-		struct commit *commit = work->item;
-		free(work);
-		work = list;
+		struct commit_list *list;
+		struct commit *commit = pop_commit(&work);
 
 		if (commit->object.flags & THEY_HAVE) {
 			want->object.flags |= COMMON_KNOWN;