diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-02-02 13:36:58 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-02-02 13:36:58 -0800 |
commit | 85279e86499501be0f046cb9885ad24fbf9d0b8d (patch) | |
tree | d272cb15ce42c4b57ad685c133a8d1f36e836995 /graph.c | |
parent | cc8364c28be5d15787ad4791afa0da49af78d007 (diff) | |
parent | 512aba261a8951a470147b493c720f205638ba14 (diff) | |
download | git-85279e86499501be0f046cb9885ad24fbf9d0b8d.tar.gz |
Merge branch 'nd/log-graph-configurable-colors'
Some people feel the default set of colors used by "git log --graph"
rather limiting. A mechanism to customize the set of colors has
been introduced.
* nd/log-graph-configurable-colors:
document behavior of empty color name
color_parse_mem: allow empty color spec
log --graph: customize the graph lines with config log.graphColors
color.c: trim leading spaces in color_parse_mem()
color.c: fix color_parse_mem() with value_len == 0
Diffstat (limited to 'graph.c')
-rw-r--r-- | graph.c | 40 |
1 files changed, 37 insertions, 3 deletions
@@ -3,6 +3,7 @@ #include "color.h" #include "graph.h" #include "revision.h" +#include "argv-array.h" /* Internal API */ @@ -79,6 +80,26 @@ static void graph_show_line_prefix(const struct diff_options *diffopt) static const char **column_colors; static unsigned short column_colors_max; +static void parse_graph_colors_config(struct argv_array *colors, const char *string) +{ + const char *end, *start; + + start = string; + end = string + strlen(string); + while (start < end) { + const char *comma = strchrnul(start, ','); + char color[COLOR_MAXLEN]; + + if (!color_parse_mem(start, comma - start, color)) + argv_array_push(colors, color); + else + warning(_("ignore invalid color '%.*s' in log.graphColors"), + (int)(comma - start), start); + start = comma + 1; + } + argv_array_push(colors, GIT_COLOR_RESET); +} + void graph_set_column_colors(const char **colors, unsigned short colors_max) { column_colors = colors; @@ -238,9 +259,22 @@ struct git_graph *graph_init(struct rev_info *opt) { struct git_graph *graph = xmalloc(sizeof(struct git_graph)); - if (!column_colors) - graph_set_column_colors(column_colors_ansi, - column_colors_ansi_max); + if (!column_colors) { + char *string; + if (git_config_get_string("log.graphcolors", &string)) { + /* not configured -- use default */ + graph_set_column_colors(column_colors_ansi, + column_colors_ansi_max); + } else { + static struct argv_array custom_colors = ARGV_ARRAY_INIT; + argv_array_clear(&custom_colors); + parse_graph_colors_config(&custom_colors, string); + free(string); + /* graph_set_column_colors takes a max-index, not a count */ + graph_set_column_colors(custom_colors.argv, + custom_colors.argc - 1); + } + } graph->commit = NULL; graph->revs = opt; |