Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3b500a9
ci: update to windows-2022 for sha256 builds
ethomson Oct 2, 2024
419948e
attrcache: make the attribute cache opaque
ethomson Sep 21, 2024
53bc5a1
pool: introduce is_initialized helper method
ethomson Oct 1, 2024
539059f
hashmap: introduce git_hashmap / git_hashset
ethomson Sep 30, 2024
0e110d2
apply: use new hashset for strings
ethomson Sep 30, 2024
7890eb1
attr: use a hashset instead of a strmap
ethomson Sep 30, 2024
29f141d
attr_cache: move from strmap to hashset_str
ethomson Sep 30, 2024
ee29ac7
checkout: use a hashset_str instead of a strmap
ethomson Sep 30, 2024
1f0c38f
config_list: use a hashset_str instead of a strmap
ethomson Sep 30, 2024
8dc52d0
sortedcache: use a hashset_str instead of a strmap
ethomson Sep 30, 2024
be8e75a
diff_driver: use a hashmap_str instead of a strmap
ethomson Sep 30, 2024
c9c5eba
submodule: use a hashmap for submodule map
ethomson Sep 30, 2024
e39a4f7
mwindow: use hashmaps
ethomson Sep 30, 2024
58c1558
transaction: use hashmap
ethomson Sep 30, 2024
74c4233
tree: use hashmap
ethomson Sep 30, 2024
c1ecf56
hashmap: update index to use new hashmap
ethomson Sep 28, 2024
b4be7d0
oid: introduce oid hash functions
ethomson Sep 29, 2024
7fb641b
cache: use a well-typed hashmap for oid mapped cache
ethomson Sep 29, 2024
f9ad579
commit_graph: use a well-typed oid hashmap
ethomson Sep 29, 2024
90f1785
describe: use a typed oid hashmap
ethomson Sep 29, 2024
9a7d920
grafts: use a typed oid hashmap
ethomson Sep 29, 2024
c729431
merge: use type safe oid-keyed hashmaps
ethomson Sep 29, 2024
79290ba
odb_mempack: use a typed hashmap
ethomson Sep 29, 2024
5d2c56d
revwalk: hashmap
ethomson Sep 29, 2024
77e359e
indexer: use typed hashmap
ethomson Oct 1, 2024
9daf45a
pack: use typed hashmap for index cache
ethomson Oct 1, 2024
597a671
pack: typed hashmap for offsets instead of offmap
ethomson Oct 1, 2024
4e2ce7e
packbuilder: use hashmap for pobject map
ethomson Oct 1, 2024
8c55bbe
packbuilder: use hashmap for walk_objects
ethomson Oct 1, 2024
8d81bb5
hashmap: remove now-unused offmap and strmap
ethomson Oct 1, 2024
9c1f4b4
oidmap: remove now-unused oidmap
ethomson Oct 1, 2024
7ca51a8
util: remove now-used khash.h
ethomson Oct 1, 2024
9d57a7a
hashmap_oid: introduce hashmap_oid
ethomson Oct 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/experimental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
SKIP_NEGOTIATE_TESTS: true
- name: "Windows (SHA256, amd64, Visual Studio)"
id: windows-sha256
os: windows-2019
os: windows-2022
env:
ARCH: amd64
CMAKE_GENERATOR: Visual Studio 16 2019
CMAKE_GENERATOR: Visual Studio 17 2022
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DEXPERIMENTAL_SHA256=ON
SKIP_SSH_TESTS: true
SKIP_NEGOTIATE_TESTS: true
Expand Down
18 changes: 8 additions & 10 deletions src/libgit2/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "reader.h"
#include "index.h"
#include "repository.h"
#include "hashmap_str.h"
#include "apply.h"

typedef struct {
Expand Down Expand Up @@ -452,7 +453,7 @@ static int apply_one(
git_reader *postimage_reader,
git_index *postimage,
git_diff *diff,
git_strmap *removed_paths,
git_hashset_str *removed_paths,
size_t i,
const git_apply_options *opts)
{
Expand Down Expand Up @@ -489,7 +490,7 @@ static int apply_one(
*/
if (delta->status != GIT_DELTA_RENAMED &&
delta->status != GIT_DELTA_ADDED) {
if (git_strmap_exists(removed_paths, delta->old_file.path)) {
if (git_hashset_str_contains(removed_paths, delta->old_file.path)) {
error = apply_err("path '%s' has been renamed or deleted", delta->old_file.path);
goto done;
}
Expand Down Expand Up @@ -573,11 +574,11 @@ static int apply_one(

if (delta->status == GIT_DELTA_RENAMED ||
delta->status == GIT_DELTA_DELETED)
error = git_strmap_set(removed_paths, delta->old_file.path, (char *) delta->old_file.path);
error = git_hashset_str_add(removed_paths, delta->old_file.path);

if (delta->status == GIT_DELTA_RENAMED ||
delta->status == GIT_DELTA_ADDED)
git_strmap_delete(removed_paths, delta->new_file.path);
git_hashset_str_remove(removed_paths, delta->new_file.path);

done:
git_str_dispose(&pre_contents);
Expand All @@ -597,20 +598,17 @@ static int apply_deltas(
git_diff *diff,
const git_apply_options *opts)
{
git_strmap *removed_paths;
git_hashset_str removed_paths = GIT_HASHSET_INIT;
size_t i;
int error = 0;

if (git_strmap_new(&removed_paths) < 0)
return -1;

for (i = 0; i < git_diff_num_deltas(diff); i++) {
if ((error = apply_one(repo, pre_reader, preimage, post_reader, postimage, diff, removed_paths, i, opts)) < 0)
if ((error = apply_one(repo, pre_reader, preimage, post_reader, postimage, diff, &removed_paths, i, opts)) < 0)
goto done;
}

done:
git_strmap_free(removed_paths);
git_hashset_str_dispose(&removed_paths);
return error;
}

Expand Down
35 changes: 24 additions & 11 deletions src/libgit2/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "attr_file.h"
#include "ignore.h"
#include "git2/oid.h"
#include "hashmap_str.h"
#include <ctype.h>

const char *git_attr__true = "[internal]__TRUE__";
Expand Down Expand Up @@ -254,7 +255,7 @@ int git_attr_foreach_ext(
git_attr_file *file;
git_attr_rule *rule;
git_attr_assignment *assign;
git_strmap *seen = NULL;
git_hashset_str seen = GIT_HASHSET_INIT;
git_dir_flag dir_flag = GIT_DIR_FLAG_UNKNOWN;

GIT_ASSERT_ARG(repo);
Expand All @@ -267,8 +268,7 @@ int git_attr_foreach_ext(
if (git_attr_path__init(&path, pathname, git_repository_workdir(repo), dir_flag) < 0)
return -1;

if ((error = collect_attr_files(repo, NULL, opts, pathname, &files)) < 0 ||
(error = git_strmap_new(&seen)) < 0)
if ((error = collect_attr_files(repo, NULL, opts, pathname, &files)) < 0)
goto cleanup;

git_vector_foreach(&files, i, file) {
Expand All @@ -277,10 +277,10 @@ int git_attr_foreach_ext(

git_vector_foreach(&rule->assigns, k, assign) {
/* skip if higher priority assignment was already seen */
if (git_strmap_exists(seen, assign->name))
if (git_hashset_str_contains(&seen, assign->name))
continue;

if ((error = git_strmap_set(seen, assign->name, assign)) < 0)
if ((error = git_hashset_str_add(&seen, assign->name)) < 0)
goto cleanup;

error = callback(assign->name, assign->value, payload);
Expand All @@ -293,7 +293,7 @@ int git_attr_foreach_ext(
}

cleanup:
git_strmap_free(seen);
git_hashset_str_dispose(&seen);
release_attr_files(&files);
git_attr_path__free(&path);

Expand Down Expand Up @@ -384,6 +384,8 @@ static int attr_setup(
git_attr_file_source index_source = { GIT_ATTR_FILE_SOURCE_INDEX, NULL, GIT_ATTR_FILE, NULL };
git_attr_file_source head_source = { GIT_ATTR_FILE_SOURCE_HEAD, NULL, GIT_ATTR_FILE, NULL };
git_attr_file_source commit_source = { GIT_ATTR_FILE_SOURCE_COMMIT, NULL, GIT_ATTR_FILE, NULL };
git_attr_cache *attrcache;
const char *attr_cfg_file = NULL;
git_index *idx = NULL;
const char *workdir;
int error = 0;
Expand All @@ -407,8 +409,10 @@ static int attr_setup(
error = 0;
}

if ((error = preload_attr_file(repo, attr_session, NULL,
git_repository_attr_cache(repo)->cfg_attr_file)) < 0)
if ((attrcache = git_repository_attr_cache(repo)) != NULL)
attr_cfg_file = git_attr_cache_attributesfile(attrcache);

if ((error = preload_attr_file(repo, attr_session, NULL, attr_cfg_file)) < 0)
goto out;

if ((error = git_repository__item_path(&info, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
Expand Down Expand Up @@ -464,6 +468,7 @@ int git_attr_add_macro(
{
int error;
git_attr_rule *macro = NULL;
git_attr_cache *attrcache;
git_pool *pool;

GIT_ASSERT_ARG(repo);
Expand All @@ -475,7 +480,8 @@ int git_attr_add_macro(
macro = git__calloc(1, sizeof(git_attr_rule));
GIT_ERROR_CHECK_ALLOC(macro);

pool = &git_repository_attr_cache(repo)->pool;
attrcache = git_repository_attr_cache(repo);
pool = git_attr_cache_pool(attrcache);

macro->match.pattern = git_pool_strdup(pool, name);
GIT_ERROR_CHECK_ALLOC(macro->match.pattern);
Expand Down Expand Up @@ -631,6 +637,8 @@ static int collect_attr_files(
int error = 0;
git_str dir = GIT_STR_INIT, attrfile = GIT_STR_INIT;
const char *workdir = git_repository_workdir(repo);
git_attr_cache *attrcache;
const char *attr_cfg_file = NULL;
attr_walk_up_info info = { NULL };

GIT_ASSERT(!git_fs_path_is_absolute(path));
Expand Down Expand Up @@ -679,8 +687,13 @@ static int collect_attr_files(
if (error < 0)
goto cleanup;

if (git_repository_attr_cache(repo)->cfg_attr_file != NULL) {
error = push_attr_file(repo, attr_session, files, NULL, git_repository_attr_cache(repo)->cfg_attr_file);
if ((attrcache = git_repository_attr_cache(repo)) != NULL)
attr_cfg_file = git_attr_cache_attributesfile(attrcache);


if (attr_cfg_file) {
error = push_attr_file(repo, attr_session, files, NULL, attr_cfg_file);

if (error < 0)
goto cleanup;
}
Expand Down
102 changes: 69 additions & 33 deletions src/libgit2/attrcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@
#include "sysdir.h"
#include "ignore.h"
#include "path.h"
#include "hashmap_str.h"

GIT_HASHMAP_STR_SETUP(git_attr_cache_filemap, git_attr_file_entry *);
GIT_HASHMAP_STR_SETUP(git_attr_cache_macromap, git_attr_rule *);

struct git_attr_cache {
char *cfg_attr_file; /* cached value of core.attributesfile */
char *cfg_excl_file; /* cached value of core.excludesfile */

/* hash path to git_attr_file_entry records */
git_attr_cache_filemap files;
/* hash name to git_attr_rule */
git_attr_cache_macromap macros;

git_mutex lock;
git_pool pool;
};

const char *git_attr_cache_attributesfile(git_attr_cache *cache)
{
return cache->cfg_attr_file;
}

const char *git_attr_cache_excludesfile(git_attr_cache *cache)
{
return cache->cfg_excl_file;
}

git_pool *git_attr_cache_pool(git_attr_cache *cache)
{
return &cache->pool;
}

GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache)
{
Expand All @@ -34,7 +66,12 @@ GIT_INLINE(void) attr_cache_unlock(git_attr_cache *cache)
GIT_INLINE(git_attr_file_entry *) attr_cache_lookup_entry(
git_attr_cache *cache, const char *path)
{
return git_strmap_get(cache->files, path);
git_attr_file_entry *result;

if (git_attr_cache_filemap_get(&result, &cache->files, path) == 0)
return result;

return NULL;
}

int git_attr_cache__alloc_file_entry(
Expand Down Expand Up @@ -92,7 +129,7 @@ static int attr_cache_make_entry(
git_repository_workdir(repo), path, &cache->pool)) < 0)
return error;

if ((error = git_strmap_set(cache->files, entry->path, entry)) < 0)
if ((error = git_attr_cache_filemap_put(&cache->files, entry->path, entry)) < 0)
return error;

*out = entry;
Expand Down Expand Up @@ -271,12 +308,11 @@ bool git_attr_cache__is_cached(
{
git_attr_cache *cache = git_repository_attr_cache(repo);
git_attr_file_entry *entry;
git_strmap *files;

if (!cache || !(files = cache->files))
if (!cache)
return false;

if ((entry = git_strmap_get(files, filename)) == NULL)
if (git_attr_cache_filemap_get(&entry, &cache->files, filename) != 0)
return false;

return entry && (entry->file[source_type] != NULL);
Expand Down Expand Up @@ -318,37 +354,34 @@ static int attr_cache__lookup_path(

static void attr_cache__free(git_attr_cache *cache)
{
git_hashmap_iter_t iter = GIT_HASHMAP_ITER_INIT;
git_attr_rule *rule;
git_attr_file_entry *entry;
bool unlock;

if (!cache)
return;

unlock = (attr_cache_lock(cache) == 0);

if (cache->files != NULL) {
git_attr_file_entry *entry;
while (git_attr_cache_filemap_iterate(&iter, NULL, &entry, &cache->files) == 0) {
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_atomic_swap(entry->file[i], NULL)) != NULL) {
GIT_REFCOUNT_OWN(file, NULL);
git_attr_file__free(file);
}
size_t i;

for (i = 0; i < GIT_ATTR_FILE_NUM_SOURCES; i++) {
if ((file = git_atomic_swap(entry->file[i], NULL)) != NULL) {
GIT_REFCOUNT_OWN(file, NULL);
git_attr_file__free(file);
}
});
git_strmap_free(cache->files);
}
}

if (cache->macros != NULL) {
git_attr_rule *rule;
iter = GIT_HASHMAP_ITER_INIT;
while (git_attr_cache_macromap_iterate(&iter, NULL, &rule, &cache->macros) == 0)
git_attr_rule__free(rule);

git_strmap_foreach_value(cache->macros, rule, {
git_attr_rule__free(rule);
});
git_strmap_free(cache->macros);
}
git_attr_cache_filemap_dispose(&cache->files);
git_attr_cache_macromap_dispose(&cache->macros);

git_pool_clear(&cache->pool);

Expand Down Expand Up @@ -401,9 +434,7 @@ int git_attr_cache__init(git_repository *repo)
/* allocate hashtable for attribute and ignore file contents,
* hashtable for attribute macros, and string pool
*/
if ((ret = git_strmap_new(&cache->files)) < 0 ||
(ret = git_strmap_new(&cache->macros)) < 0 ||
(ret = git_pool_init(&cache->pool, 1)) < 0)
if ((ret = git_pool_init(&cache->pool, 1)) < 0)
goto cancel;

if (git_atomic_compare_and_swap(&repo->attrcache, NULL, cache) != NULL)
Expand Down Expand Up @@ -457,11 +488,11 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)
goto out;
locked = true;

if ((preexisting = git_strmap_get(cache->macros, macro->match.pattern)) != NULL)
git_attr_rule__free(preexisting);
if (git_attr_cache_macromap_get(&preexisting, &cache->macros, macro->match.pattern) == 0)
git_attr_rule__free(preexisting);

if ((error = git_strmap_set(cache->macros, macro->match.pattern, macro)) < 0)
goto out;
if ((error = git_attr_cache_macromap_put(&cache->macros, macro->match.pattern, macro)) < 0)
goto out;

out:
if (locked)
Expand All @@ -472,7 +503,12 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)
git_attr_rule *git_attr_cache__lookup_macro(
git_repository *repo, const char *name)
{
git_strmap *macros = git_repository_attr_cache(repo)->macros;
git_attr_cache *cache = git_repository_attr_cache(repo);
git_attr_rule *rule;

if (!cache ||
git_attr_cache_macromap_get(&rule, &cache->macros, name) != 0)
return NULL;

return git_strmap_get(macros, name);
return rule;
}
14 changes: 5 additions & 9 deletions src/libgit2/attrcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@
#include "common.h"

#include "attr_file.h"
#include "strmap.h"

#define GIT_ATTR_CONFIG "core.attributesfile"
#define GIT_IGNORE_CONFIG "core.excludesfile"

typedef struct {
char *cfg_attr_file; /* cached value of core.attributesfile */
char *cfg_excl_file; /* cached value of core.excludesfile */
git_strmap *files; /* hash path to git_attr_cache_entry records */
git_strmap *macros; /* hash name to vector<git_attr_assignment> */
git_mutex lock;
git_pool pool;
} git_attr_cache;
typedef struct git_attr_cache git_attr_cache;

extern int git_attr_cache__init(git_repository *repo);

extern const char *git_attr_cache_attributesfile(git_attr_cache *ac);
extern const char *git_attr_cache_excludesfile(git_attr_cache *ac);
extern git_pool *git_attr_cache_pool(git_attr_cache *ac);

/* get file - loading and reload as needed */
extern int git_attr_cache__get(
git_attr_file **file,
Expand Down
Loading