@@ -954,6 +954,44 @@ static int format_reflog_person(struct strbuf *sb,
954954 return format_person_part (sb , part , ident , strlen (ident ), dmode );
955955}
956956
957+ static size_t parse_color (struct strbuf * sb , /* in UTF-8 */
958+ const char * placeholder ,
959+ struct format_commit_context * c )
960+ {
961+ if (placeholder [1 ] == '(' ) {
962+ const char * begin = placeholder + 2 ;
963+ const char * end = strchr (begin , ')' );
964+ char color [COLOR_MAXLEN ];
965+
966+ if (!end )
967+ return 0 ;
968+ if (!prefixcmp (begin , "auto," )) {
969+ if (!want_color (c -> pretty_ctx -> color ))
970+ return end - placeholder + 1 ;
971+ begin += 5 ;
972+ }
973+ color_parse_mem (begin ,
974+ end - begin ,
975+ "--pretty format" , color );
976+ strbuf_addstr (sb , color );
977+ return end - placeholder + 1 ;
978+ }
979+ if (!prefixcmp (placeholder + 1 , "red" )) {
980+ strbuf_addstr (sb , GIT_COLOR_RED );
981+ return 4 ;
982+ } else if (!prefixcmp (placeholder + 1 , "green" )) {
983+ strbuf_addstr (sb , GIT_COLOR_GREEN );
984+ return 6 ;
985+ } else if (!prefixcmp (placeholder + 1 , "blue" )) {
986+ strbuf_addstr (sb , GIT_COLOR_BLUE );
987+ return 5 ;
988+ } else if (!prefixcmp (placeholder + 1 , "reset" )) {
989+ strbuf_addstr (sb , GIT_COLOR_RESET );
990+ return 6 ;
991+ } else
992+ return 0 ;
993+ }
994+
957995static size_t format_commit_one (struct strbuf * sb , /* in UTF-8 */
958996 const char * placeholder ,
959997 void * context )
@@ -967,38 +1005,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
9671005 /* these are independent of the commit */
9681006 switch (placeholder [0 ]) {
9691007 case 'C' :
970- if (placeholder [1 ] == '(' ) {
971- const char * begin = placeholder + 2 ;
972- const char * end = strchr (begin , ')' );
973- char color [COLOR_MAXLEN ];
974-
975- if (!end )
976- return 0 ;
977- if (!prefixcmp (begin , "auto," )) {
978- if (!want_color (c -> pretty_ctx -> color ))
979- return end - placeholder + 1 ;
980- begin += 5 ;
981- }
982- color_parse_mem (begin ,
983- end - begin ,
984- "--pretty format" , color );
985- strbuf_addstr (sb , color );
986- return end - placeholder + 1 ;
987- }
988- if (!prefixcmp (placeholder + 1 , "red" )) {
989- strbuf_addstr (sb , GIT_COLOR_RED );
990- return 4 ;
991- } else if (!prefixcmp (placeholder + 1 , "green" )) {
992- strbuf_addstr (sb , GIT_COLOR_GREEN );
993- return 6 ;
994- } else if (!prefixcmp (placeholder + 1 , "blue" )) {
995- strbuf_addstr (sb , GIT_COLOR_BLUE );
996- return 5 ;
997- } else if (!prefixcmp (placeholder + 1 , "reset" )) {
998- strbuf_addstr (sb , GIT_COLOR_RESET );
999- return 6 ;
1000- } else
1001- return 0 ;
1008+ return parse_color (sb , placeholder , c );
10021009 case 'n' : /* newline */
10031010 strbuf_addch (sb , '\n' );
10041011 return 1 ;
0 commit comments