log --decorate: Colorize commit decorations
This makes the decorations stand out more and easier to distinguish and spot because they are colored differently depending on their type. Signed-off-by: Nazri Ramliy <ayiehere@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nazri Ramliy committed
Jun 19, 2010 at 09:37 UTC
67a4b5864f9423ccfe8090365029dae918504830
1 file changed
+33
-1
log-tree.c
+33
-1
@@ -7,6 +7,7 @@
7
#include "reflog-walk.h"
8
#include "refs.h"
9
#include "string-list.h"
10
+#include "color.h"
11
12
struct decoration name_decoration = { "object names" };
13
@@ -19,6 +20,29 @@ enum decoration_type {
20
DECORATION_REF_HEAD,
21
};
22
23
+static char decoration_colors[][COLOR_MAXLEN] = {
24
+ GIT_COLOR_RESET,
25
+ GIT_COLOR_BOLD_GREEN, /* REF_LOCAL */
26
+ GIT_COLOR_BOLD_RED, /* REF_REMOTE */
27
+ GIT_COLOR_BOLD_YELLOW, /* REF_TAG */
28
+ GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */
29
+ GIT_COLOR_BOLD_CYAN, /* REF_HEAD */
30
+};
31
+
32
+static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
33
+{
34
+ if (decorate_use_color)
35
+ return decoration_colors[ix];
36
+ return "";
37
+}
38
+
39
+/*
40
+ * log-tree.c uses DIFF_OPT_TST for determining whether to use color
41
+ * for showing the commit sha1, use the same check for --decorate
42
+ */
43
+#define decorate_get_color_opt(o, ix) \
44
+ decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
45
+
46
static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
47
{
48
int nlen = strlen(name);
@@ -81,6 +105,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
105
{
106
const char *prefix;
107
struct name_decoration *decoration;
108
+ const char *color_commit =
109
+ diff_get_color_opt(&opt->diffopt, DIFF_COMMIT);
110
+ const char *color_reset =
111
+ decorate_get_color_opt(&opt->diffopt, DECORATION_NONE);
112
113
if (opt->show_source && commit->util)
114
printf("\t%s", (char *) commit->util);
@@ -92,9 +120,13 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
120
prefix = " (";
121
while (decoration) {
122
printf("%s", prefix);
123
+ fputs(decorate_get_color_opt(&opt->diffopt, decoration->type),
124
+ stdout);
125
if (decoration->type == DECORATION_REF_TAG)
96
- printf("tag: ");
126
+ fputs("tag: ", stdout);
127
printf("%s", decoration->name);
128
+ fputs(color_reset, stdout);
129
+ fputs(color_commit, stdout);
130
prefix = ", ";
131
decoration = decoration->next;
132
}