Skip to content

Commit 6e6ed3e

Browse files
pks-tgitster
authored andcommitted
builtin/config: do not die in get_color()
When trying to parse an invalid color via `get_color()` we die. We're about to introduce another caller in a subsequent commit though that has its own error handling, so dying is a bit drastic there. Furthermore, the only caller that we already have right now already knows to handle errors in other branches that don't call `get_color()`. Convert the function to instead return an error code to improve its flexibility. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f89ad8 commit 6e6ed3e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

builtin/config.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,24 +547,31 @@ static int git_get_color_config(const char *var, const char *value,
547547
return 0;
548548
}
549549

550-
static void get_color(const struct config_location_options *opts,
550+
static int get_color(const struct config_location_options *opts,
551551
const char *var, const char *def_color)
552552
{
553553
struct get_color_config_data data = {
554554
.get_color_slot = var,
555555
.parsed_color[0] = '\0',
556556
};
557+
int ret;
557558

558559
config_with_options(git_get_color_config, &data,
559560
&opts->source, the_repository,
560561
&opts->options);
561562

562563
if (!data.get_color_found && def_color) {
563-
if (color_parse(def_color, data.parsed_color) < 0)
564-
die(_("unable to parse default color value"));
564+
if (color_parse(def_color, data.parsed_color) < 0) {
565+
ret = error(_("unable to parse default color value"));
566+
goto out;
567+
}
565568
}
566569

570+
ret = 0;
571+
572+
out:
567573
fputs(data.parsed_color, stdout);
574+
return ret;
568575
}
569576

570577
struct get_colorbool_config_data {
@@ -1390,7 +1397,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)
13901397
}
13911398
else if (actions == ACTION_GET_COLOR) {
13921399
check_argc(argc, 1, 2);
1393-
get_color(&location_opts, argv[0], argv[1]);
1400+
ret = get_color(&location_opts, argv[0], argv[1]);
13941401
}
13951402
else if (actions == ACTION_GET_COLORBOOL) {
13961403
check_argc(argc, 1, 2);

0 commit comments

Comments
 (0)