Skip to content

Commit 4bbaa1e

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cedc61a commit 4bbaa1e

File tree

5 files changed

+6
-42
lines changed

5 files changed

+6
-42
lines changed

builtin/blame.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,11 +1371,8 @@ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit
13711371

13721372
static int num_scapegoats(struct rev_info *revs, struct commit *commit)
13731373
{
1374-
int cnt;
13751374
struct commit_list *l = first_scapegoat(revs, commit);
1376-
for (cnt = 0; l; l = l->next)
1377-
cnt++;
1378-
return cnt;
1375+
return commit_list_count(l);
13791376
}
13801377

13811378
/* Distribute collected unsorted blames to the respected sorted lists

builtin/for-each-ref.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,6 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
283283
}
284284
}
285285

286-
static int num_parents(struct commit *commit)
287-
{
288-
struct commit_list *parents;
289-
int i;
290-
291-
for (i = 0, parents = commit->parents;
292-
parents;
293-
parents = parents->next)
294-
i++;
295-
return i;
296-
}
297-
298286
/* See grab_values */
299287
static void grab_commit_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
300288
{
@@ -315,12 +303,12 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
315303
}
316304
if (!strcmp(name, "numparent")) {
317305
char *s = xmalloc(40);
318-
v->ul = num_parents(commit);
306+
v->ul = commit_list_count(commit->parents);
319307
sprintf(s, "%lu", v->ul);
320308
v->s = s;
321309
}
322310
else if (!strcmp(name, "parent")) {
323-
int num = num_parents(commit);
311+
int num = commit_list_count(commit->parents);
324312
int i;
325313
struct commit_list *parents;
326314
char *s = xmalloc(41 * num + 1);

commit.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -987,12 +987,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
987987
}
988988

989989
/* There are more than one */
990-
cnt = 0;
991-
list = result;
992-
while (list) {
993-
list = list->next;
994-
cnt++;
995-
}
990+
cnt = commit_list_count(result);
996991
rslt = xcalloc(cnt, sizeof(*rslt));
997992
for (list = result, i = 0; list; list = list->next)
998993
rslt[i++] = list->item;

line-log.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -766,17 +766,6 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
766766
}
767767
}
768768

769-
static int count_parents(struct commit *commit)
770-
{
771-
struct commit_list *parents = commit->parents;
772-
int count = 0;
773-
while (parents) {
774-
count++;
775-
parents = parents->next;
776-
}
777-
return count;
778-
}
779-
780769
static void move_diff_queue(struct diff_queue_struct *dst,
781770
struct diff_queue_struct *src)
782771
{
@@ -1150,7 +1139,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
11501139
struct commit **parents;
11511140
struct commit_list *p;
11521141
int i;
1153-
int nparents = count_parents(commit);
1142+
int nparents = commit_list_count(commit->parents);
11541143

11551144
diffqueues = xmalloc(nparents * sizeof(*diffqueues));
11561145
cand = xmalloc(nparents * sizeof(*cand));

pretty.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,12 +1556,7 @@ static void pp_header(struct pretty_print_context *pp,
15561556
}
15571557

15581558
if (!parents_shown) {
1559-
struct commit_list *parent;
1560-
int num;
1561-
for (parent = commit->parents, num = 0;
1562-
parent;
1563-
parent = parent->next, num++)
1564-
;
1559+
unsigned num = commit_list_count(commit->parents);
15651560
/* with enough slop */
15661561
strbuf_grow(sb, num * 50 + 20);
15671562
add_merge_info(pp, sb, commit);

0 commit comments

Comments
 (0)