Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 6a89897

Browse files
committed
Merge branch 'rs/commit-list-append'
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()
2 parents 5fa8bf6 + a81a7fb commit 6a89897

File tree

4 files changed

+31
-45
lines changed

4 files changed

+31
-45
lines changed

commit.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,21 +361,6 @@ struct commit_list *commit_list_insert(struct commit *item, struct commit_list *
361361
return new_list;
362362
}
363363

364-
void commit_list_reverse(struct commit_list **list_p)
365-
{
366-
struct commit_list *prev = NULL, *curr = *list_p, *next;
367-
368-
if (!list_p)
369-
return;
370-
while (curr) {
371-
next = curr->next;
372-
curr->next = prev;
373-
prev = curr;
374-
curr = next;
375-
}
376-
*list_p = prev;
377-
}
378-
379364
unsigned commit_list_count(const struct commit_list *l)
380365
{
381366
unsigned c = 0;
@@ -1214,3 +1199,30 @@ struct commit *get_merge_parent(const char *name)
12141199
}
12151200
return commit;
12161201
}
1202+
1203+
/*
1204+
* Append a commit to the end of the commit_list.
1205+
*
1206+
* next starts by pointing to the variable that holds the head of an
1207+
* empty commit_list, and is updated to point to the "next" field of
1208+
* the last item on the list as new commits are appended.
1209+
*
1210+
* Usage example:
1211+
*
1212+
* struct commit_list *list;
1213+
* struct commit_list **next = &list;
1214+
*
1215+
* next = commit_list_append(c1, next);
1216+
* next = commit_list_append(c2, next);
1217+
* assert(commit_list_count(list) == 2);
1218+
* return list;
1219+
*/
1220+
struct commit_list **commit_list_append(struct commit *commit,
1221+
struct commit_list **next)
1222+
{
1223+
struct commit_list *new = xmalloc(sizeof(struct commit_list));
1224+
new->item = commit;
1225+
*next = new;
1226+
new->next = NULL;
1227+
return &new->next;
1228+
}

commit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ int find_commit_subject(const char *commit_buffer, const char **subject);
5353

5454
struct commit_list *commit_list_insert(struct commit *item,
5555
struct commit_list **list);
56+
struct commit_list **commit_list_append(struct commit *commit,
57+
struct commit_list **next);
5658
unsigned commit_list_count(const struct commit_list *l);
5759
struct commit_list *commit_list_insert_by_date(struct commit *item,
5860
struct commit_list **list);
5961
void commit_list_sort_by_date(struct commit_list **list);
60-
void commit_list_reverse(struct commit_list **list_p);
6162

6263
void free_commit_list(struct commit_list *list);
6364

revision.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,7 @@ int prepare_revision_walk(struct rev_info *revs)
20752075
{
20762076
int nr = revs->pending.nr;
20772077
struct object_array_entry *e, *list;
2078+
struct commit_list **next = &revs->commits;
20782079

20792080
e = list = revs->pending.objects;
20802081
revs->pending.nr = 0;
@@ -2085,12 +2086,11 @@ int prepare_revision_walk(struct rev_info *revs)
20852086
if (commit) {
20862087
if (!(commit->object.flags & SEEN)) {
20872088
commit->object.flags |= SEEN;
2088-
commit_list_insert(commit, &revs->commits);
2089+
next = commit_list_append(commit, next);
20892090
}
20902091
}
20912092
e++;
20922093
}
2093-
commit_list_reverse(&revs->commits);
20942094
commit_list_sort_by_date(&revs->commits);
20952095
if (!revs->leak_pending)
20962096
free(list);

sequencer.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -468,33 +468,6 @@ static void read_and_refresh_cache(struct replay_opts *opts)
468468
rollback_lock_file(&index_lock);
469469
}
470470

471-
/*
472-
* Append a commit to the end of the commit_list.
473-
*
474-
* next starts by pointing to the variable that holds the head of an
475-
* empty commit_list, and is updated to point to the "next" field of
476-
* the last item on the list as new commits are appended.
477-
*
478-
* Usage example:
479-
*
480-
* struct commit_list *list;
481-
* struct commit_list **next = &list;
482-
*
483-
* next = commit_list_append(c1, next);
484-
* next = commit_list_append(c2, next);
485-
* assert(commit_list_count(list) == 2);
486-
* return list;
487-
*/
488-
static struct commit_list **commit_list_append(struct commit *commit,
489-
struct commit_list **next)
490-
{
491-
struct commit_list *new = xmalloc(sizeof(struct commit_list));
492-
new->item = commit;
493-
*next = new;
494-
new->next = NULL;
495-
return &new->next;
496-
}
497-
498471
static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
499472
struct replay_opts *opts)
500473
{

0 commit comments

Comments
 (0)