path: root/color.c
diff options
authorJeff King <>2009-01-17 15:32:30 (GMT)
committerJunio C Hamano <>2009-01-18 02:03:58 (GMT)
commit5ef8d77a752884f3c5fad9f143ce5cc72ff1340c (patch)
treecc540ee0d68dde1a2a0a25686a131a9ada561e0c /color.c
parent7bbd8d6c139f163ee26b8416cd227408888f31c3 (diff)
color: make it easier for non-config to parse color specs
We have very featureful color-parsing routines which are used for color.diff.* and other options. Let's make it easier to use those routines from other parts of the code. This patch adds a color_parse_mem() helper function which takes a length-bounded string instead of a NUL-terminated one. While the helper is only a few lines long, it is nice to abstract this out so that: - callers don't forget to free() the temporary buffer - right now, it is implemented in terms of color_parse(). But it would be more efficient to reverse this and implement color_parse in terms of color_parse_mem. This also changes the error string for an invalid color not to mention the word "config", since it is not always appropriate (and when it is, the context is obvious since the offending config variable is given). Finally, while we are in the area, we clean up the parameter names in the declaration of color_parse; the var and value parameters were reversed from the actual implementation. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'color.c')
1 files changed, 8 insertions, 1 deletions
diff --git a/color.c b/color.c
index fc0b72a..54a3da1 100644
--- a/color.c
+++ b/color.c
@@ -115,7 +115,7 @@ void color_parse(const char *value, const char *var, char *dst)
*dst = 0;
- die("bad config value '%s' for variable '%s'", value, var);
+ die("bad color value '%s' for variable '%s'", value, var);
int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
@@ -191,3 +191,10 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)
return r;
+void color_parse_mem(const char *value, int len, const char *var, char *dst)
+ char *tmp = xmemdupz(value, len);
+ color_parse(tmp, var, dst);
+ free(tmp);