MCPcopy Create free account
hub / github.com/git/git / parse_color

Function parse_color

pretty.c:1063–1113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1061}
1062
1063static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
1064 const char *placeholder,
1065 struct format_commit_context *c)
1066{
1067 const char *rest = placeholder;
1068 const char *basic_color = NULL;
1069
1070 if (placeholder[1] == '(') {
1071 const char *begin = placeholder + 2;
1072 const char *end = strchr(begin, ')');
1073 char color[COLOR_MAXLEN];
1074
1075 if (!end)
1076 return 0;
1077
1078 if (skip_prefix(begin, "auto,", &begin)) {
1079 if (!want_color(c->pretty_ctx->color))
1080 return end - placeholder + 1;
1081 } else if (skip_prefix(begin, "always,", &begin)) {
1082 /* nothing to do; we do not respect want_color at all */
1083 } else {
1084 /* the default is the same as "auto" */
1085 if (!want_color(c->pretty_ctx->color))
1086 return end - placeholder + 1;
1087 }
1088
1089 if (color_parse_mem(begin, end - begin, color) < 0)
1090 die(_("unable to parse --pretty format"));
1091 strbuf_addstr(sb, color);
1092 return end - placeholder + 1;
1093 }
1094
1095 /*
1096 * We handle things like "%C(red)" above; for historical reasons, there
1097 * are a few colors that can be specified without parentheses (and
1098 * they cannot support things like "auto" or "always" at all).
1099 */
1100 if (skip_prefix(placeholder + 1, "red", &rest))
1101 basic_color = GIT_COLOR_RED;
1102 else if (skip_prefix(placeholder + 1, "green", &rest))
1103 basic_color = GIT_COLOR_GREEN;
1104 else if (skip_prefix(placeholder + 1, "blue", &rest))
1105 basic_color = GIT_COLOR_BLUE;
1106 else if (skip_prefix(placeholder + 1, "reset", &rest))
1107 basic_color = GIT_COLOR_RESET;
1108
1109 if (basic_color && want_color(c->pretty_ctx->color))
1110 strbuf_addstr(sb, basic_color);
1111
1112 return rest - placeholder;
1113}
1114
1115static size_t parse_padding_placeholder(const char *placeholder,
1116 struct format_commit_context *c)

Callers 1

format_commit_oneFunction · 0.70

Calls 3

color_parse_memFunction · 0.85
strbuf_addstrFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected