Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]>
---
pretty.c | 60 +++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/pretty.c b/pretty.c
index e910679..93c96c2 100644
--- a/pretty.c
+++ b/pretty.c
@@ -863,6 +863,40 @@ static int format_reflog_person(struct strbuf *sb,
return format_person_part(sb, part, ident, strlen(ident), dmode);
}
+static size_t parse_color_placeholder(struct strbuf *sb,
+ const char *placeholder,
+ struct format_commit_context *c)
+{
+ if (placeholder[1] == '(') {
+ const char *end = strchr(placeholder + 2, ')');
+ char color[COLOR_MAXLEN];
+ if (!end)
+ return 0;
+ color_parse_mem(placeholder + 2,
+ end - (placeholder + 2),
+ "--pretty format", color);
+ strbuf_addstr(sb, color);
+ return end - placeholder + 1;
+ }
+ if (!prefixcmp(placeholder + 1, "red")) {
+ strbuf_addstr(sb, GIT_COLOR_RED);
+ return 4;
+ }
+ if (!prefixcmp(placeholder + 1, "green")) {
+ strbuf_addstr(sb, GIT_COLOR_GREEN);
+ return 6;
+ }
+ if (!prefixcmp(placeholder + 1, "blue")) {
+ strbuf_addstr(sb, GIT_COLOR_BLUE);
+ return 5;
+ }
+ if (!prefixcmp(placeholder + 1, "reset")) {
+ strbuf_addstr(sb, GIT_COLOR_RESET);
+ return 6;
+ }
+ return 0;
+}
+
static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
void *context)
{
@@ -875,31 +909,7 @@ static size_t format_commit_one(struct strbuf *sb, const
char *placeholder,
/* these are independent of the commit */
switch (placeholder[0]) {
case 'C':
- if (placeholder[1] == '(') {
- const char *end = strchr(placeholder + 2, ')');
- char color[COLOR_MAXLEN];
- if (!end)
- return 0;
- color_parse_mem(placeholder + 2,
- end - (placeholder + 2),
- "--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;
+ return parse_color_placeholder(sb, placeholder, c);
case 'n': /* newline */
strbuf_addch(sb, '\n');
return 1;
--
1.7.12.1.406.g6ab07c4
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html