Merge branch 'rs/pop-commit'

Code simplification.

* rs/pop-commit:
  use pop_commit() for consuming the first entry of a struct commit_list
This commit is contained in:
Junio C Hamano 2015-10-30 13:07:03 -07:00
commit 0692a6c22c
10 changed files with 31 additions and 92 deletions

View File

@ -537,7 +537,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
static void find_merge_parents(struct merge_parents *result, static void find_merge_parents(struct merge_parents *result,
struct strbuf *in, unsigned char *head) struct strbuf *in, unsigned char *head)
{ {
struct commit_list *parents, *next; struct commit_list *parents;
struct commit *head_commit; struct commit *head_commit;
int pos = 0, i, j; int pos = 0, i, j;
@ -576,13 +576,10 @@ static void find_merge_parents(struct merge_parents *result,
parents = reduce_heads(parents); parents = reduce_heads(parents);
while (parents) { while (parents) {
struct commit *cmit = pop_commit(&parents);
for (i = 0; i < result->nr; i++) for (i = 0; i < result->nr; i++)
if (!hashcmp(result->item[i].commit, if (!hashcmp(result->item[i].commit, cmit->object.sha1))
parents->item->object.sha1))
result->item[i].used = 1; result->item[i].used = 1;
next = parents->next;
free(parents);
parents = next;
} }
for (i = j = 0; i < result->nr; i++) { for (i = j = 0; i < result->nr; i++) {

View File

@ -1019,7 +1019,7 @@ static struct commit_list *reduce_parents(struct commit *head_commit,
int *head_subsumed, int *head_subsumed,
struct commit_list *remoteheads) 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 * Is the current HEAD reachable from another commit being
@ -1033,16 +1033,14 @@ static struct commit_list *reduce_parents(struct commit *head_commit,
/* Find what parents to record by checking independent ones. */ /* Find what parents to record by checking independent ones. */
parents = reduce_heads(remoteheads); parents = reduce_heads(remoteheads);
for (remoteheads = NULL, remotes = &remoteheads; remoteheads = NULL;
parents; remotes = &remoteheads;
parents = next) { while (parents) {
struct commit *commit = parents->item; struct commit *commit = pop_commit(&parents);
next = parents->next;
if (commit == head_commit) if (commit == head_commit)
*head_subsumed = 0; *head_subsumed = 0;
else else
remotes = &commit_list_insert(commit, remotes)->next; remotes = &commit_list_insert(commit, remotes)->next;
free(parents);
} }
return remoteheads; return remoteheads;
} }

View File

@ -218,7 +218,6 @@ static int keep_entry(struct commit **it, unsigned char *sha1)
*/ */
static void mark_reachable(struct expire_reflog_policy_cb *cb) static void mark_reachable(struct expire_reflog_policy_cb *cb)
{ {
struct commit *commit;
struct commit_list *pending; struct commit_list *pending;
unsigned long expire_limit = cb->mark_limit; unsigned long expire_limit = cb->mark_limit;
struct commit_list *leftover = NULL; struct commit_list *leftover = NULL;
@ -228,11 +227,8 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb)
pending = cb->mark_list; pending = cb->mark_list;
while (pending) { while (pending) {
struct commit_list *entry = pending;
struct commit_list *parent; struct commit_list *parent;
pending = entry->next; struct commit *commit = pop_commit(&pending);
commit = entry->item;
free(entry);
if (commit->object.flags & REACHABLE) if (commit->object.flags & REACHABLE)
continue; continue;
if (parse_commit(commit)) if (parse_commit(commit))

View File

@ -281,11 +281,8 @@ static int try_difference(const char *arg)
b = lookup_commit_reference(end); b = lookup_commit_reference(end);
exclude = get_merge_bases(a, b); exclude = get_merge_bases(a, b);
while (exclude) { while (exclude) {
struct commit_list *n = exclude->next; struct commit *commit = pop_commit(&exclude);
show_rev(REVERSED, show_rev(REVERSED, commit->object.sha1, NULL);
exclude->item->object.sha1,NULL);
free(exclude);
exclude = n;
} }
} }
*dotdot = '.'; *dotdot = '.';

View File

@ -53,17 +53,6 @@ static struct commit *interesting(struct commit_list *list)
return NULL; 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 { struct commit_name {
const char *head_name; /* which head's ancestor? */ const char *head_name; /* which head's ancestor? */
int generation; /* how many parents away from head_name */ int generation; /* how many parents away from head_name */
@ -213,7 +202,7 @@ static void join_revs(struct commit_list **list_p,
while (*list_p) { while (*list_p) {
struct commit_list *parents; struct commit_list *parents;
int still_interesting = !!interesting(*list_p); 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; int flags = commit->object.flags & all_mask;
if (!still_interesting && extra <= 0) if (!still_interesting && extra <= 0)
@ -504,7 +493,7 @@ static int show_merge_base(struct commit_list *seen, int num_rev)
int exit_status = 1; int exit_status = 1;
while (seen) { while (seen) {
struct commit *commit = pop_one_commit(&seen); struct commit *commit = pop_commit(&seen);
int flags = commit->object.flags & all_mask; int flags = commit->object.flags & all_mask;
if (!(flags & UNINTERESTING) && if (!(flags & UNINTERESTING) &&
((flags & all_revs) == all_revs)) { ((flags & all_revs) == all_revs)) {
@ -929,7 +918,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
all_revs = all_mask & ~((1u << REV_SHIFT) - 1); all_revs = all_mask & ~((1u << REV_SHIFT) - 1);
while (seen) { while (seen) {
struct commit *commit = pop_one_commit(&seen); struct commit *commit = pop_commit(&seen);
int this_flag = commit->object.flags; int this_flag = commit->object.flags;
int is_merge_point = ((this_flag & all_revs) == all_revs); int is_merge_point = ((this_flag & all_revs) == all_revs);

View File

@ -455,11 +455,8 @@ struct commit_list *copy_commit_list(struct commit_list *list)
void free_commit_list(struct commit_list *list) void free_commit_list(struct commit_list *list)
{ {
while (list) { while (list)
struct commit_list *temp = list; pop_commit(&list);
list = temp->next;
free(temp);
}
} }
struct commit_list * commit_list_insert_by_date(struct commit *item, struct commit_list **list) struct commit_list * commit_list_insert_by_date(struct commit *item, struct commit_list **list)
@ -505,12 +502,8 @@ void commit_list_sort_by_date(struct commit_list **list)
struct commit *pop_most_recent_commit(struct commit_list **list, struct commit *pop_most_recent_commit(struct commit_list **list,
unsigned int mark) unsigned int mark)
{ {
struct commit *ret = (*list)->item; struct commit *ret = pop_commit(list);
struct commit_list *parents = ret->parents; struct commit_list *parents = ret->parents;
struct commit_list *old = *list;
*list = (*list)->next;
free(old);
while (parents) { while (parents) {
struct commit *commit = parents->item; struct commit *commit = parents->item;
@ -861,11 +854,9 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
list = paint_down_to_common(one, n, twos); list = paint_down_to_common(one, n, twos);
while (list) { while (list) {
struct commit_list *next = list->next; struct commit *commit = pop_commit(&list);
if (!(list->item->object.flags & STALE)) if (!(commit->object.flags & STALE))
commit_list_insert_by_date(list->item, &result); commit_list_insert_by_date(commit, &result);
free(list);
list = next;
} }
return result; return result;
} }
@ -1546,13 +1537,9 @@ int commit_tree_extended(const char *msg, size_t msg_len,
* if everything else stays the same. * if everything else stays the same.
*/ */
while (parents) { while (parents) {
struct commit_list *next = parents->next; struct commit *parent = pop_commit(&parents);
struct commit *parent = parents->item;
strbuf_addf(&buffer, "parent %s\n", strbuf_addf(&buffer, "parent %s\n",
sha1_to_hex(parent->object.sha1)); sha1_to_hex(parent->object.sha1));
free(parents);
parents = next;
} }
/* Person/date information */ /* Person/date information */

View File

@ -1939,10 +1939,8 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)
static void unmark_and_free(struct commit_list *list, unsigned int mark) static void unmark_and_free(struct commit_list *list, unsigned int mark)
{ {
while (list) { while (list) {
struct commit_list *temp = list; struct commit *commit = pop_commit(&list);
temp->item->object.flags &= ~mark; commit->object.flags &= ~mark;
list = temp->next;
free(temp);
} }
} }

View File

@ -153,10 +153,7 @@ void mark_parents_uninteresting(struct commit *commit)
commit_list_insert(l->item, &parents); commit_list_insert(l->item, &parents);
while (parents) { while (parents) {
struct commit *commit = parents->item; struct commit *commit = pop_commit(&parents);
l = parents;
parents = parents->next;
free(l);
while (commit) { while (commit) {
/* /*
@ -1102,14 +1099,10 @@ static int limit_list(struct rev_info *revs)
} }
while (list) { while (list) {
struct commit_list *entry = list; struct commit *commit = pop_commit(&list);
struct commit *commit = list->item;
struct object *obj = &commit->object; struct object *obj = &commit->object;
show_early_output_fn_t show; show_early_output_fn_t show;
list = list->next;
free(entry);
if (commit == interesting_cache) if (commit == interesting_cache)
interesting_cache = NULL; interesting_cache = NULL;
@ -2733,10 +2726,7 @@ static void simplify_merges(struct rev_info *revs)
yet_to_do = NULL; yet_to_do = NULL;
tail = &yet_to_do; tail = &yet_to_do;
while (list) { while (list) {
commit = list->item; commit = pop_commit(&list);
next = list->next;
free(list);
list = next;
tail = simplify_one(revs, commit, tail); tail = simplify_one(revs, commit, tail);
} }
} }
@ -2748,10 +2738,7 @@ static void simplify_merges(struct rev_info *revs)
while (list) { while (list) {
struct merge_simplify_state *st; struct merge_simplify_state *st;
commit = list->item; commit = pop_commit(&list);
next = list->next;
free(list);
list = next;
st = locate_simplify_state(revs, commit); st = locate_simplify_state(revs, commit);
if (st->simplified == commit) if (st->simplified == commit)
tail = &commit_list_insert(commit, tail)->next; tail = &commit_list_insert(commit, tail)->next;
@ -3125,11 +3112,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
return NULL; return NULL;
do { do {
struct commit_list *entry = revs->commits; struct commit *commit = pop_commit(&revs->commits);
struct commit *commit = entry->item;
revs->commits = entry->next;
free(entry);
if (revs->reflog_info) { if (revs->reflog_info) {
save_parents(revs, commit); save_parents(revs, commit);

View File

@ -400,13 +400,9 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
commit_list_insert(c, &head); commit_list_insert(c, &head);
while (head) { while (head) {
struct commit_list *p; 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); 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 */ /* XXX check "UNINTERESTING" from pack bitmaps if available */
if (c->object.flags & (SEEN | UNINTERESTING)) if (c->object.flags & (SEEN | UNINTERESTING))
continue; continue;

View File

@ -316,10 +316,8 @@ static int reachable(struct commit *want)
commit_list_insert_by_date(want, &work); commit_list_insert_by_date(want, &work);
while (work) { while (work) {
struct commit_list *list = work->next; struct commit_list *list;
struct commit *commit = work->item; struct commit *commit = pop_commit(&work);
free(work);
work = list;
if (commit->object.flags & THEY_HAVE) { if (commit->object.flags & THEY_HAVE) {
want->object.flags |= COMMON_KNOWN; want->object.flags |= COMMON_KNOWN;