static void gc_config(void) { const char *value; if (!git_config_get_value("gc.packrefs", &value)) { if (value && !strcmp(value, "notbare")) pack_refs = -1; else pack_refs = git_config_bool("gc.packrefs", value); } git_config_get_int("gc.aggressivewindow", &aggressive_window); git_config_get_int("gc.aggressivedepth", &aggressive_depth); git_config_get_int("gc.auto", &gc_auto_threshold); git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit); git_config_get_bool("gc.autodetach", &detach_auto); if (!git_config_get_string_const("gc.pruneexpire", &prune_expire)) { if (strcmp(prune_expire, "now")) { unsigned long now = approxidate("now"); if (approxidate(prune_expire) >= now) { git_die_config("gc.pruneexpire", _("Invalid gc.pruneexpire: '%s'"), prune_expire); } } } git_config(git_default_config, NULL); }
void list_cmds_by_config(struct string_list *list) { const char *cmd_list; /* * There's no actual repository setup at this point (and even * if there is, we don't really care; only global config * matters). If we accidentally set up a repository, it's ok * too since the caller (git --list-cmds=) should exit shortly * anyway. */ if (git_config_get_string_const("completion.commands", &cmd_list)) return; string_list_sort(list); string_list_remove_duplicates(list, 0); while (*cmd_list) { struct strbuf sb = STRBUF_INIT; const char *p = strchrnul(cmd_list, ' '); strbuf_add(&sb, cmd_list, p - cmd_list); if (*cmd_list == '-') string_list_remove(list, cmd_list + 1, 0); else string_list_insert(list, sb.buf); strbuf_release(&sb); while (*p == ' ') p++; cmd_list = p; } }
void list_cmds_by_config(struct string_list *list) { const char *cmd_list; if (git_config_get_string_const("completion.commands", &cmd_list)) return; string_list_sort(list); string_list_remove_duplicates(list, 0); while (*cmd_list) { struct strbuf sb = STRBUF_INIT; const char *p = strchrnul(cmd_list, ' '); strbuf_add(&sb, cmd_list, p - cmd_list); if (sb.buf[0] == '-') string_list_remove(list, sb.buf + 1, 0); else string_list_insert(list, sb.buf); strbuf_release(&sb); while (*p == ' ') p++; cmd_list = p; } }
static void git_config_date_string(const char *key, const char **output) { if (git_config_get_string_const(key, output)) return; if (strcmp(*output, "now")) { unsigned long now = approxidate("now"); if (approxidate(*output) >= now) git_die_config(key, _("Invalid %s: '%s'"), key, *output); } }
const char *git_sequence_editor(void) { const char *editor = getenv("GIT_SEQUENCE_EDITOR"); if (!editor) git_config_get_string_const("sequence.editor", &editor); if (!editor) editor = git_editor(); return editor; }
static int git_config_get_notes_strategy(const char *key, enum notes_merge_strategy *strategy) { const char *value; if (git_config_get_string_const(key, &value)) return 1; if (parse_notes_merge_strategy(value, strategy)) git_die_config(key, "unknown notes merge strategy %s", value); return 0; }
static const char *get_ssh_command(void) { const char *ssh; if ((ssh = getenv("GIT_SSH_COMMAND"))) return ssh; if (!git_config_get_string_const("core.sshcommand", &ssh)) return ssh; return NULL; }
static void override_ssh_variant(enum ssh_variant *ssh_variant) { const char *variant = getenv("GIT_SSH_VARIANT"); if (!variant && git_config_get_string_const("ssh.variant", &variant)) return; if (!strcmp(variant, "auto")) *ssh_variant = VARIANT_AUTO; else if (!strcmp(variant, "plink")) *ssh_variant = VARIANT_PLINK; else if (!strcmp(variant, "putty")) *ssh_variant = VARIANT_PUTTY; else if (!strcmp(variant, "tortoiseplink")) *ssh_variant = VARIANT_TORTOISEPLINK; else if (!strcmp(variant, "simple")) *ssh_variant = VARIANT_SIMPLE; else *ssh_variant = VARIANT_SSH; }
int cmd_main(int argc, const char **argv) { int i, val; const char *v; const struct string_list *strptr; struct config_set cs; git_configset_init(&cs); if (argc < 2) { fprintf(stderr, "Please, provide a command name on the command-line\n"); goto exit1; } else if (argc == 3 && !strcmp(argv[1], "get_value")) { if (!git_config_get_value(argv[2], &v)) { if (!v) printf("(NULL)\n"); else printf("%s\n", v); goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } } else if (argc == 3 && !strcmp(argv[1], "get_value_multi")) { strptr = git_config_get_value_multi(argv[2]); if (strptr) { for (i = 0; i < strptr->nr; i++) { v = strptr->items[i].string; if (!v) printf("(NULL)\n"); else printf("%s\n", v); } goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } } else if (argc == 3 && !strcmp(argv[1], "get_int")) { if (!git_config_get_int(argv[2], &val)) { printf("%d\n", val); goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } } else if (argc == 3 && !strcmp(argv[1], "get_bool")) { if (!git_config_get_bool(argv[2], &val)) { printf("%d\n", val); goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } } else if (argc == 3 && !strcmp(argv[1], "get_string")) { if (!git_config_get_string_const(argv[2], &v)) { printf("%s\n", v); goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } } else if (!strcmp(argv[1], "configset_get_value")) { for (i = 3; i < argc; i++) { int err; if ((err = git_configset_add_file(&cs, argv[i]))) { fprintf(stderr, "Error (%d) reading configuration file %s.\n", err, argv[i]); goto exit2; } } if (!git_configset_get_value(&cs, argv[2], &v)) { if (!v) printf("(NULL)\n"); else printf("%s\n", v); goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } } else if (!strcmp(argv[1], "configset_get_value_multi")) { for (i = 3; i < argc; i++) { int err; if ((err = git_configset_add_file(&cs, argv[i]))) { fprintf(stderr, "Error (%d) reading configuration file %s.\n", err, argv[i]); goto exit2; } } strptr = git_configset_get_value_multi(&cs, argv[2]); if (strptr) { for (i = 0; i < strptr->nr; i++) { v = strptr->items[i].string; if (!v) printf("(NULL)\n"); else printf("%s\n", v); } goto exit0; } else { printf("Value not found for \"%s\"\n", argv[2]); goto exit1; } } else if (!strcmp(argv[1], "iterate")) { git_config(iterate_cb, NULL); goto exit0; } die("%s: Please check the syntax and the function name", argv[0]); exit0: git_configset_clear(&cs); return 0; exit1: git_configset_clear(&cs); return 1; exit2: git_configset_clear(&cs); return 2; }