void repo_clear(struct repository *repo) { FREE_AND_NULL(repo->gitdir); FREE_AND_NULL(repo->commondir); FREE_AND_NULL(repo->graft_file); FREE_AND_NULL(repo->index_file); FREE_AND_NULL(repo->worktree); FREE_AND_NULL(repo->submodule_prefix); raw_object_store_clear(repo->objects); FREE_AND_NULL(repo->objects); if (repo->config) { git_configset_clear(repo->config); FREE_AND_NULL(repo->config); } if (repo->submodule_cache) { submodule_cache_free(repo->submodule_cache); repo->submodule_cache = NULL; } if (repo->index) { discard_index(repo->index); FREE_AND_NULL(repo->index); } }
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; }