diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-06-04 17:31:42 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-06-04 17:31:42 +0200 |
commit | 57cb1179e5c9c8f5c27c9115f13f1cae5d0f87a0 (patch) | |
tree | 67871086b1437dcd410979b423cd3ba140ab9257 /src | |
parent | 90befde4a1938641dfdb9a7bdb9f361d1de5c26f (diff) | |
download | libgit2-cmn/config-default-snapshot.tar.gz |
Make the default repository config getter return a snapshotcmn/config-default-snapshot
You should always use a snapshot, with the sole exception of writing to
the configuration.
Any reads that are not against a snapshot have race conditions, both in
terms of returned values as well as dangling pointers.
Diffstat (limited to 'src')
-rw-r--r-- | src/attrcache.c | 2 | ||||
-rw-r--r-- | src/branch.c | 2 | ||||
-rw-r--r-- | src/checkout.c | 5 | ||||
-rw-r--r-- | src/diff.c | 2 | ||||
-rw-r--r-- | src/diff_driver.c | 2 | ||||
-rw-r--r-- | src/merge.c | 2 | ||||
-rw-r--r-- | src/pack-objects.c | 2 | ||||
-rw-r--r-- | src/remote.c | 2 | ||||
-rw-r--r-- | src/repository.c | 6 | ||||
-rw-r--r-- | src/signature.c | 2 | ||||
-rw-r--r-- | src/submodule.c | 2 |
11 files changed, 14 insertions, 15 deletions
diff --git a/src/attrcache.c b/src/attrcache.c index b4579bfc0..20be9c7a8 100644 --- a/src/attrcache.c +++ b/src/attrcache.c @@ -364,7 +364,7 @@ int git_attr_cache__do_init(git_repository *repo) return -1; } - if ((ret = git_repository_config_snapshot(&cfg, repo)) < 0) + if ((ret = git_repository_config(&cfg, repo)) < 0) goto cancel; /* cache config settings for attributes and ignores */ diff --git a/src/branch.c b/src/branch.c index 52760853b..808f6998e 100644 --- a/src/branch.c +++ b/src/branch.c @@ -341,7 +341,7 @@ int git_branch_upstream_name( if (!git_reference__is_branch(refname)) return not_a_local_branch(refname); - if ((error = git_repository_config_snapshot(&config, repo)) < 0) + if ((error = git_repository_config(&config, repo)) < 0) return error; if ((error = retrieve_upstream_configuration( diff --git a/src/checkout.c b/src/checkout.c index 20763fd35..6de7585cd 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -1935,12 +1935,11 @@ static int checkout_data_init( GIT_DIR_MODE, GIT_MKDIR_VERIFY_DIR)) < 0) goto cleanup; - /* refresh config and index content unless NO_REFRESH is given */ + /* refresh index content unless NO_REFRESH is given */ if ((data->opts.checkout_strategy & GIT_CHECKOUT_NO_REFRESH) == 0) { git_config *cfg; - if ((error = git_repository_config__weakptr(&cfg, repo)) < 0 || - (error = git_config_refresh(cfg)) < 0) + if ((error = git_repository_config__weakptr(&cfg, repo)) < 0) goto cleanup; /* if we are checking out the index, don't reload, diff --git a/src/diff.c b/src/diff.c index 325c599e0..287530893 100644 --- a/src/diff.c +++ b/src/diff.c @@ -406,7 +406,7 @@ static int diff_list_apply_options( diff->opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED; /* load config values that affect diff behavior */ - if ((val = git_repository_config_snapshot(&cfg, repo)) < 0) + if ((val = git_repository_config(&cfg, repo)) < 0) return val; if (!git_config__cvar(&val, cfg, GIT_CVAR_SYMLINKS) && val) diff --git a/src/diff_driver.c b/src/diff_driver.c index c3c5f365b..56f89b30c 100644 --- a/src/diff_driver.c +++ b/src/diff_driver.c @@ -239,7 +239,7 @@ static int git_diff_driver_load( memcpy(drv->name, driver_name, namelen); /* if you can't read config for repo, just use default driver */ - if (git_repository_config_snapshot(&cfg, repo) < 0) { + if (git_repository_config(&cfg, repo) < 0) { giterr_clear(); goto done; } diff --git a/src/merge.c b/src/merge.c index a279d31d4..beb6c8f9c 100644 --- a/src/merge.c +++ b/src/merge.c @@ -2572,7 +2572,7 @@ static int merge_preference(git_merge_preference_t *out, git_repository *repo) *out = GIT_MERGE_PREFERENCE_NONE; - if ((error = git_repository_config_snapshot(&config, repo)) < 0) + if ((error = git_repository_config(&config, repo)) < 0) goto done; if ((error = git_config_get_string(&value, config, "merge.ff")) < 0) { diff --git a/src/pack-objects.c b/src/pack-objects.c index 3d3330ae8..0459fc4cf 100644 --- a/src/pack-objects.c +++ b/src/pack-objects.c @@ -90,7 +90,7 @@ static int packbuilder_config(git_packbuilder *pb) int ret; int64_t val; - if ((ret = git_repository_config_snapshot(&config, pb->repo)) < 0) + if ((ret = git_repository_config(&config, pb->repo)) < 0) return ret; #define config_get(KEY,DST,DFLT) do { \ diff --git a/src/remote.c b/src/remote.c index 0c82433d1..851fc66b5 100644 --- a/src/remote.c +++ b/src/remote.c @@ -356,7 +356,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name) if ((error = ensure_remote_name_is_valid(name)) < 0) return error; - if ((error = git_repository_config_snapshot(&config, repo)) < 0) + if ((error = git_repository_config(&config, repo)) < 0) return error; remote = git__malloc(sizeof(git_remote)); diff --git a/src/repository.c b/src/repository.c index e8d50aed3..709506486 100644 --- a/src/repository.c +++ b/src/repository.c @@ -462,7 +462,7 @@ int git_repository_open_ext( else { git_config *config = NULL; - if ((error = git_repository_config_snapshot(&config, repo)) < 0 || + if ((error = git_repository_config(&config, repo)) < 0 || (error = load_config_data(repo, config)) < 0 || (error = load_workdir(repo, config, &parent)) < 0) git_repository_free(repo); @@ -616,7 +616,7 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo) return error; } -int git_repository_config(git_config **out, git_repository *repo) +int git_repository_config_writable(git_config **out, git_repository *repo) { if (git_repository_config__weakptr(out, repo) < 0) return -1; @@ -625,7 +625,7 @@ int git_repository_config(git_config **out, git_repository *repo) return 0; } -int git_repository_config_snapshot(git_config **out, git_repository *repo) +int git_repository_config(git_config **out, git_repository *repo) { int error; git_config *weak; diff --git a/src/signature.c b/src/signature.c index 2545b7519..f501cd8b6 100644 --- a/src/signature.c +++ b/src/signature.c @@ -144,7 +144,7 @@ int git_signature_default(git_signature **out, git_repository *repo) git_config *cfg; const char *user_name, *user_email; - if ((error = git_repository_config_snapshot(&cfg, repo)) < 0) + if ((error = git_repository_config(&cfg, repo)) < 0) return error; if (!(error = git_config_get_string(&user_name, cfg, "user.name")) && diff --git a/src/submodule.c b/src/submodule.c index b1291df8e..22a6ba63f 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -797,7 +797,7 @@ int git_submodule_init(git_submodule *sm, int overwrite) return -1; } - if ((error = git_repository_config(&cfg, sm->repo)) < 0) + if ((error = git_repository_config__weakptr(&cfg, sm->repo)) < 0) return error; /* write "submodule.NAME.url" */ |