summaryrefslogtreecommitdiff
path: root/src/config_file.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-03-31 09:58:44 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-04-18 16:07:33 +0200
commit523032cd24e5b238752394bd1b691a3e28ba321e (patch)
treed112c7c8a850ef30e1043b4e679d61e6a5725c66 /src/config_file.c
parenteaf3703401a64d59fd8bf2609449343d739ef056 (diff)
downloadlibgit2-523032cd24e5b238752394bd1b691a3e28ba321e.tar.gz
config: refresh before reading a value
With the isolation of complex reads, we can now try to refresh the on-disk file before reading a value from it. This changes the semantics a bit, as before we could be sure that a string we got from the configuration was valid until we wrote or refreshed. This is no longer the case, as a read can also invalidate the pointer.
Diffstat (limited to 'src/config_file.c')
-rw-r--r--src/config_file.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 621a7c3e2..227ec82e9 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -89,6 +89,7 @@ struct reader {
typedef struct {
git_config_backend parent;
git_strmap *values;
+ int readonly;
} diskfile_header;
typedef struct {
@@ -448,12 +449,19 @@ out:
/*
* Internal function that actually gets the value in string form
*/
-static int config_get(const git_config_backend *cfg, const char *key, const git_config_entry **out)
+static int config_get(git_config_backend *cfg, const char *key, const git_config_entry **out)
{
diskfile_header *h = (diskfile_header *)cfg;
- git_strmap *values = h->values;
- khiter_t pos = git_strmap_lookup_index(values, key);
+ git_strmap *values;
+ khiter_t pos;
cvar_t *var;
+ int error;
+
+ if (!h->readonly && ((error = config_refresh(cfg)) < 0))
+ return error;
+
+ values = h->values;
+ pos = git_strmap_lookup_index(values, key);
/* no error message; the config system will write one */
if (!git_strmap_valid_index(values, pos))
@@ -783,6 +791,7 @@ int git_config_file__snapshot(git_config_backend **out, diskfile_backend *in)
backend->snapshot_from = in;
+ backend->header.readonly = 1;
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
backend->header.parent.open = config_readonly_open;
backend->header.parent.get = config_get;