pretty: split color parsing into a separate function
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7e77df39bf
commit
fcabc2d91c
71
pretty.c
71
pretty.c
@ -954,6 +954,44 @@ static int format_reflog_person(struct strbuf *sb,
|
|||||||
return format_person_part(sb, part, ident, strlen(ident), dmode);
|
return format_person_part(sb, part, ident, strlen(ident), dmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t parse_color(struct strbuf *sb, /* in UTF-8 */
|
||||||
|
const char *placeholder,
|
||||||
|
struct format_commit_context *c)
|
||||||
|
{
|
||||||
|
if (placeholder[1] == '(') {
|
||||||
|
const char *begin = placeholder + 2;
|
||||||
|
const char *end = strchr(begin, ')');
|
||||||
|
char color[COLOR_MAXLEN];
|
||||||
|
|
||||||
|
if (!end)
|
||||||
|
return 0;
|
||||||
|
if (!prefixcmp(begin, "auto,")) {
|
||||||
|
if (!want_color(c->pretty_ctx->color))
|
||||||
|
return end - placeholder + 1;
|
||||||
|
begin += 5;
|
||||||
|
}
|
||||||
|
color_parse_mem(begin,
|
||||||
|
end - begin,
|
||||||
|
"--pretty format", color);
|
||||||
|
strbuf_addstr(sb, color);
|
||||||
|
return end - placeholder + 1;
|
||||||
|
}
|
||||||
|
if (!prefixcmp(placeholder + 1, "red")) {
|
||||||
|
strbuf_addstr(sb, GIT_COLOR_RED);
|
||||||
|
return 4;
|
||||||
|
} else if (!prefixcmp(placeholder + 1, "green")) {
|
||||||
|
strbuf_addstr(sb, GIT_COLOR_GREEN);
|
||||||
|
return 6;
|
||||||
|
} else if (!prefixcmp(placeholder + 1, "blue")) {
|
||||||
|
strbuf_addstr(sb, GIT_COLOR_BLUE);
|
||||||
|
return 5;
|
||||||
|
} else if (!prefixcmp(placeholder + 1, "reset")) {
|
||||||
|
strbuf_addstr(sb, GIT_COLOR_RESET);
|
||||||
|
return 6;
|
||||||
|
} else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
|
static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
|
||||||
const char *placeholder,
|
const char *placeholder,
|
||||||
void *context)
|
void *context)
|
||||||
@ -967,38 +1005,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
|
|||||||
/* these are independent of the commit */
|
/* these are independent of the commit */
|
||||||
switch (placeholder[0]) {
|
switch (placeholder[0]) {
|
||||||
case 'C':
|
case 'C':
|
||||||
if (placeholder[1] == '(') {
|
return parse_color(sb, placeholder, c);
|
||||||
const char *begin = placeholder + 2;
|
|
||||||
const char *end = strchr(begin, ')');
|
|
||||||
char color[COLOR_MAXLEN];
|
|
||||||
|
|
||||||
if (!end)
|
|
||||||
return 0;
|
|
||||||
if (!prefixcmp(begin, "auto,")) {
|
|
||||||
if (!want_color(c->pretty_ctx->color))
|
|
||||||
return end - placeholder + 1;
|
|
||||||
begin += 5;
|
|
||||||
}
|
|
||||||
color_parse_mem(begin,
|
|
||||||
end - begin,
|
|
||||||
"--pretty format", color);
|
|
||||||
strbuf_addstr(sb, color);
|
|
||||||
return end - placeholder + 1;
|
|
||||||
}
|
|
||||||
if (!prefixcmp(placeholder + 1, "red")) {
|
|
||||||
strbuf_addstr(sb, GIT_COLOR_RED);
|
|
||||||
return 4;
|
|
||||||
} else if (!prefixcmp(placeholder + 1, "green")) {
|
|
||||||
strbuf_addstr(sb, GIT_COLOR_GREEN);
|
|
||||||
return 6;
|
|
||||||
} else if (!prefixcmp(placeholder + 1, "blue")) {
|
|
||||||
strbuf_addstr(sb, GIT_COLOR_BLUE);
|
|
||||||
return 5;
|
|
||||||
} else if (!prefixcmp(placeholder + 1, "reset")) {
|
|
||||||
strbuf_addstr(sb, GIT_COLOR_RESET);
|
|
||||||
return 6;
|
|
||||||
} else
|
|
||||||
return 0;
|
|
||||||
case 'n': /* newline */
|
case 'n': /* newline */
|
||||||
strbuf_addch(sb, '\n');
|
strbuf_addch(sb, '\n');
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user