Skip to content

Commit c659f55

Browse files
peffgitster
authored andcommitted
config: refactor get_colorbool function
For "git config --get-colorbool color.foo", we use a custom callback that looks not only for the key that the user gave us, but also for "diff.color" (for backwards compatibility) and "color.ui" (as a fallback). For the former, we use a custom variable to store the diff.color value. For the latter, though, we store it in the main "git_use_color_default" variable, turning on color.ui for any other parts of git that respect this value. In practice, this doesn't cause any bugs, because git-config runs without caring about git_use_color_default, and then exits. But it crosses module boundaries in an unusual and confusing way, and it makes refactoring color handling harder than it needs to be. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent daa0c3d commit c659f55

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/config.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ static void get_color(const char *def_color)
305305

306306
static int get_colorbool_found;
307307
static int get_diff_color_found;
308+
static int get_color_ui_found;
308309
static int git_get_colorbool_config(const char *var, const char *value,
309310
void *cb)
310311
{
@@ -313,7 +314,7 @@ static int git_get_colorbool_config(const char *var, const char *value,
313314
else if (!strcmp(var, "diff.color"))
314315
get_diff_color_found = git_config_colorbool(var, value);
315316
else if (!strcmp(var, "color.ui"))
316-
git_use_color_default = git_config_colorbool(var, value);
317+
get_color_ui_found = git_config_colorbool(var, value);
317318
return 0;
318319
}
319320

@@ -327,7 +328,7 @@ static int get_colorbool(int print)
327328
if (!strcmp(get_colorbool_slot, "color.diff"))
328329
get_colorbool_found = get_diff_color_found;
329330
if (get_colorbool_found < 0)
330-
get_colorbool_found = git_use_color_default;
331+
get_colorbool_found = get_color_ui_found;
331332
}
332333

333334
get_colorbool_found = want_color(get_colorbool_found);

0 commit comments

Comments
 (0)