I doubt you want these to be static (and allow multiple instances of
the same configuration variable to accumulate). As you defined the
value to be comma-separated colors, users would want the usual "last
one wins" rule to override previous settings, no?
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 <redacted>
---
Compared to v2:
* set_column_colors_by_config() is renamed to set_column_colors()
* no memory leak if the function is called the second time
* proper space trimming since color_parse_mem expects so
* fixed the warning message, giving some context
* at least one test to exercise the code
* I'm not going with the cumulative behavior because I think that's
just harder to manage colors, and we would need a way to remove
colors from the config too.
Documentation/config.txt | 4 ++++
graph.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
t/t4202-log.sh | 22 ++++++++++++++++++++++
3 files changed, 70 insertions(+), 2 deletions(-)
@@ -2003,6 +2003,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.
@@ -313,6 +313,28 @@ test_expect_success 'log --graph with merge' 'test_cmpexpectactual'+cat>expect.colors<<\EOF+*Mergebranch'side'+<BLUE>|<RESET><CYAN>\<RESET>+<BLUE>|<RESET>*side-2+<BLUE>|<RESET>*side-1+*<CYAN>|<RESET>Second+*<CYAN>|<RESET>sixth+*<CYAN>|<RESET>fifth+*<CYAN>|<RESET>fourth+<CYAN>|<RESET><CYAN>/<RESET>+*third+*second+*initial+EOF++test_expect_success'log --graph with merge with log.graphColors''+test_configlog.graphColors" blue , cyan , red "&&+gitlog--color=always--graph--date-order--pretty=tformat:%s|+test_decode_color|sed"s/ *\$//">actual&&+test_cmpexpect.colorsactual+'+ test_expect_success'log --raw --graph -m with merge''gitlog--raw--graph--oneline-mmaster|head-n500>actual&&grep"initial"actual
From: Jeff King <hidden> Date: 2017-01-09 05:34:55
On Sun, Jan 08, 2017 at 05:13:33PM +0700, Nguyễn Thái Ngọc Duy wrote:
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.
I like this approach much more than the 256-color option.
* I'm not going with the cumulative behavior because I think that's
just harder to manage colors, and we would need a way to remove
colors from the config too.
Yeah, figuring out the list semantics would be a pain. This makes it
hard to exclude a single color, but I think it's more likely somebody
would want to replace the whole set with something that works well
against their background.
+test_expect_success 'log --graph with merge with log.graphColors' '
+ test_config log.graphColors " blue , cyan , red " &&
This funny syntax isn't required, right? It should work with the more
natural:
test_config log.graphColors "blue, cyan, red"
-Peff
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 <redacted>
---
v4:
* rename the function again (and it reads better)
* use argv_array
* fix a bug with two consecutive commas (after spaces are trimmed)
Documentation/config.txt | 4 ++++
graph.c | 43 +++++++++++++++++++++++++++++++++++++++++--
t/t4202-log.sh | 22 ++++++++++++++++++++++
3 files changed, 67 insertions(+), 2 deletions(-)
@@ -2003,6 +2003,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.
@@ -4,6 +4,7 @@#include"graph.h"#include"diff.h"#include"revision.h"+#include"argv-array.h"/* Internal API */
@@ -62,6 +63,45 @@ enum graph_state {staticconstchar**column_colors;staticunsignedshortcolumn_colors_max;+staticvoidread_graph_colors_config(void)+{+staticstructargv_arraycolors=ARGV_ARRAY_INIT;+char*string=NULL;+constchar*end,*start;++if(git_config_get_string("log.graphcolors",&string)){+graph_set_column_colors(column_colors_ansi,+column_colors_ansi_max);+return;+}++argv_array_clear(&colors);+start=string;+end=string+strlen(string);+while(start<end){+constchar*comma=strchrnul(start,',');+charcolor[COLOR_MAXLEN];++while(start<comma&&isspace(*start))+start++;+if(start==comma){+start=comma+1;+continue;+}++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;+}+free(string);+argv_array_push(&colors,GIT_COLOR_RESET);+/* graph_set_column_colors takes a max-index, not a count */+graph_set_column_colors(colors.argv,colors.argc-1);+}+voidgraph_set_column_colors(constchar**colors,unsignedshortcolors_max){column_colors=colors;
v5 moves space trimming to color_parse_mem() from read_graph_colors_config,
which is renamed to parse_graph... because the config reading is moved
back to graph_init.
I think it looks better, but we may be pushing the limits of
argv_array's abuse.
Nguyễn Thái Ngọc Duy (3):
color.c: fix color_parse_mem() with value_len == 0
color.c: trim leading spaces in color_parse_mem()
log --graph: customize the graph lines with config log.graphColors
Documentation/config.txt | 4 ++++
color.c | 10 +++++++++-
graph.c | 42 +++++++++++++++++++++++++++++++++++++++---
t/t4202-log.sh | 22 ++++++++++++++++++++++
4 files changed, 74 insertions(+), 4 deletions(-)
--
2.8.2.524.g6ff3d78
In this code we want to match the word "reset". If len is zero,
strncasecmp() will return zero and we incorrectly assume it's "reset" as
a result.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
color.c | 3 +++
1 file changed, 3 insertions(+)
Normally color_parse_mem() is called from config parser which trims the
leading spaces already. The new caller in the next patch won't. Let's be
tidy and trim leading spaces too (we already trim trailing spaces before
comma).
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
color.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
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 <redacted>
---
Documentation/config.txt | 4 ++++
graph.c | 42 +++++++++++++++++++++++++++++++++++++++---
t/t4202-log.sh | 22 ++++++++++++++++++++++
3 files changed, 65 insertions(+), 3 deletions(-)
@@ -2003,6 +2003,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.
From: Jeff King <hidden> Date: 2017-01-19 16:39:47
On Thu, Jan 19, 2017 at 06:41:21PM +0700, Nguyễn Thái Ngọc Duy wrote:
In this code we want to match the word "reset". If len is zero,
strncasecmp() will return zero and we incorrectly assume it's "reset" as
a result.
This is probably a good idea. This _is_ user-visible, so it's possible
somebody was using empty config as a synonym for "reset". But since it
was never documented, I feel like relying on that is somewhat crazy.
-Peff
From: Jeff King <hidden> Date: 2017-01-19 16:43:07
On Thu, Jan 19, 2017 at 06:41:22PM +0700, Nguyễn Thái Ngọc Duy wrote:
Normally color_parse_mem() is called from config parser which trims the
leading spaces already. The new caller in the next patch won't. Let's be
tidy and trim leading spaces too (we already trim trailing spaces before
comma).
What comma? I don't think that exists until the next patch. :)
I think just trimming from the front is OK, though, because
color_parse_mem() trims trailing whitespace after a word. So either you
have a word and we will trim after it, or you do not (in which case
this will trim everything and hit the !len case you added).
So maybe a better commit message is just:
Normally color_parse_mem() is called from config parser which trims
the leading spaces already. The new caller in the next patch won't.
Let's be tidy and trim leading spaces too (we already trim trailing
spaces after a word).
-Peff
Hrm. At first I thought this would cause memory corrution, because your
argv_array_clear() would try to free() the non-heap array you've stuffed
inside. But you only clear the custom_colors array which actually is
dynamically allocated. This outer one is just here to give uniform
access:
Since there's only one line that cares about the result of "colors",
maybe it would be less confusing to do:
if (!git_config_get-string("log.graphcolors", &string)) {
... parse, etc ...
graph_set_column_colors(colors.argv, colors.argc - 1);
} else {
graph_set_column_colors(column_colors_ansi,
column_colors_ansi_max);
}
-Peff
From: Jeff King <hidden> Date: 2017-01-28 04:07:17
On Thu, Jan 19, 2017 at 11:38:41AM -0500, Jeff King wrote:
On Thu, Jan 19, 2017 at 06:41:21PM +0700, Nguyễn Thái Ngọc Duy wrote:
quoted
In this code we want to match the word "reset". If len is zero,
strncasecmp() will return zero and we incorrectly assume it's "reset" as
a result.
This is probably a good idea. This _is_ user-visible, so it's possible
somebody was using empty config as a synonym for "reset". But since it
was never documented, I feel like relying on that is somewhat crazy.
Hrm. This seems to break the add--interactive script if you do not have
color.diff.plain set:
$ GIT_TRACE=1 git add -p
...
22:58:12.568990 [pid=11401] git.c:387 trace: built-in: git 'config' '--get-color' 'color.diff.plain' ''
fatal: unable to parse default color value
config --get-color color.diff.plain : command returned error: 128
As you can see, the default value the empty string, which is now an
error.
The default in the C code for that value is GIT_COLOR_NORMAL, which
really is the empty string. So I think the old code was buggy to choose
"reset", but the new one is worse because it fails entirely. :)
We probably want something like this instead: