vendor/libgit2/src/attrcache.c in rugged-0.26.0b3 vs vendor/libgit2/src/attrcache.c in rugged-0.26.0b4

- old
+ new

@@ -3,12 +3,10 @@ #include "attr_file.h" #include "config.h" #include "sysdir.h" #include "ignore.h" -GIT__USE_STRMAP - GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache) { GIT_UNUSED(cache); /* avoid warning if threading is off */ if (git_mutex_lock(&cache->lock) < 0) { @@ -80,11 +78,11 @@ error = git_attr_cache__alloc_file_entry( &entry, git_repository_workdir(repo), path, &cache->pool); if (!error) { - git_strmap_insert(cache->files, entry->path, entry, error); + git_strmap_insert(cache->files, entry->path, entry, &error); if (error > 0) error = 0; } *out = entry; @@ -103,12 +101,15 @@ 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); + /* + * Replace the existing value if another thread has + * created it in the meantime. + */ + old = git__swap(entry->file[file->source], file); if (old) { GIT_REFCOUNT_OWN(old, NULL); git_attr_file__free(old); } @@ -309,11 +310,11 @@ bool unlock; if (!cache) return; - unlock = (git_mutex_lock(&cache->lock) == 0); + unlock = (attr_cache_lock(cache) == 0); if (cache->files != NULL) { git_attr_file_entry *entry; git_attr_file *file; int i; @@ -345,17 +346,17 @@ git__free(cache->cfg_excl_file); cache->cfg_excl_file = NULL; if (unlock) - git_mutex_unlock(&cache->lock); + attr_cache_unlock(cache); git_mutex_free(&cache->lock); git__free(cache); } -int git_attr_cache__do_init(git_repository *repo) +int git_attr_cache__init(git_repository *repo) { int ret = 0; git_attr_cache *cache = git_repository_attr_cache(repo); git_config *cfg = NULL; @@ -429,14 +430,14 @@ /* TODO: generate warning log if (macro->assigns.length == 0) */ if (macro->assigns.length == 0) return 0; - if (git_mutex_lock(&cache->lock) < 0) { + if (attr_cache_lock(cache) < 0) { giterr_set(GITERR_OS, "unable to get attr cache lock"); error = -1; } else { - git_strmap_insert(macros, macro->match.pattern, macro, error); + git_strmap_insert(macros, macro->match.pattern, macro, &error); git_mutex_unlock(&cache->lock); } return (error < 0) ? -1 : 0; }