Skip to content

Commit

Permalink
Merge branch 'rs/commit-list-append'
Browse files Browse the repository at this point in the history
There is no need for "commit_list_reverse()" function that only invites
inefficient code.

By René Scharfe
* rs/commit-list-append:
  commit: remove commit_list_reverse()
  revision: append to list instead of insert and reverse
  sequencer: export commit_list_append()
  • Loading branch information
gitster committed Apr 30, 2012
2 parents 5fa8bf6 + a81a7fb commit 6a89897
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 45 deletions.
42 changes: 27 additions & 15 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,21 +361,6 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list *
return new_list;
}

void commit_list_reverse(struct commit_list **list_p)
{
struct commit_list *prev = NULL, *curr = *list_p, *next;

if (!list_p)
return;
while (curr) {
next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
*list_p = prev;
}

unsigned commit_list_count(const struct commit_list *l)
{
unsigned c = 0;
Expand Down Expand Up @@ -1214,3 +1199,30 @@ struct commit *get_merge_parent(const char *name)
}
return commit;
}

/*
* Append a commit to the end of the commit_list.
*
* next starts by pointing to the variable that holds the head of an
* empty commit_list, and is updated to point to the "next" field of
* the last item on the list as new commits are appended.
*
* Usage example:
*
* struct commit_list *list;
* struct commit_list **next = &list;
*
* next = commit_list_append(c1, next);
* next = commit_list_append(c2, next);
* assert(commit_list_count(list) == 2);
* return list;
*/
struct commit_list **commit_list_append(struct commit *commit,
struct commit_list **next)
{
struct commit_list *new = xmalloc(sizeof(struct commit_list));
new->item = commit;
*next = new;
new->next = NULL;
return &new->next;
}
3 changes: 2 additions & 1 deletion commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ int find_commit_subject(const char *commit_buffer, const char **subject);

struct commit_list *commit_list_insert(struct commit *item,
struct commit_list **list);
struct commit_list **commit_list_append(struct commit *commit,
struct commit_list **next);
unsigned commit_list_count(const struct commit_list *l);
struct commit_list *commit_list_insert_by_date(struct commit *item,
struct commit_list **list);
void commit_list_sort_by_date(struct commit_list **list);
void commit_list_reverse(struct commit_list **list_p);

void free_commit_list(struct commit_list *list);

Expand Down
4 changes: 2 additions & 2 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ int prepare_revision_walk(struct rev_info *revs)
{
int nr = revs->pending.nr;
struct object_array_entry *e, *list;
struct commit_list **next = &revs->commits;

e = list = revs->pending.objects;
revs->pending.nr = 0;
Expand All @@ -2085,12 +2086,11 @@ int prepare_revision_walk(struct rev_info *revs)
if (commit) {
if (!(commit->object.flags & SEEN)) {
commit->object.flags |= SEEN;
commit_list_insert(commit, &revs->commits);
next = commit_list_append(commit, next);
}
}
e++;
}
commit_list_reverse(&revs->commits);
commit_list_sort_by_date(&revs->commits);
if (!revs->leak_pending)
free(list);
Expand Down
27 changes: 0 additions & 27 deletions sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,33 +468,6 @@ static void read_and_refresh_cache(struct replay_opts *opts)
rollback_lock_file(&index_lock);
}

/*
* Append a commit to the end of the commit_list.
*
* next starts by pointing to the variable that holds the head of an
* empty commit_list, and is updated to point to the "next" field of
* the last item on the list as new commits are appended.
*
* Usage example:
*
* struct commit_list *list;
* struct commit_list **next = &list;
*
* next = commit_list_append(c1, next);
* next = commit_list_append(c2, next);
* assert(commit_list_count(list) == 2);
* return list;
*/
static struct commit_list **commit_list_append(struct commit *commit,
struct commit_list **next)
{
struct commit_list *new = xmalloc(sizeof(struct commit_list));
new->item = commit;
*next = new;
new->next = NULL;
return &new->next;
}

static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
struct replay_opts *opts)
{
Expand Down

0 comments on commit 6a89897

Please sign in to comment.