git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 4/5] config.c: introduce 'git_config_color' to parse ANSI colors

From
Taylor Blau <me@ttaylorr.com>
Date
Apr 26, 2018, 05:58 UTC
Message-ID
<bb9a3e13d26c3986dc91fea8e73a879602701b1e.1524722247.git.me@ttaylorr.com>
In-Reply-To
<cover.1524722247.git.me@ttaylorr.com>

In preparation for adding `--type=color` to the `git-config(1)` builtin, let's introduce a color parsing utility, `git_config_color` in a similar fashion to `git_config_<type>`.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 config.c | 10 ++++++++++
 config.h |  1 +
 2 files changed, 11 insertions(+)
diff --git a/config.c b/config.c
index 62c56099bf..d14813bef7 100644
--- a/config.c
+++ b/config.c
@@ -16,6 +16,7 @@
 #include "string-list.h"
 #include "utf8.h"
 #include "dir.h"
+#include "color.h"
 
 struct config_source {
 	struct config_source *prev;
@@ -1000,6 +1001,15 @@ int git_config_expiry_date(timestamp_t *timestamp, const char *var, const char *
 	return 0;
 }
 
+int git_config_color(char *dest, const char *var, const char *value)
+{
+	if (!value)
+		return config_error_nonbool(var);
+	if (color_parse(value, dest) < 0)
+		return -1;
+	return 0;
+}
+
 static int git_default_core_config(const char *var, const char *value)
 {
 	/* This needs a better name */
diff --git a/config.h b/config.h
index ef70a9cac1..0e060779d9 100644
--- a/config.h
+++ b/config.h
@@ -59,6 +59,7 @@ extern int git_config_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
 extern int git_config_expiry_date(timestamp_t *, const char *, const char *);
+extern int git_config_color(char *, const char *, const char *);
 extern int git_config_set_in_file_gently(const char *, const char *, const char *);
 extern void git_config_set_in_file(const char *, const char *, const char *);
 extern int git_config_set_gently(const char *, const char *);
-- 
2.17.0
Previous: Taylor BlauNext: Taylor Blau
Message 18 of 20 in “builtin/config.c: combined series '--type', '--default'”
  1. 0/5 builtin/config.c: combined series '--type', '--default'Taylor Blau, Apr 26, 2018
  2. 1/5 builtin/config.c: treat type specifiers singularlyTaylor Blau, Apr 26, 2018
  3. 2/5 builtin/config.c: support `--type=<type>` as preferred alias for `--type`Taylor Blau, Apr 26, 2018
  4. Junio C HamanoApr 26, 2018
  5. Taylor BlauApr 26, 2018
  6. Eric SunshineApr 27, 2018
  7. 3/5 builtin/config: introduce `--default`Taylor Blau, Apr 26, 2018
  8. 4/5 config.c: introduce 'git_config_color' to parse ANSI colorsTaylor Blau, Apr 26, 2018
  9. 5/5 builtin/config: introduce `color` type specifierTaylor Blau, Apr 26, 2018
  10. Junio C HamanoApr 26, 2018
  11. Taylor BlauApr 26, 2018
  12. 0/5 builtin/config.c: combined series '--type', '--default'Taylor Blau, Apr 26, 2018
  13. 1/5 builtin/config.c: treat type specifiers singularlyTaylor Blau, Apr 26, 2018
  14. 2/5 builtin/config.c: support `--type=<type>` as preferred alias for `--<type>`Taylor Blau, Apr 26, 2018
  15. Junio C HamanoApr 26, 2018
  16. Eric SunshineApr 27, 2018
  17. 3/5 builtin/config: introduce `--default`Taylor Blau, Apr 26, 2018
  18. 4/5 config.c: introduce 'git_config_color' to parse ANSI colorsTaylor Blau, Apr 26, 2018
  19. 5/5 builtin/config: introduce `color` type specifierTaylor Blau, Apr 26, 2018
  20. Eric SunshineApr 27, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.