int git_repository_index__weakptr(git_index **out, git_repository *repo) { int error = 0; assert(out && repo); if (repo->_index == NULL) { git_buf index_path = GIT_BUF_INIT; git_index *index; if ((error = git_buf_joinpath(&index_path, repo->path_repository, GIT_INDEX_FILE)) < 0) return error; error = git_index_open(&index, index_path.ptr); if (!error) { GIT_REFCOUNT_OWN(index, repo); index = (git_index*) git__compare_and_swap(&repo->_index, NULL, index); if (index != NULL) { GIT_REFCOUNT_OWN(index, NULL); git_index_free(index); } error = git_index_set_caps(repo->_index, GIT_INDEXCAP_FROM_OWNER); } git_buf_free(&index_path); } *out = repo->_index; return error; }
int git_repository_odb__weakptr(git_odb **out, git_repository *repo) { int error = 0; assert(repo && out); if (repo->_odb == NULL) { git_buf odb_path = GIT_BUF_INIT; git_odb *odb; if ((error = git_buf_joinpath(&odb_path, repo->path_repository, GIT_OBJECTS_DIR)) < 0) return error; error = git_odb_open(&odb, odb_path.ptr); if (!error) { GIT_REFCOUNT_OWN(odb, repo); odb = (git_odb*) git__compare_and_swap(&repo->_odb, NULL, odb); if (odb != NULL) { GIT_REFCOUNT_OWN(odb, NULL); git_odb_free(odb); } } git_buf_free(&odb_path); } *out = repo->_odb; return error; }
static void set_index(git_repository *repo, git_index *index) { if (index) { GIT_REFCOUNT_OWN(index, repo); GIT_REFCOUNT_INC(index); } if ((index = (git_index*) git__swap(repo->_index, index)) != NULL) { GIT_REFCOUNT_OWN(index, NULL); git_index_free(index); } }
static void set_refdb(git_repository *repo, git_refdb *refdb) { if (refdb) { GIT_REFCOUNT_OWN(refdb, repo); GIT_REFCOUNT_INC(refdb); } if ((refdb = (git_refdb*) git__swap(repo->_refdb, refdb)) != NULL) { GIT_REFCOUNT_OWN(refdb, NULL); git_refdb_free(refdb); } }
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); }
int git_repository_config__weakptr(git_config **out, git_repository *repo) { if (repo->_config == NULL) { git_buf global_buf = GIT_BUF_INIT, system_buf = GIT_BUF_INIT; int res; const char *global_config_path = NULL; const char *system_config_path = NULL; if (git_config_find_global_r(&global_buf) == 0) global_config_path = global_buf.ptr; if (git_config_find_system_r(&system_buf) == 0) system_config_path = system_buf.ptr; res = load_config(&repo->_config, repo, global_config_path, system_config_path); git_buf_free(&global_buf); git_buf_free(&system_buf); if (res < 0) return -1; GIT_REFCOUNT_OWN(repo->_config, repo); } *out = repo->_config; return 0; }
static void drop_index(git_repository *repo) { if (repo->_index != NULL) { GIT_REFCOUNT_OWN(repo->_index, NULL); git_index_free(repo->_index); repo->_index = NULL; } }
static void drop_odb(git_repository *repo) { if (repo->_odb != NULL) { GIT_REFCOUNT_OWN(repo->_odb, NULL); git_odb_free(repo->_odb); repo->_odb = NULL; } }
void git_repository_set_config(git_repository *repo, git_config *config) { assert(repo && config); drop_config(repo); repo->_config = config; GIT_REFCOUNT_OWN(repo->_config, repo); }
void git_repository_set_odb(git_repository *repo, git_odb *odb) { assert(repo && odb); drop_odb(repo); repo->_odb = odb; GIT_REFCOUNT_OWN(repo->_odb, repo); GIT_REFCOUNT_INC(odb); }
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); }
void git_repository_set_index(git_repository *repo, git_index *index) { assert(repo && index); drop_index(repo); repo->_index = index; GIT_REFCOUNT_OWN(repo->_index, repo); GIT_REFCOUNT_INC(index); }
int git_repository_config__weakptr(git_config **out, git_repository *repo) { int error = 0; if (repo->_config == NULL) { git_buf global_buf = GIT_BUF_INIT; git_buf xdg_buf = GIT_BUF_INIT; git_buf system_buf = GIT_BUF_INIT; git_config *config; git_config_find_global(&global_buf); git_config_find_xdg(&xdg_buf); git_config_find_system(&system_buf); /* If there is no global file, open a backend for it anyway */ if (git_buf_len(&global_buf) == 0) git_config__global_location(&global_buf); error = load_config( &config, repo, path_unless_empty(&global_buf), path_unless_empty(&xdg_buf), path_unless_empty(&system_buf)); if (!error) { GIT_REFCOUNT_OWN(config, repo); config = (git_config*) git__compare_and_swap(&repo->_config, NULL, config); if (config != NULL) { GIT_REFCOUNT_OWN(config, NULL); git_config_free(config); } } git_buf_free(&global_buf); git_buf_free(&xdg_buf); git_buf_free(&system_buf); } *out = repo->_config; return error; }
/* insert entry or replace existing if we raced with another thread */ static int attr_cache_upsert(git_attr_cache *cache, git_attr_file *file) { git_attr_file_entry *entry; git_attr_file *old; if (attr_cache_lock(cache) < 0) return -1; entry = attr_cache_lookup_entry(cache, file->entry->path); GIT_REFCOUNT_OWN(file, entry); GIT_REFCOUNT_INC(file); old = git__compare_and_swap( &entry->file[file->source], entry->file[file->source], file); if (old) { GIT_REFCOUNT_OWN(old, NULL); git_attr_file__free(old); } attr_cache_unlock(cache); return 0; }
int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo) { int error = 0; assert(out && repo); if (repo->_refdb == NULL) { git_refdb *refdb; error = git_refdb_open(&refdb, repo); if (!error) { GIT_REFCOUNT_OWN(refdb, repo); refdb = (git_refdb*) git__compare_and_swap(&repo->_refdb, NULL, refdb); if (refdb != NULL) { GIT_REFCOUNT_OWN(refdb, NULL); git_refdb_free(refdb); } } } *out = repo->_refdb; return error; }
static void attr_cache__free(git_attr_cache *cache) { bool unlock; if (!cache) return; unlock = (git_mutex_lock(&cache->lock) == 0); if (cache->files != NULL) { git_attr_file_entry *entry; git_attr_file *file; int i; git_strmap_foreach_value(cache->files, entry, { for (i = 0; i < GIT_ATTR_FILE_NUM_SOURCES; ++i) { if ((file = git__swap(entry->file[i], NULL)) != NULL) { GIT_REFCOUNT_OWN(file, NULL); git_attr_file__free(file); } } });
static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file) { int error = 0; git_attr_file_entry *entry; if (!file) return 0; if ((error = attr_cache_lock(cache)) < 0) return error; if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL) file = git__compare_and_swap(&entry->file[file->source], file, NULL); attr_cache_unlock(cache); if (file) { GIT_REFCOUNT_OWN(file, NULL); git_attr_file__free(file); } return error; }
int git_repository_odb__weakptr(git_odb **out, git_repository *repo) { assert(repo && out); if (repo->_odb == NULL) { git_buf odb_path = GIT_BUF_INIT; int res; if (git_buf_joinpath(&odb_path, repo->path_repository, GIT_OBJECTS_DIR) < 0) return -1; res = git_odb_open(&repo->_odb, odb_path.ptr); git_buf_free(&odb_path); /* done with path */ if (res < 0) return -1; GIT_REFCOUNT_OWN(repo->_odb, repo); } *out = repo->_odb; return 0; }
int git_repository_index__weakptr(git_index **out, git_repository *repo) { assert(out && repo); if (repo->_index == NULL) { int res; git_buf index_path = GIT_BUF_INIT; if (git_buf_joinpath(&index_path, repo->path_repository, GIT_INDEX_FILE) < 0) return -1; res = git_index_open(&repo->_index, index_path.ptr); git_buf_free(&index_path); /* done with path */ if (res < 0) return -1; GIT_REFCOUNT_OWN(repo->_index, repo); } *out = repo->_index; return 0; }