@matheusbsbs / matheus-bagliano / commits / 7cd52b5b4b
Fork 0

Share color list between graph and show-branch

This also adds the new colors to show-branch that were added a while back for graph output. Signed-off-by: Dan McGee <dpmcgee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dan McGee committed Apr 5, 2011 at 00:40 UTC 7cd52b5b4bf3be1f5d33fed889af186aae1ea7b8
4 files changed +29 -35
builtin/show-branch.c
+3 -13
@@ -12,16 +12,6 @@ static const char* show_branch_usage[] = {
12 };
13
14 static int showbranch_use_color = -1;
15 -static char column_colors[][COLOR_MAXLEN] = {
16 - GIT_COLOR_RED,
17 - GIT_COLOR_GREEN,
18 - GIT_COLOR_YELLOW,
19 - GIT_COLOR_BLUE,
20 - GIT_COLOR_MAGENTA,
21 - GIT_COLOR_CYAN,
22 -};
23 -
24 -#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))
15
16 static int default_num;
17 static int default_alloc;
@@ -37,7 +27,7 @@ static const char **default_arg;
27 static const char *get_color_code(int idx)
28 {
29 if (showbranch_use_color)
40 - return column_colors[idx];
30 + return column_colors_ansi[idx % column_colors_ansi_max];
31 return "";
32 }
33
@@ -892,7 +882,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
882 for (j = 0; j < i; j++)
883 putchar(' ');
884 printf("%s%c%s [%s] ",
895 - get_color_code(i % COLUMN_COLORS_MAX),
885 + get_color_code(i),
886 is_head ? '*' : '!',
887 get_color_reset_code(), ref_name[i]);
888 }
@@ -954,7 +944,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
944 else
945 mark = '+';
946 printf("%s%c%s",
957 - get_color_code(i % COLUMN_COLORS_MAX),
947 + get_color_code(i),
948 mark, get_color_reset_code());
949 }
950 putchar(' ');
color.c
+22
@@ -3,6 +3,28 @@
3
4 int git_use_color_default = 0;
5
6 +/*
7 + * The list of available column colors.
8 + */
9 +const char *column_colors_ansi[] = {
10 + GIT_COLOR_RED,
11 + GIT_COLOR_GREEN,
12 + GIT_COLOR_YELLOW,
13 + GIT_COLOR_BLUE,
14 + GIT_COLOR_MAGENTA,
15 + GIT_COLOR_CYAN,
16 + GIT_COLOR_BOLD_RED,
17 + GIT_COLOR_BOLD_GREEN,
18 + GIT_COLOR_BOLD_YELLOW,
19 + GIT_COLOR_BOLD_BLUE,
20 + GIT_COLOR_BOLD_MAGENTA,
21 + GIT_COLOR_BOLD_CYAN,
22 + GIT_COLOR_RESET,
23 +};
24 +
25 +/* Ignore the RESET at the end when giving the size */
26 +const int column_colors_ansi_max = ARRAY_SIZE(column_colors_ansi) - 1;
27 +
28 static int parse_color(const char *name, int len)
29 {
30 static const char * const color_names[] = {
color.h
+3
@@ -53,6 +53,9 @@ struct strbuf;
53 */
54 extern int git_use_color_default;
55
56 +/* A default list of colors to use for commit graphs and show-branch output */
57 +extern const char *column_colors_ansi[];
58 +extern const int column_colors_ansi_max;
59
60 /*
61 * Use this instead of git_default_config if you need the value of color.ui.
graph.c
+1 -22
@@ -59,27 +59,6 @@ enum graph_state {
59 GRAPH_COLLAPSING
60 };
61
62 -/*
63 - * The list of available column colors.
64 - */
65 -static const char *column_colors_ansi[] = {
66 - GIT_COLOR_RED,
67 - GIT_COLOR_GREEN,
68 - GIT_COLOR_YELLOW,
69 - GIT_COLOR_BLUE,
70 - GIT_COLOR_MAGENTA,
71 - GIT_COLOR_CYAN,
72 - GIT_COLOR_BOLD_RED,
73 - GIT_COLOR_BOLD_GREEN,
74 - GIT_COLOR_BOLD_YELLOW,
75 - GIT_COLOR_BOLD_BLUE,
76 - GIT_COLOR_BOLD_MAGENTA,
77 - GIT_COLOR_BOLD_CYAN,
78 - GIT_COLOR_RESET,
79 -};
80 -
81 -#define COLUMN_COLORS_ANSI_MAX (ARRAY_SIZE(column_colors_ansi) - 1)
82 -
62 static const char **column_colors;
63 static unsigned short column_colors_max;
64
@@ -228,7 +207,7 @@ struct git_graph *graph_init(struct rev_info *opt)
207
208 if (!column_colors)
209 graph_set_column_colors(column_colors_ansi,
231 - COLUMN_COLORS_ANSI_MAX);
210 + column_colors_ansi_max);
211
212 graph->commit = NULL;
213 graph->revs = opt;