use commit_list_count() to count the members of commit_lists

Call commit_list_count() instead of open-coding it repeatedly.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe 2014-07-17 01:52:09 +02:00 коммит произвёл Junio C Hamano
Родитель cedc61a998
Коммит 4bbaa1eb6f
5 изменённых файлов: 6 добавлений и 42 удалений

Просмотреть файл

@ -1371,11 +1371,8 @@ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit
static int num_scapegoats(struct rev_info *revs, struct commit *commit)
{
int cnt;
struct commit_list *l = first_scapegoat(revs, commit);
for (cnt = 0; l; l = l->next)
cnt++;
return cnt;
return commit_list_count(l);
}
/* Distribute collected unsorted blames to the respected sorted lists

Просмотреть файл

@ -283,18 +283,6 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
}
}
static int num_parents(struct commit *commit)
{
struct commit_list *parents;
int i;
for (i = 0, parents = commit->parents;
parents;
parents = parents->next)
i++;
return i;
}
/* See grab_values */
static void grab_commit_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
{
@ -315,12 +303,12 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
}
if (!strcmp(name, "numparent")) {
char *s = xmalloc(40);
v->ul = num_parents(commit);
v->ul = commit_list_count(commit->parents);
sprintf(s, "%lu", v->ul);
v->s = s;
}
else if (!strcmp(name, "parent")) {
int num = num_parents(commit);
int num = commit_list_count(commit->parents);
int i;
struct commit_list *parents;
char *s = xmalloc(41 * num + 1);

Просмотреть файл

@ -987,12 +987,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
}
/* There are more than one */
cnt = 0;
list = result;
while (list) {
list = list->next;
cnt++;
}
cnt = commit_list_count(result);
rslt = xcalloc(cnt, sizeof(*rslt));
for (list = result, i = 0; list; list = list->next)
rslt[i++] = list->item;

Просмотреть файл

@ -766,17 +766,6 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
}
}
static int count_parents(struct commit *commit)
{
struct commit_list *parents = commit->parents;
int count = 0;
while (parents) {
count++;
parents = parents->next;
}
return count;
}
static void move_diff_queue(struct diff_queue_struct *dst,
struct diff_queue_struct *src)
{
@ -1150,7 +1139,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
struct commit **parents;
struct commit_list *p;
int i;
int nparents = count_parents(commit);
int nparents = commit_list_count(commit->parents);
diffqueues = xmalloc(nparents * sizeof(*diffqueues));
cand = xmalloc(nparents * sizeof(*cand));

Просмотреть файл

@ -1556,12 +1556,7 @@ static void pp_header(struct pretty_print_context *pp,
}
if (!parents_shown) {
struct commit_list *parent;
int num;
for (parent = commit->parents, num = 0;
parent;
parent = parent->next, num++)
;
unsigned num = commit_list_count(commit->parents);
/* with enough slop */
strbuf_grow(sb, num * 50 + 20);
add_merge_info(pp, sb, commit);