@@ -73,10 +73,9 @@ static int git_pretty_formats_config(const char *var, const char *value, void *c
7373 if (git_config_string (& fmt , var , value ))
7474 return -1 ;
7575
76- if (starts_with (fmt , "format:" ) || starts_with (fmt , "tformat:" )) {
77- commit_format -> is_tformat = fmt [0 ] == 't' ;
78- fmt = strchr (fmt , ':' ) + 1 ;
79- } else if (strchr (fmt , '%' ))
76+ if (skip_prefix (fmt , "format:" , & fmt ))
77+ commit_format -> is_tformat = 0 ;
78+ else if (skip_prefix (fmt , "tformat:" , & fmt ) || strchr (fmt , '%' ))
8079 commit_format -> is_tformat = 1 ;
8180 else
8281 commit_format -> is_alias = 1 ;
@@ -157,12 +156,12 @@ void get_commit_format(const char *arg, struct rev_info *rev)
157156 rev -> commit_format = CMIT_FMT_DEFAULT ;
158157 return ;
159158 }
160- if (starts_with (arg , "format:" ) || starts_with ( arg , "tformat:" )) {
161- save_user_format (rev , strchr ( arg , ':' ) + 1 , arg [ 0 ] == 't' );
159+ if (skip_prefix (arg , "format:" , & arg )) {
160+ save_user_format (rev , arg , 0 );
162161 return ;
163162 }
164163
165- if (!* arg || strchr (arg , '%' )) {
164+ if (!* arg || skip_prefix ( arg , "tformat:" , & arg ) || strchr (arg , '%' )) {
166165 save_user_format (rev , arg , 1 );
167166 return ;
168167 }
@@ -809,18 +808,19 @@ static void parse_commit_header(struct format_commit_context *context)
809808 int i ;
810809
811810 for (i = 0 ; msg [i ]; i ++ ) {
811+ const char * name ;
812812 int eol ;
813813 for (eol = i ; msg [eol ] && msg [eol ] != '\n' ; eol ++ )
814814 ; /* do nothing */
815815
816816 if (i == eol ) {
817817 break ;
818- } else if (starts_with (msg + i , "author " )) {
819- context -> author .off = i + 7 ;
820- context -> author .len = eol - i - 7 ;
821- } else if (starts_with (msg + i , "committer " )) {
822- context -> committer .off = i + 10 ;
823- context -> committer .len = eol - i - 10 ;
818+ } else if (skip_prefix (msg + i , "author " , & name )) {
819+ context -> author .off = name - msg ;
820+ context -> author .len = msg + eol - name ;
821+ } else if (skip_prefix (msg + i , "committer " , & name )) {
822+ context -> committer .off = name - msg ;
823+ context -> committer .len = msg + eol - name ;
824824 }
825825 i = eol ;
826826 }
@@ -951,38 +951,34 @@ static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
951951 const char * placeholder ,
952952 struct format_commit_context * c )
953953{
954+ const char * rest = placeholder ;
955+
954956 if (placeholder [1 ] == '(' ) {
955957 const char * begin = placeholder + 2 ;
956958 const char * end = strchr (begin , ')' );
957959 char color [COLOR_MAXLEN ];
958960
959961 if (!end )
960962 return 0 ;
961- if (starts_with (begin , "auto," )) {
963+ if (skip_prefix (begin , "auto," , & begin )) {
962964 if (!want_color (c -> pretty_ctx -> color ))
963965 return end - placeholder + 1 ;
964- begin += 5 ;
965966 }
966967 color_parse_mem (begin ,
967968 end - begin ,
968969 "--pretty format" , color );
969970 strbuf_addstr (sb , color );
970971 return end - placeholder + 1 ;
971972 }
972- if (starts_with (placeholder + 1 , "red" )) {
973+ if (skip_prefix (placeholder + 1 , "red" , & rest ))
973974 strbuf_addstr (sb , GIT_COLOR_RED );
974- return 4 ;
975- } else if (starts_with (placeholder + 1 , "green" )) {
975+ else if (skip_prefix (placeholder + 1 , "green" , & rest ))
976976 strbuf_addstr (sb , GIT_COLOR_GREEN );
977- return 6 ;
978- } else if (starts_with (placeholder + 1 , "blue" )) {
977+ else if (skip_prefix (placeholder + 1 , "blue" , & rest ))
979978 strbuf_addstr (sb , GIT_COLOR_BLUE );
980- return 5 ;
981- } else if (starts_with (placeholder + 1 , "reset" )) {
979+ else if (skip_prefix (placeholder + 1 , "reset" , & rest ))
982980 strbuf_addstr (sb , GIT_COLOR_RESET );
983- return 6 ;
984- } else
985- return 0 ;
981+ return rest - placeholder ;
986982}
987983
988984static size_t parse_padding_placeholder (struct strbuf * sb ,
@@ -1522,7 +1518,7 @@ static void pp_header(struct pretty_print_context *pp,
15221518 int parents_shown = 0 ;
15231519
15241520 for (;;) {
1525- const char * line = * msg_p ;
1521+ const char * name , * line = * msg_p ;
15261522 int linelen = get_one_line (* msg_p );
15271523
15281524 if (!linelen )
@@ -1557,14 +1553,14 @@ static void pp_header(struct pretty_print_context *pp,
15571553 * FULL shows both authors but not dates.
15581554 * FULLER shows both authors and dates.
15591555 */
1560- if (starts_with (line , "author " )) {
1556+ if (skip_prefix (line , "author " , & name )) {
15611557 strbuf_grow (sb , linelen + 80 );
1562- pp_user_info (pp , "Author" , sb , line + 7 , encoding );
1558+ pp_user_info (pp , "Author" , sb , name , encoding );
15631559 }
1564- if (starts_with (line , "committer " ) &&
1560+ if (skip_prefix (line , "committer " , & name ) &&
15651561 (pp -> fmt == CMIT_FMT_FULL || pp -> fmt == CMIT_FMT_FULLER )) {
15661562 strbuf_grow (sb , linelen + 80 );
1567- pp_user_info (pp , "Commit" , sb , line + 10 , encoding );
1563+ pp_user_info (pp , "Commit" , sb , name , encoding );
15681564 }
15691565 }
15701566}
0 commit comments