summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2009-01-17 10:38:46 -0500
committerJunio C Hamano <gitster@pobox.com>2009-01-17 18:04:24 -0800
commitc002922adce90b69ac56a86eeb77b249afa88eb2 (patch)
tree7772108654e9729079ebdbac302f76cb272fc977 /pretty.c
parent5ef8d77a752884f3c5fad9f143ce5cc72ff1340c (diff)
downloadgit-c002922adce90b69ac56a86eeb77b249afa88eb2.tar.gz
expand --pretty=format color options
Currently, the only colors available to --pretty=format users are red, green, and blue. Rather than expand it with a few new colors, this patch makes the usual config color syntax available, including more colors, backgrounds, and attributes. Because colors are no longer bounded to a single word (e.g., %Cred), this uses a more advanced syntax that features a beginning and end delimiter (but the old syntax still works). So you can now do: git log --pretty=tformat:'%C(yellow)%h%C(reset) %s' to emulate --pretty=oneline, or even git log --pretty=tformat:'%C(cyan magenta bold)%s%C(reset)' if you want to relive the awesomeness of 4-color CGA. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/pretty.c b/pretty.c
index 343dca556c..b1b86202e1 100644
--- a/pretty.c
+++ b/pretty.c
@@ -6,6 +6,7 @@
#include "string-list.h"
#include "mailmap.h"
#include "log-tree.h"
+#include "color.h"
static char *user_format;
@@ -554,6 +555,17 @@ static size_t format_commit_item(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, "\033[31m");
return 4;