From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2] log --graph: customize the graph lines with config log.graphColors
Date: Sat, 24 Dec 2016 18:38:17 +0700 [thread overview]
Message-ID: <20161224113817.18407-1-pclouds@gmail.com> (raw)
In-Reply-To: <20161220123929.15329-1-pclouds@gmail.com>
If you have a 256 colors terminal (or one with true color support), then
the predefined 12 colors seem limited. On the other hand, you don't want
to draw graph lines with every single color in this mode because the two
colors could look extremely similar. This option allows you to hand pick
the colors you want.
Even with standard terminal, if your background color is neither black
or white, then the graph line may match your background and become
hidden. You can exclude your background color (or simply the colors you
hate) with this.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Sounds like the good first step should be something like this instead
of jumping straight to generating a new color palette automatically.
It's not hard to create a script that generate this config value
based on some jump calculation, if you don't want to manually picking
colors.
Documentation/config.txt | 4 ++++
graph.c | 36 ++++++++++++++++++++++++++++++++++--
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index d51182a..4f26c2a 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2033,6 +2033,10 @@ log.follow::
i.e. it cannot be used to follow multiple files and does not work well
on non-linear history.
+log.graphColors::
+ A list of colors, separated by commas, that can be used to draw
+ history lines in `git log --graph`.
+
log.showRoot::
If true, the initial commit will be shown as a big creation event.
This is equivalent to a diff against an empty tree.
diff --git a/graph.c b/graph.c
index d4e8519..9c58fd1 100644
--- a/graph.c
+++ b/graph.c
@@ -79,6 +79,39 @@ static void graph_show_line_prefix(const struct diff_options *diffopt)
static const char **column_colors;
static unsigned short column_colors_max;
+static void set_column_colors_by_config(void)
+{
+ static char **colors;
+ static int colors_max, colors_alloc;
+ char *string = NULL;
+ const char *end, *start;
+
+ if (git_config_get_string("log.graphcolors", &string)) {
+ graph_set_column_colors(column_colors_ansi,
+ column_colors_ansi_max);
+ return;
+ }
+
+ 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)) {
+ ALLOC_GROW(colors, colors_max + 1, colors_alloc);
+ colors[colors_max++] = xstrdup(color);
+ } else
+ warning(_("ignore invalid color '%.*s'"),
+ (int)(comma - start), start);
+ start = comma + 1;
+ }
+ free(string);
+ ALLOC_GROW(colors, colors_max + 1, colors_alloc);
+ colors[colors_max] = xstrdup(GIT_COLOR_RESET);
+ graph_set_column_colors((const char **)colors, colors_max);
+}
+
void graph_set_column_colors(const char **colors, unsigned short colors_max)
{
column_colors = colors;
@@ -239,8 +272,7 @@ 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);
+ set_column_colors_by_config();
graph->commit = NULL;
graph->revs = opt;
--
2.8.2.524.g6ff3d78
next prev parent reply other threads:[~2016-12-24 11:38 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-20 12:39 [PATCH] log: support 256 colors with --graph=256colors Nguyễn Thái Ngọc Duy
2016-12-20 16:57 ` Jeff King
2016-12-22 9:48 ` Duy Nguyen
2016-12-22 19:06 ` Junio C Hamano
2016-12-25 2:36 ` Duy Nguyen
2016-12-20 17:26 ` Junio C Hamano
2016-12-22 9:38 ` Duy Nguyen
2016-12-24 11:38 ` Nguyễn Thái Ngọc Duy [this message]
2016-12-25 23:02 ` [PATCH v2] log --graph: customize the graph lines with config log.graphColors Junio C Hamano
2017-01-08 10:13 ` [PATCH v3] " Nguyễn Thái Ngọc Duy
2017-01-09 3:05 ` Junio C Hamano
2017-01-09 5:30 ` Jeff King
2017-01-09 10:30 ` Duy Nguyen
2017-01-09 14:23 ` Junio C Hamano
2017-01-09 5:34 ` Jeff King
2017-01-09 10:10 ` Duy Nguyen
2017-01-09 10:32 ` [PATCH v4] " Nguyễn Thái Ngọc Duy
2017-01-09 17:29 ` Junio C Hamano
2017-01-12 12:20 ` Duy Nguyen
2017-01-19 11:41 ` [PATCH v5 0/3] nd/log-graph-configurable-colors Nguyễn Thái Ngọc Duy
2017-01-19 11:41 ` [PATCH v5 1/3] color.c: fix color_parse_mem() with value_len == 0 Nguyễn Thái Ngọc Duy
2017-01-19 16:38 ` Jeff King
2017-01-28 4:07 ` Jeff King
2017-01-19 11:41 ` [PATCH v5 2/3] color.c: trim leading spaces in color_parse_mem() Nguyễn Thái Ngọc Duy
2017-01-19 16:41 ` Jeff King
2017-01-19 18:22 ` Junio C Hamano
2017-01-19 11:41 ` [PATCH v5 3/3] log --graph: customize the graph lines with config log.graphColors Nguyễn Thái Ngọc Duy
2017-01-19 16:51 ` Jeff King
2017-01-19 18:27 ` Junio C Hamano
2017-01-19 19:34 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161224113817.18407-1-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).