{"thread":{"id":"13383","subject":"[PATCH] Add color.diff.{header,message} formats","startedAt":"2008-05-05T09:38:36Z","lastAt":"2008-05-17T18:34:19Z","messageCount":4,"participants":["Pierre Habouzit","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"76105","messageId":"1209980316-7340-1-git-send-email-madcoder@debian.org","threadId":"13383","inReplyTo":null,"subject":"[PATCH] Add color.diff.{header,message} formats","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-05-05T09:38:36Z","receivedAt":"2008-05-05T09:38:36Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"The goal is to be able to read git log -p more easily, and commit messages\ntends to meld within the diff. Now it's possible to set e.g.\ncolor.diff.message to 'bold' and read them more easily.\n\nDefaults for those two colors are set to normal color to match previous\nbehavior.\n\nSigned-off-by: Pierre Habouzit <madcoder@debian.org>\n---\n builtin-branch.c      |    2 +-\n builtin-checkout.c    |    2 +-\n builtin-log.c         |    8 ++++----\n builtin-rev-list.c    |    2 +-\n builtin-show-branch.c |    2 +-\n commit.h              |    8 +++++---\n diff.c                |    6 ++++++\n diff.h                |    2 ++\n log-tree.c            |    6 +++---\n pretty.c              |   43 ++++++++++++++++++++++++++++++-------------\n 10 files changed, 54 insertions(+), 27 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 19c508a..c2f4227 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -315,7 +315,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,\n \n \t\tcommit = lookup_commit(item->sha1);\n \t\tif (commit && !parse_commit(commit)) {\n-\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, commit,\n+\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, NULL, commit,\n \t\t\t\t\t    &subject, 0, NULL, NULL, 0, 0);\n \t\t\tsub = subject.buf;\n \t\t}\ndiff --git a/builtin-checkout.c b/builtin-checkout.c\nindex 28722aa..b89851d 100644\n--- a/builtin-checkout.c\n+++ b/builtin-checkout.c\n@@ -142,7 +142,7 @@ static void describe_detached_head(char *msg, struct commit *commit)\n \tstruct strbuf sb;\n \tstrbuf_init(&sb, 0);\n \tparse_commit(commit);\n-\tpretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, 0, \"\", \"\", 0, 0);\n+\tpretty_print_commit(CMIT_FMT_ONELINE, NULL, commit, &sb, 0, \"\", \"\", 0, 0);\n \tfprintf(stderr, \"%s %s... %s\\n\", msg,\n \t\tfind_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);\n \tstrbuf_release(&sb);\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 5e9c256..9efb3ad 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -693,11 +693,11 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \n \tmsg = body;\n \tstrbuf_init(&sb, 0);\n-\tpp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,\n+\tpp_user_info(NULL, CMIT_FMT_EMAIL, &sb, \"\", committer, DATE_RFC2822,\n \t\t     encoding);\n \tpp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,\n \t\t      encoding, need_8bit_cte);\n-\tpp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0);\n+\tpp_remainder(CMIT_FMT_EMAIL, &msg, &sb, \"\", 0);\n \tprintf(\"%s\\n\", sb.buf);\n \n \tstrbuf_release(&sb);\n@@ -1160,8 +1160,8 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)\n \t\tif (verbose) {\n \t\t\tstruct strbuf buf;\n \t\t\tstrbuf_init(&buf, 0);\n-\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, commit,\n-\t\t\t                    &buf, 0, NULL, NULL, 0, 0);\n+\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, &revs.diffopt,\n+\t\t\t                    commit, &buf, 0, NULL, NULL, 0, 0);\n \t\t\tprintf(\"%c %s %s\\n\", sign,\n \t\t\t       sha1_to_hex(commit->object.sha1), buf.buf);\n \t\t\tstrbuf_release(&buf);\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 9199b32..240fc8d 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -103,7 +103,7 @@ static void show_commit(struct commit *commit)\n \tif (REV_DIFF_TST(&revs, VERBOSE_HEADER) && commit->buffer) {\n \t\tstruct strbuf buf;\n \t\tstrbuf_init(&buf, 0);\n-\t\tpretty_print_commit(revs.commit_format, commit,\n+\t\tpretty_print_commit(revs.commit_format, &revs.diffopt, commit,\n \t\t\t\t    &buf, revs.abbrev, NULL, NULL,\n \t\t\t\t    revs.date_mode, 0);\n \t\tif (buf.len)\ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 019abd3..39a8b04 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -265,7 +265,7 @@ static void show_one_commit(struct commit *commit, int no_name)\n \n \tstrbuf_init(&pretty, 0);\n \tif (commit->object.parsed) {\n-\t\tpretty_print_commit(CMIT_FMT_ONELINE, commit,\n+\t\tpretty_print_commit(CMIT_FMT_ONELINE, NULL, commit,\n \t\t\t\t    &pretty, 0, NULL, NULL, 0, 0);\n \t\tpretty_str = pretty.buf;\n \t}\ndiff --git a/commit.h b/commit.h\nindex 2d94d41..6175e0f 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -5,6 +5,7 @@\n #include \"tree.h\"\n #include \"strbuf.h\"\n #include \"decorate.h\"\n+#include \"diff.h\"\n \n struct commit_list {\n \tstruct commit *item;\n@@ -67,13 +68,13 @@ struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */\n extern void get_commit_format(const char *arg, struct rev_info *);\n extern void format_commit_message(const struct commit *commit,\n                                   const void *format, struct strbuf *sb);\n-extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,\n-                                struct strbuf *,\n+extern void pretty_print_commit(enum cmit_fmt fmt, const struct diff_options *dopt,\n+                                const struct commit*, struct strbuf *,\n                                 int abbrev, const char *subject,\n                                 const char *after_subject, enum date_mode,\n \t\t\t\tint need_8bit_cte);\n void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,\n-\t\t   const char *line, enum date_mode dmode,\n+\t\t   const char *color, const char *line, enum date_mode dmode,\n \t\t   const char *encoding);\n void pp_title_line(enum cmit_fmt fmt,\n \t\t   const char **msg_p,\n@@ -85,6 +86,7 @@ void pp_title_line(enum cmit_fmt fmt,\n void pp_remainder(enum cmit_fmt fmt,\n \t\t  const char **msg_p,\n \t\t  struct strbuf *sb,\n+\t\t  const char *color,\n \t\t  int indent);\n \n \ndiff --git a/diff.c b/diff.c\nindex 29c168d..787c91b 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -33,6 +33,8 @@ static char diff_colors[][COLOR_MAXLEN] = {\n \t\"\\033[32m\",\t/* NEW (green) */\n \t\"\\033[33m\",\t/* COMMIT (yellow) */\n \t\"\\033[41m\",\t/* WHITESPACE (red background) */\n+\t\"\",\t        /* HEADER (normal) */\n+\t\"\",         /* COMMIT_MSG (normal) */\n };\n \n static int parse_diff_color_slot(const char *var, int ofs)\n@@ -51,6 +53,10 @@ static int parse_diff_color_slot(const char *var, int ofs)\n \t\treturn DIFF_COMMIT;\n \tif (!strcasecmp(var+ofs, \"whitespace\"))\n \t\treturn DIFF_WHITESPACE;\n+\tif (!strcasecmp(var+ofs, \"header\"))\n+\t\treturn DIFF_HEADER;\n+\tif (!strcasecmp(var+ofs, \"message\"))\n+\t\treturn DIFF_COMMIT_MSG;\n \tdie(\"bad config variable '%s'\", var);\n }\n \ndiff --git a/diff.h b/diff.h\nindex 1fc1939..dba4d5e 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -192,6 +192,8 @@ enum color_diff {\n \tDIFF_FILE_NEW = 5,\n \tDIFF_COMMIT = 6,\n \tDIFF_WHITESPACE = 7,\n+\tDIFF_HEADER = 8,\n+\tDIFF_COMMIT_MSG = 9,\n };\n const char *diff_get_color(int diff_use_color, enum color_diff ix);\n #define diff_get_color_opt(o, ix) \\\ndiff --git a/log-tree.c b/log-tree.c\nindex 2b005a2..3bcb113 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -308,9 +308,9 @@ void show_log(struct rev_info *opt, const char *sep)\n \tstrbuf_init(&msgbuf, 0);\n \tif (need_8bit_cte >= 0)\n \t\tneed_8bit_cte = has_non_ascii(opt->add_signoff);\n-\tpretty_print_commit(opt->commit_format, commit, &msgbuf,\n-\t\t\t    abbrev, subject, extra_headers, opt->date_mode,\n-\t\t\t    need_8bit_cte);\n+\tpretty_print_commit(opt->commit_format, &opt->diffopt, commit,\n+\t                    &msgbuf, abbrev, subject, extra_headers,\n+\t                    opt->date_mode, need_8bit_cte);\n \n \tif (opt->add_signoff)\n \t\tappend_signoff(&msgbuf, opt->add_signoff);\ndiff --git a/pretty.c b/pretty.c\nindex 30c2699..6a67cf4 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -119,7 +119,7 @@ needquote:\n }\n \n void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,\n-\t\t  const char *line, enum date_mode dmode,\n+\t\t  const char *color, const char *line, enum date_mode dmode,\n \t\t  const char *encoding)\n {\n \tchar *date;\n@@ -146,24 +146,25 @@ void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,\n \t\t\tname_tail--;\n \t\tdisplay_name_length = name_tail - line;\n \t\tfiller = \"\";\n+\t\tstrbuf_addstr(sb, color);\n \t\tstrbuf_addstr(sb, \"From: \");\n \t\tadd_rfc2047(sb, line, display_name_length, encoding);\n \t\tstrbuf_add(sb, name_tail, namelen - display_name_length);\n \t\tstrbuf_addch(sb, '\\n');\n \t} else {\n-\t\tstrbuf_addf(sb, \"%s: %.*s%.*s\\n\", what,\n+\t\tstrbuf_addf(sb, \"%s%s: %.*s%.*s\\n\", color, what,\n \t\t\t      (fmt == CMIT_FMT_FULLER) ? 4 : 0,\n \t\t\t      filler, namelen, line);\n \t}\n \tswitch (fmt) {\n \tcase CMIT_FMT_MEDIUM:\n-\t\tstrbuf_addf(sb, \"Date:   %s\\n\", show_date(time, tz, dmode));\n+\t\tstrbuf_addf(sb, \"%sDate:   %s\\n\", color, show_date(time, tz, dmode));\n \t\tbreak;\n \tcase CMIT_FMT_EMAIL:\n-\t\tstrbuf_addf(sb, \"Date: %s\\n\", show_date(time, tz, DATE_RFC2822));\n+\t\tstrbuf_addf(sb, \"%sDate: %s\\n\", color, show_date(time, tz, DATE_RFC2822));\n \t\tbreak;\n \tcase CMIT_FMT_FULLER:\n-\t\tstrbuf_addf(sb, \"%sDate: %s\\n\", what, show_date(time, tz, dmode));\n+\t\tstrbuf_addf(sb, \"%s%sDate: %s\\n\", color, what, show_date(time, tz, dmode));\n \t\tbreak;\n \tdefault:\n \t\t/* notin' */\n@@ -590,6 +591,7 @@ void format_commit_message(const struct commit *commit,\n static void pp_header(enum cmit_fmt fmt,\n \t\t      int abbrev,\n \t\t      enum date_mode dmode,\n+\t\t      const char *color,\n \t\t      const char *encoding,\n \t\t      const struct commit *commit,\n \t\t      const char **msg_p,\n@@ -610,6 +612,7 @@ static void pp_header(enum cmit_fmt fmt,\n \t\t\treturn;\n \n \t\tif (fmt == CMIT_FMT_RAW) {\n+\t\t\tstrbuf_addstr(sb, color);\n \t\t\tstrbuf_add(sb, line, linelen);\n \t\t\tcontinue;\n \t\t}\n@@ -629,6 +632,7 @@ static void pp_header(enum cmit_fmt fmt,\n \t\t\t\t;\n \t\t\t/* with enough slop */\n \t\t\tstrbuf_grow(sb, num * 50 + 20);\n+\t\t\tstrbuf_addstr(sb, color);\n \t\t\tadd_merge_info(fmt, sb, commit, abbrev);\n \t\t\tparents_shown = 1;\n \t\t}\n@@ -640,12 +644,12 @@ static void pp_header(enum cmit_fmt fmt,\n \t\t */\n \t\tif (!memcmp(line, \"author \", 7)) {\n \t\t\tstrbuf_grow(sb, linelen + 80);\n-\t\t\tpp_user_info(\"Author\", fmt, sb, line + 7, dmode, encoding);\n+\t\t\tpp_user_info(\"Author\", fmt, sb, color, line + 7, dmode, encoding);\n \t\t}\n \t\tif (!memcmp(line, \"committer \", 10) &&\n \t\t    (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {\n \t\t\tstrbuf_grow(sb, linelen + 80);\n-\t\t\tpp_user_info(\"Commit\", fmt, sb, line + 10, dmode, encoding);\n+\t\t\tpp_user_info(\"Commit\", fmt, sb, color, line + 10, dmode, encoding);\n \t\t}\n \t}\n }\n@@ -708,6 +712,7 @@ void pp_title_line(enum cmit_fmt fmt,\n void pp_remainder(enum cmit_fmt fmt,\n \t\t  const char **msg_p,\n \t\t  struct strbuf *sb,\n+\t\t  const char *color,\n \t\t  int indent)\n {\n \tint first = 1;\n@@ -728,6 +733,7 @@ void pp_remainder(enum cmit_fmt fmt,\n \t\tfirst = 0;\n \n \t\tstrbuf_grow(sb, linelen + indent + 20);\n+\t\tstrbuf_addstr(sb, color);\n \t\tif (indent) {\n \t\t\tmemset(sb->buf + sb->len, ' ', indent);\n \t\t\tstrbuf_setlen(sb, sb->len + indent);\n@@ -737,7 +743,8 @@ void pp_remainder(enum cmit_fmt fmt,\n \t}\n }\n \n-void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n+void pretty_print_commit(enum cmit_fmt fmt,\n+\t\t\t const struct diff_options *dopt, const struct commit *commit,\n \t\t\t struct strbuf *sb, int abbrev,\n \t\t\t const char *subject, const char *after_subject,\n \t\t\t enum date_mode dmode, int need_8bit_cte)\n@@ -747,6 +754,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \tconst char *msg = commit->buffer;\n \tchar *reencoded;\n \tconst char *encoding;\n+\tconst char *rstcol = dopt ? diff_get_color_opt(dopt, DIFF_RESET) : \"\";\n+\tconst char *hdrcol = dopt ? diff_get_color_opt(dopt, DIFF_HEADER) : \"\";\n+\tconst char *msgcol = dopt ? diff_get_color_opt(dopt, DIFF_COMMIT_MSG) : \"\";\n \n \tif (fmt == CMIT_FMT_USERFORMAT) {\n \t\tformat_commit_message(commit, user_format, sb);\n@@ -789,8 +799,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \t\t}\n \t}\n \n-\tpp_header(fmt, abbrev, dmode, encoding, commit, &msg, sb);\n+\tpp_header(fmt, abbrev, dmode, hdrcol, encoding, commit, &msg, sb);\n \tif (fmt != CMIT_FMT_ONELINE && !subject) {\n+\t\tstrbuf_addstr(sb, rstcol);\n \t\tstrbuf_addch(sb, '\\n');\n \t}\n \n@@ -811,20 +822,26 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n \t\t\t      after_subject, encoding, need_8bit_cte);\n \n \tbeginning_of_body = sb->len;\n-\tif (fmt != CMIT_FMT_ONELINE)\n-\t\tpp_remainder(fmt, &msg, sb, indent);\n+\tif (fmt != CMIT_FMT_ONELINE) {\n+\t\tpp_remainder(fmt, &msg, sb, msgcol, indent);\n+\t\tstrbuf_addstr(sb, rstcol);\n+\t}\n \tstrbuf_rtrim(sb);\n \n \t/* Make sure there is an EOLN for the non-oneline case */\n-\tif (fmt != CMIT_FMT_ONELINE)\n+\tif (fmt != CMIT_FMT_ONELINE) {\n+\t\tstrbuf_addstr(sb, rstcol);\n \t\tstrbuf_addch(sb, '\\n');\n+\t}\n \n \t/*\n \t * The caller may append additional body text in e-mail\n \t * format.  Make sure we did not strip the blank line\n \t * between the header and the body.\n \t */\n-\tif (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)\n+\tif (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body) {\n+\t\tstrbuf_addstr(sb, rstcol);\n \t\tstrbuf_addch(sb, '\\n');\n+\t}\n \tfree(reencoded);\n }\n-- \n1.5.5.1.224.g993e4.dirty\n"},{"id":"77189","messageId":"20080517130739.GA2326@artemis.madism.org","threadId":"13383","inReplyTo":"1209980316-7340-1-git-send-email-madcoder@debian.org","subject":"Re: [PATCH] Add color.diff.{header,message} formats","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-05-17T13:07:39Z","receivedAt":"2008-05-17T13:07:39Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"  Hmmm it seems this patch has been somehow lost somewhere, is there\nanything wrong with it ?\n\nOn Mon, May 05, 2008 at 09:38:36AM +0000, Pierre Habouzit wrote:\n> The goal is to be able to read git log -p more easily, and commit messages\n> tends to meld within the diff. Now it's possible to set e.g.\n> color.diff.message to 'bold' and read them more easily.\n> \n> Defaults for those two colors are set to normal color to match previous\n> behavior.\n> \n> Signed-off-by: Pierre Habouzit <madcoder@debian.org>\n> ---\n>  builtin-branch.c      |    2 +-\n>  builtin-checkout.c    |    2 +-\n>  builtin-log.c         |    8 ++++----\n>  builtin-rev-list.c    |    2 +-\n>  builtin-show-branch.c |    2 +-\n>  commit.h              |    8 +++++---\n>  diff.c                |    6 ++++++\n>  diff.h                |    2 ++\n>  log-tree.c            |    6 +++---\n>  pretty.c              |   43 ++++++++++++++++++++++++++++++-------------\n>  10 files changed, 54 insertions(+), 27 deletions(-)\n> \n> diff --git a/builtin-branch.c b/builtin-branch.c\n> index 19c508a..c2f4227 100644\n> --- a/builtin-branch.c\n> +++ b/builtin-branch.c\n> @@ -315,7 +315,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,\n>  \n>  \t\tcommit = lookup_commit(item->sha1);\n>  \t\tif (commit && !parse_commit(commit)) {\n> -\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, commit,\n> +\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, NULL, commit,\n>  \t\t\t\t\t    &subject, 0, NULL, NULL, 0, 0);\n>  \t\t\tsub = subject.buf;\n>  \t\t}\n> diff --git a/builtin-checkout.c b/builtin-checkout.c\n> index 28722aa..b89851d 100644\n> --- a/builtin-checkout.c\n> +++ b/builtin-checkout.c\n> @@ -142,7 +142,7 @@ static void describe_detached_head(char *msg, struct commit *commit)\n>  \tstruct strbuf sb;\n>  \tstrbuf_init(&sb, 0);\n>  \tparse_commit(commit);\n> -\tpretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, 0, \"\", \"\", 0, 0);\n> +\tpretty_print_commit(CMIT_FMT_ONELINE, NULL, commit, &sb, 0, \"\", \"\", 0, 0);\n>  \tfprintf(stderr, \"%s %s... %s\\n\", msg,\n>  \t\tfind_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);\n>  \tstrbuf_release(&sb);\n> diff --git a/builtin-log.c b/builtin-log.c\n> index 5e9c256..9efb3ad 100644\n> --- a/builtin-log.c\n> +++ b/builtin-log.c\n> @@ -693,11 +693,11 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n>  \n>  \tmsg = body;\n>  \tstrbuf_init(&sb, 0);\n> -\tpp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,\n> +\tpp_user_info(NULL, CMIT_FMT_EMAIL, &sb, \"\", committer, DATE_RFC2822,\n>  \t\t     encoding);\n>  \tpp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,\n>  \t\t      encoding, need_8bit_cte);\n> -\tpp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0);\n> +\tpp_remainder(CMIT_FMT_EMAIL, &msg, &sb, \"\", 0);\n>  \tprintf(\"%s\\n\", sb.buf);\n>  \n>  \tstrbuf_release(&sb);\n> @@ -1160,8 +1160,8 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)\n>  \t\tif (verbose) {\n>  \t\t\tstruct strbuf buf;\n>  \t\t\tstrbuf_init(&buf, 0);\n> -\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, commit,\n> -\t\t\t                    &buf, 0, NULL, NULL, 0, 0);\n> +\t\t\tpretty_print_commit(CMIT_FMT_ONELINE, &revs.diffopt,\n> +\t\t\t                    commit, &buf, 0, NULL, NULL, 0, 0);\n>  \t\t\tprintf(\"%c %s %s\\n\", sign,\n>  \t\t\t       sha1_to_hex(commit->object.sha1), buf.buf);\n>  \t\t\tstrbuf_release(&buf);\n> diff --git a/builtin-rev-list.c b/builtin-rev-list.c\n> index 9199b32..240fc8d 100644\n> --- a/builtin-rev-list.c\n> +++ b/builtin-rev-list.c\n> @@ -103,7 +103,7 @@ static void show_commit(struct commit *commit)\n>  \tif (REV_DIFF_TST(&revs, VERBOSE_HEADER) && commit->buffer) {\n>  \t\tstruct strbuf buf;\n>  \t\tstrbuf_init(&buf, 0);\n> -\t\tpretty_print_commit(revs.commit_format, commit,\n> +\t\tpretty_print_commit(revs.commit_format, &revs.diffopt, commit,\n>  \t\t\t\t    &buf, revs.abbrev, NULL, NULL,\n>  \t\t\t\t    revs.date_mode, 0);\n>  \t\tif (buf.len)\n> diff --git a/builtin-show-branch.c b/builtin-show-branch.c\n> index 019abd3..39a8b04 100644\n> --- a/builtin-show-branch.c\n> +++ b/builtin-show-branch.c\n> @@ -265,7 +265,7 @@ static void show_one_commit(struct commit *commit, int no_name)\n>  \n>  \tstrbuf_init(&pretty, 0);\n>  \tif (commit->object.parsed) {\n> -\t\tpretty_print_commit(CMIT_FMT_ONELINE, commit,\n> +\t\tpretty_print_commit(CMIT_FMT_ONELINE, NULL, commit,\n>  \t\t\t\t    &pretty, 0, NULL, NULL, 0, 0);\n>  \t\tpretty_str = pretty.buf;\n>  \t}\n> diff --git a/commit.h b/commit.h\n> index 2d94d41..6175e0f 100644\n> --- a/commit.h\n> +++ b/commit.h\n> @@ -5,6 +5,7 @@\n>  #include \"tree.h\"\n>  #include \"strbuf.h\"\n>  #include \"decorate.h\"\n> +#include \"diff.h\"\n>  \n>  struct commit_list {\n>  \tstruct commit *item;\n> @@ -67,13 +68,13 @@ struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */\n>  extern void get_commit_format(const char *arg, struct rev_info *);\n>  extern void format_commit_message(const struct commit *commit,\n>                                    const void *format, struct strbuf *sb);\n> -extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,\n> -                                struct strbuf *,\n> +extern void pretty_print_commit(enum cmit_fmt fmt, const struct diff_options *dopt,\n> +                                const struct commit*, struct strbuf *,\n>                                  int abbrev, const char *subject,\n>                                  const char *after_subject, enum date_mode,\n>  \t\t\t\tint need_8bit_cte);\n>  void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,\n> -\t\t   const char *line, enum date_mode dmode,\n> +\t\t   const char *color, const char *line, enum date_mode dmode,\n>  \t\t   const char *encoding);\n>  void pp_title_line(enum cmit_fmt fmt,\n>  \t\t   const char **msg_p,\n> @@ -85,6 +86,7 @@ void pp_title_line(enum cmit_fmt fmt,\n>  void pp_remainder(enum cmit_fmt fmt,\n>  \t\t  const char **msg_p,\n>  \t\t  struct strbuf *sb,\n> +\t\t  const char *color,\n>  \t\t  int indent);\n>  \n>  \n> diff --git a/diff.c b/diff.c\n> index 29c168d..787c91b 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -33,6 +33,8 @@ static char diff_colors[][COLOR_MAXLEN] = {\n>  \t\"\\033[32m\",\t/* NEW (green) */\n>  \t\"\\033[33m\",\t/* COMMIT (yellow) */\n>  \t\"\\033[41m\",\t/* WHITESPACE (red background) */\n> +\t\"\",\t        /* HEADER (normal) */\n> +\t\"\",         /* COMMIT_MSG (normal) */\n>  };\n>  \n>  static int parse_diff_color_slot(const char *var, int ofs)\n> @@ -51,6 +53,10 @@ static int parse_diff_color_slot(const char *var, int ofs)\n>  \t\treturn DIFF_COMMIT;\n>  \tif (!strcasecmp(var+ofs, \"whitespace\"))\n>  \t\treturn DIFF_WHITESPACE;\n> +\tif (!strcasecmp(var+ofs, \"header\"))\n> +\t\treturn DIFF_HEADER;\n> +\tif (!strcasecmp(var+ofs, \"message\"))\n> +\t\treturn DIFF_COMMIT_MSG;\n>  \tdie(\"bad config variable '%s'\", var);\n>  }\n>  \n> diff --git a/diff.h b/diff.h\n> index 1fc1939..dba4d5e 100644\n> --- a/diff.h\n> +++ b/diff.h\n> @@ -192,6 +192,8 @@ enum color_diff {\n>  \tDIFF_FILE_NEW = 5,\n>  \tDIFF_COMMIT = 6,\n>  \tDIFF_WHITESPACE = 7,\n> +\tDIFF_HEADER = 8,\n> +\tDIFF_COMMIT_MSG = 9,\n>  };\n>  const char *diff_get_color(int diff_use_color, enum color_diff ix);\n>  #define diff_get_color_opt(o, ix) \\\n> diff --git a/log-tree.c b/log-tree.c\n> index 2b005a2..3bcb113 100644\n> --- a/log-tree.c\n> +++ b/log-tree.c\n> @@ -308,9 +308,9 @@ void show_log(struct rev_info *opt, const char *sep)\n>  \tstrbuf_init(&msgbuf, 0);\n>  \tif (need_8bit_cte >= 0)\n>  \t\tneed_8bit_cte = has_non_ascii(opt->add_signoff);\n> -\tpretty_print_commit(opt->commit_format, commit, &msgbuf,\n> -\t\t\t    abbrev, subject, extra_headers, opt->date_mode,\n> -\t\t\t    need_8bit_cte);\n> +\tpretty_print_commit(opt->commit_format, &opt->diffopt, commit,\n> +\t                    &msgbuf, abbrev, subject, extra_headers,\n> +\t                    opt->date_mode, need_8bit_cte);\n>  \n>  \tif (opt->add_signoff)\n>  \t\tappend_signoff(&msgbuf, opt->add_signoff);\n> diff --git a/pretty.c b/pretty.c\n> index 30c2699..6a67cf4 100644\n> --- a/pretty.c\n> +++ b/pretty.c\n> @@ -119,7 +119,7 @@ needquote:\n>  }\n>  \n>  void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,\n> -\t\t  const char *line, enum date_mode dmode,\n> +\t\t  const char *color, const char *line, enum date_mode dmode,\n>  \t\t  const char *encoding)\n>  {\n>  \tchar *date;\n> @@ -146,24 +146,25 @@ void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,\n>  \t\t\tname_tail--;\n>  \t\tdisplay_name_length = name_tail - line;\n>  \t\tfiller = \"\";\n> +\t\tstrbuf_addstr(sb, color);\n>  \t\tstrbuf_addstr(sb, \"From: \");\n>  \t\tadd_rfc2047(sb, line, display_name_length, encoding);\n>  \t\tstrbuf_add(sb, name_tail, namelen - display_name_length);\n>  \t\tstrbuf_addch(sb, '\\n');\n>  \t} else {\n> -\t\tstrbuf_addf(sb, \"%s: %.*s%.*s\\n\", what,\n> +\t\tstrbuf_addf(sb, \"%s%s: %.*s%.*s\\n\", color, what,\n>  \t\t\t      (fmt == CMIT_FMT_FULLER) ? 4 : 0,\n>  \t\t\t      filler, namelen, line);\n>  \t}\n>  \tswitch (fmt) {\n>  \tcase CMIT_FMT_MEDIUM:\n> -\t\tstrbuf_addf(sb, \"Date:   %s\\n\", show_date(time, tz, dmode));\n> +\t\tstrbuf_addf(sb, \"%sDate:   %s\\n\", color, show_date(time, tz, dmode));\n>  \t\tbreak;\n>  \tcase CMIT_FMT_EMAIL:\n> -\t\tstrbuf_addf(sb, \"Date: %s\\n\", show_date(time, tz, DATE_RFC2822));\n> +\t\tstrbuf_addf(sb, \"%sDate: %s\\n\", color, show_date(time, tz, DATE_RFC2822));\n>  \t\tbreak;\n>  \tcase CMIT_FMT_FULLER:\n> -\t\tstrbuf_addf(sb, \"%sDate: %s\\n\", what, show_date(time, tz, dmode));\n> +\t\tstrbuf_addf(sb, \"%s%sDate: %s\\n\", color, what, show_date(time, tz, dmode));\n>  \t\tbreak;\n>  \tdefault:\n>  \t\t/* notin' */\n> @@ -590,6 +591,7 @@ void format_commit_message(const struct commit *commit,\n>  static void pp_header(enum cmit_fmt fmt,\n>  \t\t      int abbrev,\n>  \t\t      enum date_mode dmode,\n> +\t\t      const char *color,\n>  \t\t      const char *encoding,\n>  \t\t      const struct commit *commit,\n>  \t\t      const char **msg_p,\n> @@ -610,6 +612,7 @@ static void pp_header(enum cmit_fmt fmt,\n>  \t\t\treturn;\n>  \n>  \t\tif (fmt == CMIT_FMT_RAW) {\n> +\t\t\tstrbuf_addstr(sb, color);\n>  \t\t\tstrbuf_add(sb, line, linelen);\n>  \t\t\tcontinue;\n>  \t\t}\n> @@ -629,6 +632,7 @@ static void pp_header(enum cmit_fmt fmt,\n>  \t\t\t\t;\n>  \t\t\t/* with enough slop */\n>  \t\t\tstrbuf_grow(sb, num * 50 + 20);\n> +\t\t\tstrbuf_addstr(sb, color);\n>  \t\t\tadd_merge_info(fmt, sb, commit, abbrev);\n>  \t\t\tparents_shown = 1;\n>  \t\t}\n> @@ -640,12 +644,12 @@ static void pp_header(enum cmit_fmt fmt,\n>  \t\t */\n>  \t\tif (!memcmp(line, \"author \", 7)) {\n>  \t\t\tstrbuf_grow(sb, linelen + 80);\n> -\t\t\tpp_user_info(\"Author\", fmt, sb, line + 7, dmode, encoding);\n> +\t\t\tpp_user_info(\"Author\", fmt, sb, color, line + 7, dmode, encoding);\n>  \t\t}\n>  \t\tif (!memcmp(line, \"committer \", 10) &&\n>  \t\t    (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER)) {\n>  \t\t\tstrbuf_grow(sb, linelen + 80);\n> -\t\t\tpp_user_info(\"Commit\", fmt, sb, line + 10, dmode, encoding);\n> +\t\t\tpp_user_info(\"Commit\", fmt, sb, color, line + 10, dmode, encoding);\n>  \t\t}\n>  \t}\n>  }\n> @@ -708,6 +712,7 @@ void pp_title_line(enum cmit_fmt fmt,\n>  void pp_remainder(enum cmit_fmt fmt,\n>  \t\t  const char **msg_p,\n>  \t\t  struct strbuf *sb,\n> +\t\t  const char *color,\n>  \t\t  int indent)\n>  {\n>  \tint first = 1;\n> @@ -728,6 +733,7 @@ void pp_remainder(enum cmit_fmt fmt,\n>  \t\tfirst = 0;\n>  \n>  \t\tstrbuf_grow(sb, linelen + indent + 20);\n> +\t\tstrbuf_addstr(sb, color);\n>  \t\tif (indent) {\n>  \t\t\tmemset(sb->buf + sb->len, ' ', indent);\n>  \t\t\tstrbuf_setlen(sb, sb->len + indent);\n> @@ -737,7 +743,8 @@ void pp_remainder(enum cmit_fmt fmt,\n>  \t}\n>  }\n>  \n> -void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n> +void pretty_print_commit(enum cmit_fmt fmt,\n> +\t\t\t const struct diff_options *dopt, const struct commit *commit,\n>  \t\t\t struct strbuf *sb, int abbrev,\n>  \t\t\t const char *subject, const char *after_subject,\n>  \t\t\t enum date_mode dmode, int need_8bit_cte)\n> @@ -747,6 +754,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n>  \tconst char *msg = commit->buffer;\n>  \tchar *reencoded;\n>  \tconst char *encoding;\n> +\tconst char *rstcol = dopt ? diff_get_color_opt(dopt, DIFF_RESET) : \"\";\n> +\tconst char *hdrcol = dopt ? diff_get_color_opt(dopt, DIFF_HEADER) : \"\";\n> +\tconst char *msgcol = dopt ? diff_get_color_opt(dopt, DIFF_COMMIT_MSG) : \"\";\n>  \n>  \tif (fmt == CMIT_FMT_USERFORMAT) {\n>  \t\tformat_commit_message(commit, user_format, sb);\n> @@ -789,8 +799,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n>  \t\t}\n>  \t}\n>  \n> -\tpp_header(fmt, abbrev, dmode, encoding, commit, &msg, sb);\n> +\tpp_header(fmt, abbrev, dmode, hdrcol, encoding, commit, &msg, sb);\n>  \tif (fmt != CMIT_FMT_ONELINE && !subject) {\n> +\t\tstrbuf_addstr(sb, rstcol);\n>  \t\tstrbuf_addch(sb, '\\n');\n>  \t}\n>  \n> @@ -811,20 +822,26 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,\n>  \t\t\t      after_subject, encoding, need_8bit_cte);\n>  \n>  \tbeginning_of_body = sb->len;\n> -\tif (fmt != CMIT_FMT_ONELINE)\n> -\t\tpp_remainder(fmt, &msg, sb, indent);\n> +\tif (fmt != CMIT_FMT_ONELINE) {\n> +\t\tpp_remainder(fmt, &msg, sb, msgcol, indent);\n> +\t\tstrbuf_addstr(sb, rstcol);\n> +\t}\n>  \tstrbuf_rtrim(sb);\n>  \n>  \t/* Make sure there is an EOLN for the non-oneline case */\n> -\tif (fmt != CMIT_FMT_ONELINE)\n> +\tif (fmt != CMIT_FMT_ONELINE) {\n> +\t\tstrbuf_addstr(sb, rstcol);\n>  \t\tstrbuf_addch(sb, '\\n');\n> +\t}\n>  \n>  \t/*\n>  \t * The caller may append additional body text in e-mail\n>  \t * format.  Make sure we did not strip the blank line\n>  \t * between the header and the body.\n>  \t */\n> -\tif (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)\n> +\tif (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body) {\n> +\t\tstrbuf_addstr(sb, rstcol);\n>  \t\tstrbuf_addch(sb, '\\n');\n> +\t}\n>  \tfree(reencoded);\n>  }\n> -- \n> 1.5.5.1.224.g993e4.dirty\n> \n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"77197","messageId":"7vej80dcdc.fsf@gitster.siamese.dyndns.org","threadId":"13383","inReplyTo":"20080517130739.GA2326@artemis.madism.org","subject":"Re: [PATCH] Add color.diff.{header,message} formats","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-05-17T18:17:03Z","receivedAt":"2008-05-17T18:17:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pierre Habouzit <madcoder@debian.org> writes:\n\n>   Hmmm it seems this patch has been somehow lost somewhere, is there\n> anything wrong with it ?\n\nIt may not break anything, and I did not hear anybody on the list who said\nthis breaks soemthing.  But I did not hear anybody on the list who wanted\nto have this except you, either.  At this stage of development, the\nquestion we should be asking is not if there is anything wrong with it,\nbut if there is anything _good_ with it.\n\nIt looks rather widespread compared to a perceived benefit.  Perhaps after\na refactoring to make the parameter to pretty-print-commit a bit more\neasily extensible, the patch might start looking more promising.  I dunno.\n"},{"id":"77198","messageId":"20080517183419.GC16746@artemis.madism.org","threadId":"13383","inReplyTo":"7vej80dcdc.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Add color.diff.{header,message} formats","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-05-17T18:34:19Z","receivedAt":"2008-05-17T18:34:19Z","isPatch":true,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Sat, May 17, 2008 at 06:17:03PM +0000, Junio C Hamano wrote:\n> Pierre Habouzit <madcoder@debian.org> writes:\n> \n> >   Hmmm it seems this patch has been somehow lost somewhere, is there\n> > anything wrong with it ?\n> \n> It may not break anything, and I did not hear anybody on the list who said\n> this breaks soemthing.  But I did not hear anybody on the list who wanted\n> to have this except you, either.  At this stage of development, the\n> question we should be asking is not if there is anything wrong with it,\n> but if there is anything _good_ with it.\n\n  Well the thing is that I (and the few people that made me write the\npatch) find git log -p hard to read, because my eyes tend to not see the\nseparations between two commits. Having a different color for commit\nmessages help a lot.\n\n> It looks rather widespread compared to a perceived benefit.  Perhaps after\n> a refactoring to make the parameter to pretty-print-commit a bit more\n> easily extensible, the patch might start looking more promising.  I dunno.\n\n  Fair enough, I wrote the patch for others, I use it on my git, but I'm\nnot really into doing that amount of work to push it in git.git either …\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"}]}