Skip to content

Commit 6d2f9ac

Browse files
ttaylorrgitster
authored andcommitted
config.c: introduce 'git_config_color' to parse ANSI colors
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eeaa24b commit 6d2f9ac

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

config.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "string-list.h"
1717
#include "utf8.h"
1818
#include "dir.h"
19+
#include "color.h"
1920

2021
struct config_source {
2122
struct config_source *prev;
@@ -1000,6 +1001,15 @@ int git_config_expiry_date(timestamp_t *timestamp, const char *var, const char *
10001001
return 0;
10011002
}
10021003

1004+
int git_config_color(char *dest, const char *var, const char *value)
1005+
{
1006+
if (!value)
1007+
return config_error_nonbool(var);
1008+
if (color_parse(value, dest) < 0)
1009+
return -1;
1010+
return 0;
1011+
}
1012+
10031013
static int git_default_core_config(const char *var, const char *value)
10041014
{
10051015
/* This needs a better name */

config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern int git_config_bool(const char *, const char *);
5959
extern int git_config_string(const char **, const char *, const char *);
6060
extern int git_config_pathname(const char **, const char *, const char *);
6161
extern int git_config_expiry_date(timestamp_t *, const char *, const char *);
62+
extern int git_config_color(char *, const char *, const char *);
6263
extern int git_config_set_in_file_gently(const char *, const char *, const char *);
6364
extern void git_config_set_in_file(const char *, const char *, const char *);
6465
extern int git_config_set_gently(const char *, const char *);

0 commit comments

Comments
 (0)