Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
6e6ed3ea 7f89ad8c

+11 -4
+11 -4
builtin/config.c
··· 547 547 return 0; 548 548 } 549 549 550 - static void get_color(const struct config_location_options *opts, 550 + static int get_color(const struct config_location_options *opts, 551 551 const char *var, const char *def_color) 552 552 { 553 553 struct get_color_config_data data = { 554 554 .get_color_slot = var, 555 555 .parsed_color[0] = '\0', 556 556 }; 557 + int ret; 557 558 558 559 config_with_options(git_get_color_config, &data, 559 560 &opts->source, the_repository, 560 561 &opts->options); 561 562 562 563 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 + } 565 568 } 566 569 570 + ret = 0; 571 + 572 + out: 567 573 fputs(data.parsed_color, stdout); 574 + return ret; 568 575 } 569 576 570 577 struct get_colorbool_config_data { ··· 1390 1397 } 1391 1398 else if (actions == ACTION_GET_COLOR) { 1392 1399 check_argc(argc, 1, 2); 1393 - get_color(&location_opts, argv[0], argv[1]); 1400 + ret = get_color(&location_opts, argv[0], argv[1]); 1394 1401 } 1395 1402 else if (actions == ACTION_GET_COLORBOOL) { 1396 1403 check_argc(argc, 1, 2);