7
7
#include "reflog-walk.h"
8
8
#include "refs.h"
9
9
#include "string-list.h"
10
+ #include "color.h"
10
11
11
12
struct decoration name_decoration = { "object names" };
12
13
@@ -19,6 +20,29 @@ enum decoration_type {
19
20
DECORATION_REF_HEAD ,
20
21
};
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
+
22
46
static void add_name_decoration (enum decoration_type type , const char * name , struct object * obj )
23
47
{
24
48
int nlen = strlen (name );
@@ -81,6 +105,10 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
81
105
{
82
106
const char * prefix ;
83
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 );
84
112
85
113
if (opt -> show_source && commit -> util )
86
114
printf ("\t%s" , (char * ) commit -> util );
@@ -92,9 +120,13 @@ void show_decorations(struct rev_info *opt, struct commit *commit)
92
120
prefix = " (" ;
93
121
while (decoration ) {
94
122
printf ("%s" , prefix );
123
+ fputs (decorate_get_color_opt (& opt -> diffopt , decoration -> type ),
124
+ stdout );
95
125
if (decoration -> type == DECORATION_REF_TAG )
96
- printf ("tag: " );
126
+ fputs ("tag: " , stdout );
97
127
printf ("%s" , decoration -> name );
128
+ fputs (color_reset , stdout );
129
+ fputs (color_commit , stdout );
98
130
prefix = ", " ;
99
131
decoration = decoration -> next ;
100
132
}
0 commit comments