static void drop_config(git_repository *repo) { if (repo->_config != NULL) { GIT_REFCOUNT_OWN(repo->_config, NULL); git_config_free(repo->_config); repo->_config = NULL; } git_repository__cvar_cache_clear(repo); }
static void set_config(git_repository *repo, git_config *config) { if (config) { GIT_REFCOUNT_OWN(config, repo); GIT_REFCOUNT_INC(config); } if ((config = (git_config*) git__swap(repo->_config, config)) != NULL) { GIT_REFCOUNT_OWN(config, NULL); git_config_free(config); } git_repository__cvar_cache_clear(repo); }
static git_repository *repository_alloc(void) { git_repository *repo = (git_repository *) git__calloc(1, sizeof(git_repository)); if (!repo) return NULL; if (git_cache_init(&repo->objects) < 0) { git__free(repo); return NULL; } /* set all the entries in the cvar cache to `unset` */ git_repository__cvar_cache_clear(repo); return repo; }
static git_repository *repository_alloc(void) { git_repository *repo = git__malloc(sizeof(git_repository)); if (!repo) return NULL; memset(repo, 0x0, sizeof(git_repository)); if (git_cache_init(&repo->objects, GIT_DEFAULT_CACHE_SIZE, &git_object__free) < 0) { git__free(repo); return NULL; } /* set all the entries in the cvar cache to `unset` */ git_repository__cvar_cache_clear(repo); return repo; }
void test_repo_config__read_with_no_configs_at_all(void) { git_repository *repo; int val; cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); /* with none */ cl_must_pass(p_unlink("empty_standard_repo/.git/config")); cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(GIT_ABBREV_DEFAULT, val); git_repository_free(repo); /* with no local config, just system */ cl_sandbox_set_search_path_defaults(); cl_must_pass(p_mkdir("alternate/1", 0777)); cl_git_pass(git_buf_joinpath(&path, path.ptr, "1")); cl_git_rewritefile("alternate/1/gitconfig", "[core]\n\tabbrev = 10\n"); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(10, val); git_repository_free(repo); /* with just xdg + system */ cl_must_pass(p_mkdir("alternate/2", 0777)); path.ptr[path.size - 1] = '2'; cl_git_rewritefile("alternate/2/config", "[core]\n\tabbrev = 20\n"); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(20, val); git_repository_free(repo); /* with global + xdg + system */ cl_must_pass(p_mkdir("alternate/3", 0777)); path.ptr[path.size - 1] = '3'; cl_git_rewritefile("alternate/3/.gitconfig", "[core]\n\tabbrev = 30\n"); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(30, val); git_repository_free(repo); /* with all configs */ cl_git_rewritefile("empty_standard_repo/.git/config", "[core]\n\tabbrev = 40\n"); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(40, val); git_repository_free(repo); /* with all configs but delete the files ? */ cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(40, val); cl_must_pass(p_unlink("empty_standard_repo/.git/config")); cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); cl_must_pass(p_unlink("alternate/1/gitconfig")); cl_assert(!git_path_isfile("alternate/1/gitconfig")); cl_must_pass(p_unlink("alternate/2/config")); cl_assert(!git_path_isfile("alternate/2/config")); cl_must_pass(p_unlink("alternate/3/.gitconfig")); cl_assert(!git_path_isfile("alternate/3/.gitconfig")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(40, val); git_repository_free(repo); /* reopen */ cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); cl_assert(!git_path_isfile("alternate/3/.gitconfig")); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__cvar_cache_clear(repo); val = -1; cl_git_pass(git_repository__cvar(&val, repo, GIT_CVAR_ABBREV)); cl_assert_equal_i(7, val); git_repository_free(repo); cl_assert(!git_path_exists("empty_standard_repo/.git/config")); cl_assert(!git_path_exists("alternate/3/.gitconfig")); }