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
This commit is contained in:
Junio C Hamano
2017-02-02 13:36:58 -08:00
6 changed files with 97 additions and 5 deletions

40
graph.c
View File

@@ -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;