source src/config_snapshot.c
Line | Flow | Count | Block(s) | Source |
---|---|---|---|---|
1 | - | /* | ||
2 | - | * Copyright (C) the libgit2 contributors. All rights reserved. | ||
3 | - | * | ||
4 | - | * This file is part of libgit2, distributed under the GNU GPL v2 with | ||
5 | - | * a Linking Exception. For full terms see the included COPYING file. | ||
6 | - | */ | ||
7 | - | |||
8 | - | #include "config_backend.h" | ||
9 | - | |||
10 | - | #include "config.h" | ||
11 | - | #include "config_entries.h" | ||
12 | - | |||
13 | - | typedef struct { | ||
14 | - | git_config_backend parent; | ||
15 | - | git_mutex values_mutex; | ||
16 | - | git_config_entries *entries; | ||
17 | - | git_config_backend *source; | ||
18 | - | } config_snapshot_backend; | ||
19 | - | |||
20 | ##### | 2 | static int config_error_readonly(void) | |
21 | - | { | ||
22 | ##### | 2 | git_error_set(GIT_ERROR_CONFIG, "this backend is read-only"); | |
23 | ##### | 3 | return -1; | |
24 | - | } | ||
25 | - | |||
26 | 3876 | 2 | static int config_snapshot_iterator( | |
27 | - | git_config_iterator **iter, | ||
28 | - | struct git_config_backend *backend) | ||
29 | - | { | ||
30 | 3876 | 2 | config_snapshot_backend *b = GIT_CONTAINER_OF(backend, config_snapshot_backend, parent); | |
31 | 3876 | 2 | git_config_entries *entries = NULL; | |
32 | - | int error; | ||
33 | - | |||
34 | 3876 | 2-4 | if ((error = git_config_entries_dup(&entries, b->entries)) < 0 || | |
35 | 3876 | 4 | (error = git_config_entries_iterator_new(iter, entries)) < 0) | |
36 | - | goto out; | ||
37 | - | |||
38 | - | out: | ||
39 | - | /* Let iterator delete duplicated entries when it's done */ | ||
40 | 3876 | 5 | git_config_entries_free(entries); | |
41 | 3876 | 6 | return error; | |
42 | - | } | ||
43 | - | |||
44 | - | /* release the map containing the entry as an equivalent to freeing it */ | ||
45 | 18365 | 2 | static void config_snapshot_entry_free(git_config_entry *entry) | |
46 | - | { | ||
47 | 18365 | 2 | git_config_entries *entries = (git_config_entries *) entry->payload; | |
48 | 18365 | 2 | git_config_entries_free(entries); | |
49 | 18367 | 3 | } | |
50 | - | |||
51 | - | 2 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files)static int config_snapshot_get(git_config_backend *cfg, const char *key, git_config_entry **out) | |
52 | - | { | ||
53 | - | 2 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) config_snapshot_backend *b = GIT_CONTAINER_OF(cfg, config_snapshot_backend, parent); | |
54 | - | 2 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) git_config_entries *entries = NULL; | |
55 | - | git_config_entry *entry; | ||
56 | - | 2 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) int error = 0; | |
57 | - | |||
58 | - | 2,3 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) if (git_mutex_lock(&b->values_mutex) < 0) { | |
59 | - | 4 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) git_error_set(GIT_ERROR_OS, "failed to lock config backend"); | |
60 | - | 5 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) return -1; | |
61 | - | } | ||
62 | - | |||
63 | - | 6 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) entries = b->entries; | |
64 | - | 6 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) git_config_entries_incref(entries); | |
65 | - | 7 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) git_mutex_unlock(&b->values_mutex); | |
66 | - | |||
67 | - | 8,9 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) if ((error = (git_config_entries_get(&entry, entries, key))) < 0) { | |
68 | - | 10 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) git_config_entries_free(entries); | |
69 | - | 11 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) return error; | |
70 | - | } | ||
71 | - | |||
72 | - | 12 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) entry->free = config_snapshot_entry_free; | |
73 | - | 12 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) entry->payload = entries; | |
74 | - | 12 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) *out = entry; | |
75 | - | |||
76 | - | 12 | suppressed: function cannot be solved config_snapshot_get (automatic due to inconsistent arc counts in .gcda files) return 0; | |
77 | - | } | ||
78 | - | |||
79 | ##### | 2 | static int config_snapshot_set(git_config_backend *cfg, const char *name, const char *value) | |
80 | - | { | ||
81 | - | GIT_UNUSED(cfg); | ||
82 | - | GIT_UNUSED(name); | ||
83 | - | GIT_UNUSED(value); | ||
84 | - | |||
85 | ##### | 2 | return config_error_readonly(); | |
86 | - | } | ||
87 | - | |||
88 | ##### | 2 | static int config_snapshot_set_multivar( | |
89 | - | git_config_backend *cfg, const char *name, const char *regexp, const char *value) | ||
90 | - | { | ||
91 | - | GIT_UNUSED(cfg); | ||
92 | - | GIT_UNUSED(name); | ||
93 | - | GIT_UNUSED(regexp); | ||
94 | - | GIT_UNUSED(value); | ||
95 | - | |||
96 | ##### | 2 | return config_error_readonly(); | |
97 | - | } | ||
98 | - | |||
99 | ##### | 2 | static int config_snapshot_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp) | |
100 | - | { | ||
101 | - | GIT_UNUSED(cfg); | ||
102 | - | GIT_UNUSED(name); | ||
103 | - | GIT_UNUSED(regexp); | ||
104 | - | |||
105 | ##### | 2 | return config_error_readonly(); | |
106 | - | } | ||
107 | - | |||
108 | ##### | 2 | static int config_snapshot_delete(git_config_backend *cfg, const char *name) | |
109 | - | { | ||
110 | - | GIT_UNUSED(cfg); | ||
111 | - | GIT_UNUSED(name); | ||
112 | - | |||
113 | ##### | 2 | return config_error_readonly(); | |
114 | - | } | ||
115 | - | |||
116 | ##### | 2 | static int config_snapshot_lock(git_config_backend *_cfg) | |
117 | - | { | ||
118 | - | GIT_UNUSED(_cfg); | ||
119 | - | |||
120 | ##### | 2 | return config_error_readonly(); | |
121 | - | } | ||
122 | - | |||
123 | ##### | 2 | static int config_snapshot_unlock(git_config_backend *_cfg, int success) | |
124 | - | { | ||
125 | - | GIT_UNUSED(_cfg); | ||
126 | - | GIT_UNUSED(success); | ||
127 | - | |||
128 | ##### | 2 | return config_error_readonly(); | |
129 | - | } | ||
130 | - | |||
131 | 47988 | 2 | static void config_snapshot_free(git_config_backend *_backend) | |
132 | - | { | ||
133 | 47988 | 2 | config_snapshot_backend *backend = GIT_CONTAINER_OF(_backend, config_snapshot_backend, parent); | |
134 | - | |||
135 | 47988 | 2 | if (backend == NULL) | |
136 | 47990 | 3,7 | return; | |
137 | - | |||
138 | 47988 | 4 | git_config_entries_free(backend->entries); | |
139 | 47990 | 5 | git_mutex_free(&backend->values_mutex); | |
140 | 47990 | 6 | git__free(backend); | |
141 | - | } | ||
142 | - | |||
143 | - | 2 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files)static int config_snapshot_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo) | |
144 | - | { | ||
145 | - | 2 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) config_snapshot_backend *b = GIT_CONTAINER_OF(cfg, config_snapshot_backend, parent); | |
146 | - | 2 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) git_config_entries *entries = NULL; | |
147 | - | 2 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) git_config_iterator *it = NULL; | |
148 | - | git_config_entry *entry; | ||
149 | - | int error; | ||
150 | - | |||
151 | - | /* We're just copying data, don't care about the level or repo*/ | ||
152 | - | GIT_UNUSED(level); | ||
153 | - | GIT_UNUSED(repo); | ||
154 | - | |||
155 | - | 2-5 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) if ((error = git_config_entries_new(&entries)) < 0 || | |
156 | - | 4 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) (error = b->source->iterator(&it, b->source)) < 0) | |
157 | - | goto out; | ||
158 | - | |||
159 | - | 6,10,11 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) while ((error = git_config_next(&entry, it)) == 0) | |
160 | - | 7,8 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) if ((error = git_config_entries_dup_entry(entries, entry)) < 0) | |
161 | - | 9 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) goto out; | |
162 | - | |||
163 | - | 12 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) if (error < 0) { | |
164 | - | 13 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) if (error != GIT_ITEROVER) | |
165 | - | 14 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) goto out; | |
166 | - | 15 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) error = 0; | |
167 | - | } | ||
168 | - | |||
169 | - | 16 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) b->entries = entries; | |
170 | - | |||
171 | - | out: | ||
172 | - | 17 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) git_config_iterator_free(it); | |
173 | - | 18 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) if (error) | |
174 | - | 19 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) git_config_entries_free(entries); | |
175 | - | 20 | suppressed: function cannot be solved config_snapshot_open (automatic due to inconsistent arc counts in .gcda files) return error; | |
176 | - | } | ||
177 | - | |||
178 | 47981 | 2 | int git_config_backend_snapshot(git_config_backend **out, git_config_backend *source) | |
179 | - | { | ||
180 | - | config_snapshot_backend *backend; | ||
181 | - | |||
182 | 47981 | 2 | backend = git__calloc(1, sizeof(config_snapshot_backend)); | |
183 | 47983 | 3,4 | GIT_ERROR_CHECK_ALLOC(backend); | |
184 | - | |||
185 | 47983 | 5 | backend->parent.version = GIT_CONFIG_BACKEND_VERSION; | |
186 | 47983 | 5 | git_mutex_init(&backend->values_mutex); | |
187 | - | |||
188 | 47981 | 6 | backend->source = source; | |
189 | - | |||
190 | 47981 | 6 | backend->parent.readonly = 1; | |
191 | 47981 | 6 | backend->parent.version = GIT_CONFIG_BACKEND_VERSION; | |
192 | 47981 | 6 | backend->parent.open = config_snapshot_open; | |
193 | 47981 | 6 | backend->parent.get = config_snapshot_get; | |
194 | 47981 | 6 | backend->parent.set = config_snapshot_set; | |
195 | 47981 | 6 | backend->parent.set_multivar = config_snapshot_set_multivar; | |
196 | 47981 | 6 | backend->parent.snapshot = git_config_backend_snapshot; | |
197 | 47981 | 6 | backend->parent.del = config_snapshot_delete; | |
198 | 47981 | 6 | backend->parent.del_multivar = config_snapshot_delete_multivar; | |
199 | 47981 | 6 | backend->parent.iterator = config_snapshot_iterator; | |
200 | 47981 | 6 | backend->parent.lock = config_snapshot_lock; | |
201 | 47981 | 6 | backend->parent.unlock = config_snapshot_unlock; | |
202 | 47981 | 6 | backend->parent.free = config_snapshot_free; | |
203 | - | |||
204 | 47981 | 6 | *out = &backend->parent; | |
205 | - | |||
206 | 47981 | 6 | return 0; | |
207 | - | } |