Skip to content

Commit

Permalink
Share color list between graph and show-branch
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
toofishes authored and gitster committed Apr 5, 2011
1 parent 485cdb9 commit 7cd52b5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 35 deletions.
16 changes: 3 additions & 13 deletions builtin/show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ static const char* show_branch_usage[] = {
};

static int showbranch_use_color = -1;
static char column_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RED,
GIT_COLOR_GREEN,
GIT_COLOR_YELLOW,
GIT_COLOR_BLUE,
GIT_COLOR_MAGENTA,
GIT_COLOR_CYAN,
};

#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))

static int default_num;
static int default_alloc;
Expand All @@ -37,7 +27,7 @@ static const char **default_arg;
static const char *get_color_code(int idx)
{
if (showbranch_use_color)
return column_colors[idx];
return column_colors_ansi[idx % column_colors_ansi_max];
return "";
}

Expand Down Expand Up @@ -892,7 +882,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
for (j = 0; j < i; j++)
putchar(' ');
printf("%s%c%s [%s] ",
get_color_code(i % COLUMN_COLORS_MAX),
get_color_code(i),
is_head ? '*' : '!',
get_color_reset_code(), ref_name[i]);
}
Expand Down Expand Up @@ -954,7 +944,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
else
mark = '+';
printf("%s%c%s",
get_color_code(i % COLUMN_COLORS_MAX),
get_color_code(i),
mark, get_color_reset_code());
}
putchar(' ');
Expand Down
22 changes: 22 additions & 0 deletions color.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@

int git_use_color_default = 0;

/*
* The list of available column colors.
*/
const char *column_colors_ansi[] = {
GIT_COLOR_RED,
GIT_COLOR_GREEN,
GIT_COLOR_YELLOW,
GIT_COLOR_BLUE,
GIT_COLOR_MAGENTA,
GIT_COLOR_CYAN,
GIT_COLOR_BOLD_RED,
GIT_COLOR_BOLD_GREEN,
GIT_COLOR_BOLD_YELLOW,
GIT_COLOR_BOLD_BLUE,
GIT_COLOR_BOLD_MAGENTA,
GIT_COLOR_BOLD_CYAN,
GIT_COLOR_RESET,
};

/* Ignore the RESET at the end when giving the size */
const int column_colors_ansi_max = ARRAY_SIZE(column_colors_ansi) - 1;

static int parse_color(const char *name, int len)
{
static const char * const color_names[] = {
Expand Down
3 changes: 3 additions & 0 deletions color.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ struct strbuf;
*/
extern int git_use_color_default;

/* A default list of colors to use for commit graphs and show-branch output */
extern const char *column_colors_ansi[];
extern const int column_colors_ansi_max;

/*
* Use this instead of git_default_config if you need the value of color.ui.
Expand Down
23 changes: 1 addition & 22 deletions graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,6 @@ enum graph_state {
GRAPH_COLLAPSING
};

/*
* The list of available column colors.
*/
static const char *column_colors_ansi[] = {
GIT_COLOR_RED,
GIT_COLOR_GREEN,
GIT_COLOR_YELLOW,
GIT_COLOR_BLUE,
GIT_COLOR_MAGENTA,
GIT_COLOR_CYAN,
GIT_COLOR_BOLD_RED,
GIT_COLOR_BOLD_GREEN,
GIT_COLOR_BOLD_YELLOW,
GIT_COLOR_BOLD_BLUE,
GIT_COLOR_BOLD_MAGENTA,
GIT_COLOR_BOLD_CYAN,
GIT_COLOR_RESET,
};

#define COLUMN_COLORS_ANSI_MAX (ARRAY_SIZE(column_colors_ansi) - 1)

static const char **column_colors;
static unsigned short column_colors_max;

Expand Down Expand Up @@ -228,7 +207,7 @@ struct git_graph *graph_init(struct rev_info *opt)

if (!column_colors)
graph_set_column_colors(column_colors_ansi,
COLUMN_COLORS_ANSI_MAX);
column_colors_ansi_max);

graph->commit = NULL;
graph->revs = opt;
Expand Down

0 comments on commit 7cd52b5

Please sign in to comment.