Merge pull request #5299 from pks-t/pks/config-mem-snapshots config_mem: implement support for snapshots
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
diff --git a/src/config_mem.c b/src/config_mem.c
index e4006db..5b573a9 100644
--- a/src/config_mem.c
+++ b/src/config_mem.c
@@ -170,14 +170,6 @@ static int config_memory_unlock(git_config_backend *backend, int success)
return config_error_readonly();
}
-static int config_memory_snapshot(git_config_backend **out, git_config_backend *backend)
-{
- GIT_UNUSED(out);
- GIT_UNUSED(backend);
- git_error_set(GIT_ERROR_CONFIG, "this backend does not support snapshots");
- return -1;
-}
-
static void config_memory_free(git_config_backend *_backend)
{
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
backend->parent.iterator = config_memory_iterator;
backend->parent.lock = config_memory_lock;
backend->parent.unlock = config_memory_unlock;
- backend->parent.snapshot = config_memory_snapshot;
+ backend->parent.snapshot = git_config_backend_snapshot;
backend->parent.free = config_memory_free;
*out = (git_config_backend *)backend;
diff --git a/tests/config/snapshot.c b/tests/config/snapshot.c
index 3b90cfe..5cc08a7 100644
--- a/tests/config/snapshot.c
+++ b/tests/config/snapshot.c
@@ -1,5 +1,7 @@
#include "clar_libgit2.h"
+#include "config_backend.h"
+
static git_config *cfg;
static git_config *snapshot;
@@ -120,3 +122,18 @@ void test_config_snapshot__snapshot(void)
cl_git_pass(p_unlink("configfile"));
}
+
+void test_config_snapshot__snapshot_from_in_memony(void)
+{
+ const char *configuration = "[section]\nkey = 1\n";
+ git_config_backend *backend;
+ int i;
+
+ cl_git_pass(git_config_new(&cfg));
+ cl_git_pass(git_config_backend_from_string(&backend, configuration, strlen(configuration)));
+ cl_git_pass(git_config_add_backend(cfg, backend, 0, NULL, 0));
+
+ cl_git_pass(git_config_snapshot(&snapshot, cfg));
+ cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
+ cl_assert_equal_i(i, 1);
+}