Skip to content

Commit 146e5bf

Browse files
committed
config_mem: implement support for snapshots
Similar as in commit dadbb33 (Fix crash if snapshotting a config_snapshot, 2019-11-01), let's implement snapshots for in-memory configuration entries. As this deletes more code than it adds, it doesn't make any sense to not allow for this and allows users to treat config backends mostly the same.
1 parent 5d773a1 commit 146e5bf

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/config_mem.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,6 @@ static int config_memory_unlock(git_config_backend *backend, int success)
170170
return config_error_readonly();
171171
}
172172

173-
static int config_memory_snapshot(git_config_backend **out, git_config_backend *backend)
174-
{
175-
GIT_UNUSED(out);
176-
GIT_UNUSED(backend);
177-
git_error_set(GIT_ERROR_CONFIG, "this backend does not support snapshots");
178-
return -1;
179-
}
180-
181173
static void config_memory_free(git_config_backend *_backend)
182174
{
183175
config_memory_backend *backend = (config_memory_backend *)_backend;
@@ -219,7 +211,7 @@ int git_config_backend_from_string(git_config_backend **out, const char *cfg, si
219211
backend->parent.iterator = config_memory_iterator;
220212
backend->parent.lock = config_memory_lock;
221213
backend->parent.unlock = config_memory_unlock;
222-
backend->parent.snapshot = config_memory_snapshot;
214+
backend->parent.snapshot = git_config_backend_snapshot;
223215
backend->parent.free = config_memory_free;
224216

225217
*out = (git_config_backend *)backend;

tests/config/snapshot.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "clar_libgit2.h"
22

3+
#include "config_backend.h"
4+
35
static git_config *cfg;
46
static git_config *snapshot;
57

@@ -120,3 +122,18 @@ void test_config_snapshot__snapshot(void)
120122

121123
cl_git_pass(p_unlink("configfile"));
122124
}
125+
126+
void test_config_snapshot__snapshot_from_in_memony(void)
127+
{
128+
const char *configuration = "[section]\nkey = 1\n";
129+
git_config_backend *backend;
130+
int i;
131+
132+
cl_git_pass(git_config_new(&cfg));
133+
cl_git_pass(git_config_backend_from_string(&backend, configuration, strlen(configuration)));
134+
cl_git_pass(git_config_add_backend(cfg, backend, 0, NULL, 0));
135+
136+
cl_git_pass(git_config_snapshot(&snapshot, cfg));
137+
cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
138+
cl_assert_equal_i(i, 1);
139+
}

0 commit comments

Comments
 (0)