use commit_list_count() to count the members of commit_lists
PATCH 1/1 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]>
--- builtin/blame.c | 5 +---- builtin/for-each-ref.c | 16 ++-------------- commit.c | 7 +------ line-log.c | 13 +------------ pretty.c | 7 +------ 5 files changed, 6 insertions(+), 42 deletions(-)
builtin/blame.c +1 -4
@@ -1371,11 +1371,8 @@ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commitstatic 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
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 } } -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 );
commit.c +1 -6
@@ -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;
line-log.c +1 -12
@@ -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 *commstruct 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));
pretty.c +1 -6
@@ -1554,12 +1554,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);
Signature · 1 line
2.0.2