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>
René Scharfe committed
Jul 17, 2014 at 01:52 UTC
4bbaa1eb6fb4a520069e53ec5afa977a316a5d36
5 files changed
+6
-42
builtin/blame.c
+1
-4
@@ -1371,11 +1371,8 @@ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit
1371
1372
static int num_scapegoats(struct rev_info *revs, struct commit *commit)
1373
{
1374
- int cnt;
1374
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);
1376
}
1377
1378
/* Distribute collected unsorted blames to the respected sorted lists
builtin/for-each-ref.c
+2
-14
@@ -283,18 +283,6 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
283
}
284
}
285
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
-
286
/* See grab_values */
287
static void grab_commit_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
288
{
@@ -315,12 +303,12 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
303
}
304
if (!strcmp(name, "numparent")) {
305
char *s = xmalloc(40);
318
- v->ul = num_parents(commit);
306
+ v->ul = commit_list_count(commit->parents);
307
sprintf(s, "%lu", v->ul);
308
v->s = s;
309
}
310
else if (!strcmp(name, "parent")) {
323
- int num = num_parents(commit);
311
+ int num = commit_list_count(commit->parents);
312
int i;
313
struct commit_list *parents;
314
char *s = xmalloc(41 * num + 1);
commit.c
+1
-6
@@ -987,12 +987,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
987
}
988
989
/* 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);
991
rslt = xcalloc(cnt, sizeof(*rslt));
992
for (list = result, i = 0; list; list = list->next)
993
rslt[i++] = list->item;
line-log.c
+1
-12
@@ -766,17 +766,6 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
766
}
767
}
768
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
-
769
static void move_diff_queue(struct diff_queue_struct *dst,
770
struct diff_queue_struct *src)
771
{
@@ -1150,7 +1139,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
1139
struct commit **parents;
1140
struct commit_list *p;
1141
int i;
1153
- int nparents = count_parents(commit);
1142
+ int nparents = commit_list_count(commit->parents);
1143
1144
diffqueues = xmalloc(nparents * sizeof(*diffqueues));
1145
cand = xmalloc(nparents * sizeof(*cand));
pretty.c
+1
-6
@@ -1556,12 +1556,7 @@ static void pp_header(struct pretty_print_context *pp,
1556
}
1557
1558
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);
1560
/* with enough slop */
1561
strbuf_grow(sb, num * 50 + 20);
1562
add_merge_info(pp, sb, commit);