static int parse_push_recurse(const char *opt, const char *arg, int die_on_error) { switch (git_parse_maybe_bool(arg)) { case 1: /* There's no simple "on" value when pushing */ if (die_on_error) die("bad %s argument: %s", opt, arg); else return RECURSE_SUBMODULES_ERROR; case 0: return RECURSE_SUBMODULES_OFF; default: if (!strcmp(arg, "on-demand")) return RECURSE_SUBMODULES_ON_DEMAND; else if (!strcmp(arg, "check")) return RECURSE_SUBMODULES_CHECK; else if (!strcmp(arg, "only")) return RECURSE_SUBMODULES_ONLY; else if (die_on_error) die("bad %s argument: %s", opt, arg); else return RECURSE_SUBMODULES_ERROR; } }
static int git_push_config(const char *k, const char *v, void *cb) { 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; } return git_default_config(k, v, NULL); }
static int parse_update_recurse(const char *opt, const char *arg, int die_on_error) { switch (git_parse_maybe_bool(arg)) { case 1: return RECURSE_SUBMODULES_ON; case 0: return RECURSE_SUBMODULES_OFF; default: if (die_on_error) die("bad %s argument: %s", opt, arg); return RECURSE_SUBMODULES_ERROR; } }
static int fn_init(void) { int want = tr2_dst_trace_want(&tr2dst_normal); int want_brief; char *brief; if (!want) return want; brief = getenv(TR2_ENVVAR_NORMAL_BRIEF); if (brief && *brief && ((want_brief = git_parse_maybe_bool(brief)) != -1)) tr2env_normal_brief = want_brief; return want; }
static int pager_command_config(const char *var, const char *value, void *vdata) { struct pager_command_config_data *data = vdata; const char *cmd; if (skip_prefix(var, "pager.", &cmd) && !strcmp(cmd, data->cmd)) { int b = git_parse_maybe_bool(value); if (b >= 0) data->want = b; else { data->want = 1; data->value = xstrdup(value); } } return 0; }
static int parse_fetch_recurse(const char *opt, const char *arg, int die_on_error) { switch (git_parse_maybe_bool(arg)) { case 1: return RECURSE_SUBMODULES_ON; case 0: return RECURSE_SUBMODULES_OFF; default: if (!strcmp(arg, "on-demand")) return RECURSE_SUBMODULES_ON_DEMAND; if (die_on_error) die("bad %s argument: %s", opt, arg); else return RECURSE_SUBMODULES_ERROR; } }
/** * If pull.ff is unset, returns NULL. If pull.ff is "true", returns "--ff". If * pull.ff is "false", returns "--no-ff". If pull.ff is "only", returns * "--ff-only". Otherwise, if pull.ff is set to an invalid value, die with an * error. */ static const char *config_get_ff(void) { const char *value; if (git_config_get_value("pull.ff", &value)) return NULL; switch (git_parse_maybe_bool(value)) { case 0: return "--no-ff"; case 1: return "--ff"; } if (!strcmp(value, "only")) return "--ff-only"; die(_("Invalid value for pull.ff: %s"), value); }
/** * Parses the value of --rebase. If value is a false value, returns * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is * "preserve", returns REBASE_PRESERVE. If value is a invalid value, dies with * a fatal error if fatal is true, otherwise returns REBASE_INVALID. */ static enum rebase_type parse_config_rebase(const char *key, const char *value, int fatal) { int v = git_parse_maybe_bool(value); if (!v) return REBASE_FALSE; else if (v > 0) return REBASE_TRUE; else if (!strcmp(value, "preserve")) return REBASE_PRESERVE; else if (!strcmp(value, "interactive")) return REBASE_INTERACTIVE; if (fatal) die(_("Invalid value for %s: %s"), key, value); else error(_("Invalid value for %s: %s"), key, value); return REBASE_INVALID; }
int option_parse_push_signed(const struct option *opt, const char *arg, int unset) { if (unset) { *(int *)(opt->value) = SEND_PACK_PUSH_CERT_NEVER; return 0; } switch (git_parse_maybe_bool(arg)) { case 1: *(int *)(opt->value) = SEND_PACK_PUSH_CERT_ALWAYS; return 0; case 0: *(int *)(opt->value) = SEND_PACK_PUSH_CERT_NEVER; return 0; } if (!strcasecmp("if-asked", arg)) { *(int *)(opt->value) = SEND_PACK_PUSH_CERT_IF_ASKED; return 0; } die("bad %s argument: %s", opt->long_name, arg); }