static int transport_color_config(void) { const char *keys[] = { "color.transport.reset", "color.transport.rejected" }, *key = "color.transport"; char *value; int i; static int initialized; if (initialized) return 0; initialized = 1; if (!git_config_get_string(key, &value)) transport_use_color = git_config_colorbool(key, value); if (!want_color_stderr(transport_use_color)) return 0; for (i = 0; i < ARRAY_SIZE(keys); i++) if (!git_config_get_string(keys[i], &value)) { if (!value) return config_error_nonbool(keys[i]); if (color_parse(value, transport_colors[i]) < 0) return -1; } return 0; }
/* Returns a color setting (GIT_COLOR_NEVER, etc). */ static int use_sideband_colors(void) { static int use_sideband_colors_cached = -1; const char *key = "color.remote"; struct strbuf sb = STRBUF_INIT; char *value; int i; if (use_sideband_colors_cached >= 0) return use_sideband_colors_cached; if (!git_config_get_string(key, &value)) { use_sideband_colors_cached = git_config_colorbool(key, value); } else if (!git_config_get_string("color.ui", &value)) { use_sideband_colors_cached = git_config_colorbool("color.ui", value); } else { use_sideband_colors_cached = GIT_COLOR_AUTO; } for (i = 0; i < ARRAY_SIZE(keywords); i++) { strbuf_reset(&sb); strbuf_addf(&sb, "%s.%s", key, keywords[i].keyword); if (git_config_get_string(sb.buf, &value)) continue; if (color_parse(value, keywords[i].color)) continue; } strbuf_release(&sb); return use_sideband_colors_cached; }
static int git_status_config(const char *k, const char *v, void *cb) { struct wt_status *s = cb; if (starts_with(k, "column.")) return git_column_config(k, v, "status", &s->colopts); if (!strcmp(k, "status.submodulesummary")) { int is_bool; s->submodule_summary = git_config_bool_or_int(k, v, &is_bool); if (is_bool && s->submodule_summary) s->submodule_summary = -1; return 0; } if (!strcmp(k, "status.short")) { if (git_config_bool(k, v)) status_deferred_config.status_format = STATUS_FORMAT_SHORT; else status_deferred_config.status_format = STATUS_FORMAT_NONE; return 0; } if (!strcmp(k, "status.branch")) { status_deferred_config.show_branch = git_config_bool(k, v); return 0; } if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { s->use_color = git_config_colorbool(k, v); return 0; } if (!strcmp(k, "status.displaycommentprefix")) { s->display_comment_prefix = git_config_bool(k, v); return 0; } if (starts_with(k, "status.color.") || starts_with(k, "color.status.")) { int slot = parse_status_slot(k, 13); if (slot < 0) return 0; if (!v) return config_error_nonbool(k); color_parse(v, k, s->color_palette[slot]); return 0; } if (!strcmp(k, "status.relativepaths")) { s->relative_paths = git_config_bool(k, v); return 0; } if (!strcmp(k, "status.showuntrackedfiles")) { if (!v) return config_error_nonbool(k); else if (!strcmp(v, "no")) s->show_untracked_files = SHOW_NO_UNTRACKED_FILES; else if (!strcmp(v, "normal")) s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; else if (!strcmp(v, "all")) s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES; else return error(_("Invalid untracked files mode '%s'"), v); return 0; } return git_diff_ui_config(k, v, NULL); }
static int get_color(int argc, const char **argv) { /* * grab the color setting for the given slot from the configuration, * or parse the default value if missing, and return ANSI color * escape sequence. * * e.g. * git config --get-color color.diff.whitespace "blue reverse" */ const char *def_color = NULL; switch (argc) { default: usage(git_config_set_usage); case 2: def_color = argv[1]; /* fallthru */ case 1: get_color_slot = argv[0]; break; } get_color_found = 0; parsed_color[0] = '\0'; git_config(git_get_color_config); if (!get_color_found && def_color) color_parse(def_color, "command line", parsed_color); fputs(parsed_color, stdout); return 0; }
int parse_decorate_color_config(const char *var, const char *slot_name, const char *value) { int slot = parse_decorate_color_slot(slot_name); if (slot < 0) return 0; if (!value) return config_error_nonbool(var); return color_parse(value, decoration_colors[slot]); }
int parse_decorate_color_config(const char *var, const int ofs, const char *value) { int slot = parse_decorate_color_slot(var + ofs); if (slot < 0) return 0; if (!value) return config_error_nonbool(var); color_parse(value, var, decoration_colors[slot]); return 0; }
static int git_get_color_config(const char *var, const char *value, void *cb) { if (!strcmp(var, get_color_slot)) { if (!value) config_error_nonbool(var); color_parse(value, var, parsed_color); get_color_found = 1; } return 0; }
/* * Read the configuration file once and store it in * the grep_defaults template. */ int grep_config(const char *var, const char *value, void *cb) { struct grep_opt *opt = &grep_defaults; char *color = NULL; if (userdiff_config(var, value) < 0) return -1; if (!strcmp(var, "grep.extendedregexp")) { if (git_config_bool(var, value)) opt->extended_regexp_option = 1; else opt->extended_regexp_option = 0; return 0; } if (!strcmp(var, "grep.patterntype")) { opt->pattern_type_option = parse_pattern_type_arg(var, value); return 0; } if (!strcmp(var, "grep.linenumber")) { opt->linenum = git_config_bool(var, value); return 0; } if (!strcmp(var, "grep.fullname")) { opt->relative = !git_config_bool(var, value); return 0; } if (!strcmp(var, "color.grep")) opt->color = git_config_colorbool(var, value); else if (!strcmp(var, "color.grep.context")) color = opt->color_context; else if (!strcmp(var, "color.grep.filename")) color = opt->color_filename; else if (!strcmp(var, "color.grep.function")) color = opt->color_function; else if (!strcmp(var, "color.grep.linenumber")) color = opt->color_lineno; else if (!strcmp(var, "color.grep.match")) color = opt->color_match; else if (!strcmp(var, "color.grep.selected")) color = opt->color_selected; else if (!strcmp(var, "color.grep.separator")) color = opt->color_sep; if (color) { if (!value) return config_error_nonbool(var); return color_parse(value, color); } return 0; }
static void get_color(const char *def_color) { get_color_found = 0; parsed_color[0] = '\0'; git_config(git_get_color_config, NULL); if (!get_color_found && def_color) color_parse(def_color, "command line", parsed_color); fputs(parsed_color, stdout); }
static void get_color(const char *def_color) { get_color_found = 0; parsed_color[0] = '\0'; git_config_with_options(git_get_color_config, NULL, given_config_file, respect_includes); if (!get_color_found && def_color) color_parse(def_color, "command line", parsed_color); fputs(parsed_color, stdout); }
int fuzz_parse(fuzz_t *fuzz, char *str) { unsigned long color_value = 0; int ret; /* Extract RGB range value */ ret = color_parse(str, &color_value); if ( ret == 0 ) color_set_rgb(color_value, fuzz->color); return ret; }
static int grep_config(const char *var, const char *value, void *cb) { struct grep_opt *opt = cb; char *color = NULL; switch (userdiff_config(var, value)) { case 0: break; case -1: return -1; default: return 0; } if (!strcmp(var, "grep.extendedregexp")) { if (git_config_bool(var, value)) opt->regflags |= REG_EXTENDED; else opt->regflags &= ~REG_EXTENDED; return 0; } if (!strcmp(var, "grep.linenumber")) { opt->linenum = git_config_bool(var, value); return 0; } if (!strcmp(var, "color.grep")) opt->color = git_config_colorbool(var, value, -1); else if (!strcmp(var, "color.grep.context")) color = opt->color_context; else if (!strcmp(var, "color.grep.filename")) color = opt->color_filename; else if (!strcmp(var, "color.grep.function")) color = opt->color_function; else if (!strcmp(var, "color.grep.linenumber")) color = opt->color_lineno; else if (!strcmp(var, "color.grep.match")) color = opt->color_match; else if (!strcmp(var, "color.grep.selected")) color = opt->color_selected; else if (!strcmp(var, "color.grep.separator")) color = opt->color_sep; else return git_color_default_config(var, value, cb); if (color) { if (!value) return config_error_nonbool(var); color_parse(value, var, color); } return 0; }
static int git_branch_config(const char *var, const char *value, void *cb) { if (!strcmp(var, "color.branch")) { branch_use_color = git_config_colorbool(var, value, -1); return 0; } if (!prefixcmp(var, "color.branch.")) { int slot = parse_branch_color_slot(var, 13); if (!value) return config_error_nonbool(var); color_parse(value, var, branch_colors[slot]); return 0; } return git_color_default_config(var, value, cb); }
static int git_branch_config(const char *var, const char *value, void *cb) { if (starts_with(var, "column.")) return git_column_config(var, value, "branch", &colopts); if (!strcmp(var, "color.branch")) { branch_use_color = git_config_colorbool(var, value); return 0; } if (starts_with(var, "color.branch.")) { int slot = parse_branch_color_slot(var, 13); if (slot < 0) return 0; if (!value) return config_error_nonbool(var); color_parse(value, var, branch_colors[slot]); return 0; } return git_color_default_config(var, value, cb); }
static int git_status_config(const char *k, const char *v, void *cb) { struct wt_status *s = cb; if (!strcmp(k, "status.submodulesummary")) { int is_bool; s->submodule_summary = git_config_bool_or_int(k, v, &is_bool); if (is_bool && s->submodule_summary) s->submodule_summary = -1; return 0; } if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { s->use_color = git_config_colorbool(k, v, -1); return 0; } if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) { int slot = parse_status_slot(k, 13); if (slot < 0) return 0; if (!v) return config_error_nonbool(k); color_parse(v, k, s->color_palette[slot]); return 0; } if (!strcmp(k, "status.relativepaths")) { s->relative_paths = git_config_bool(k, v); return 0; } if (!strcmp(k, "status.showuntrackedfiles")) { if (!v) return config_error_nonbool(k); else if (!strcmp(v, "no")) s->show_untracked_files = SHOW_NO_UNTRACKED_FILES; else if (!strcmp(v, "normal")) s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; else if (!strcmp(v, "all")) s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES; else return error("Invalid untracked files mode '%s'", v); return 0; } return git_diff_ui_config(k, v, NULL); }
static int grep_config(const char *var, const char *value, void *cb) { struct grep_opt *opt = cb; switch (userdiff_config(var, value)) { case 0: break; case -1: return -1; default: return 0; } if (!strcmp(var, "color.grep")) { opt->color = git_config_colorbool(var, value, -1); return 0; } if (!strcmp(var, "color.grep.match")) { if (!value) return config_error_nonbool(var); color_parse(value, var, opt->color_match); return 0; } return git_color_default_config(var, value, cb); }
static int git_push_config(const char *k, const char *v, void *cb) { const char *slot_name; int *flags = cb; int status; status = git_gpg_config(k, v, NULL); if (status) return status; if (!strcmp(k, "push.followtags")) { if (git_config_bool(k, v)) *flags |= TRANSPORT_PUSH_FOLLOW_TAGS; else *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS; return 0; } else if (!strcmp(k, "push.gpgsign")) { const char *value; if (!git_config_get_value("push.gpgsign", &value)) { switch (git_parse_maybe_bool(value)) { case 0: set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER); break; case 1: set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS); break; default: if (value && !strcasecmp(value, "if-asked")) set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED); else return error("Invalid value for '%s'", k); } } } else if (!strcmp(k, "push.recursesubmodules")) { const char *value; if (!git_config_get_value("push.recursesubmodules", &value)) recurse_submodules = parse_push_recurse_submodules_arg(k, value); } else if (!strcmp(k, "submodule.recurse")) { int val = git_config_bool(k, v) ? RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF; recurse_submodules = val; } else if (!strcmp(k, "push.pushoption")) { if (!v) return config_error_nonbool(k); else if (!*v) string_list_clear(&push_options_config, 0); else string_list_append(&push_options_config, v); return 0; } else if (!strcmp(k, "color.push")) { push_use_color = git_config_colorbool(k, v); return 0; } else if (skip_prefix(k, "color.push.", &slot_name)) { int slot = parse_push_color_slot(slot_name); if (slot < 0) return 0; if (!v) return config_error_nonbool(k); return color_parse(v, push_colors[slot]); } return git_default_config(k, v, NULL); }