deps/libgit2/src/libgit2/config_snapshot.c

filter: Statementstmt 65.4% 72 / 110 Branchbran 61.1% 11 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 64.8% 83 / 128 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« deps/libgit2/src/libgit2/delta.c ↑ Summary deps/libgit2/src/libgit2/threadstate.c »
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 0 static int config_error_readonly(void)
21 {
22 0 git_error_set(GIT_ERROR_CONFIG, "this backend is read-only");
23 0 return -1;
24 }
25  
26 106 static int config_snapshot_iterator(
27 git_config_iterator **iter,
28 struct git_config_backend *backend)
29 {
30 106 config_snapshot_backend *b = GIT_CONTAINER_OF(backend, config_snapshot_backend, parent);
31 106 git_config_entries *entries = NULL;
32 int error;
33  
34 212 if ((error = git_config_entries_dup(&entries, b->entries)) < 0 ||
35 106 (error = git_config_entries_iterator_new(iter, entries)) < 0)
36 0 goto out;
37  
38 106 out:
39 /* Let iterator delete duplicated entries when it's done */
40 106 git_config_entries_free(entries);
41 106 return error;
42 }
43  
44 /* release the map containing the entry as an equivalent to freeing it */
45 824 static void config_snapshot_entry_free(git_config_entry *entry)
46 {
47 824 git_config_entries *entries = (git_config_entries *) entry->payload;
48 824 git_config_entries_free(entries);
49 824 }
50  
51 4330 static int config_snapshot_get(git_config_backend *cfg, const char *key, git_config_entry **out)
52 {
53 4330 config_snapshot_backend *b = GIT_CONTAINER_OF(cfg, config_snapshot_backend, parent);
54 4330 git_config_entries *entries = NULL;
55 git_config_entry *entry;
56 4330 int error = 0;
57  
58 4330 ▶ if (git_mutex_lock(&b->values_mutex) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_mutex_lock(&b->values_mutex) < 0) { 0 4330 4330
59 0 git_error_set(GIT_ERROR_OS, "failed to lock config backend");
60 0 return -1;
61 }
62  
63 4330 entries = b->entries;
64 4330 git_config_entries_incref(entries);
65 4330 git_mutex_unlock(&b->values_mutex);
66  
67 4330 ▶ if ((error = (git_config_entries_get(&entry, entries, key))) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((error = (git_config_entries_get(&entry, entries, key))) < 0) { 3506 824 4330
68 3506 git_config_entries_free(entries);
69 3506 return error;
70 }
71  
72 824 entry->free = config_snapshot_entry_free;
73 824 entry->payload = entries;
74 824 *out = entry;
75  
76 824 return 0;
77 }
78  
79 0 static int config_snapshot_set(git_config_backend *cfg, const char *name, const char *value)
80 {
81 0 GIT_UNUSED(cfg);
82 0 GIT_UNUSED(name);
83 0 GIT_UNUSED(value);
84  
85 0 return config_error_readonly();
86 }
87  
88 0 static int config_snapshot_set_multivar(
89 git_config_backend *cfg, const char *name, const char *regexp, const char *value)
90 {
91 0 GIT_UNUSED(cfg);
92 0 GIT_UNUSED(name);
93 0 GIT_UNUSED(regexp);
94 0 GIT_UNUSED(value);
95  
96 0 return config_error_readonly();
97 }
98  
99 0 static int config_snapshot_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp)
100 {
101 0 GIT_UNUSED(cfg);
102 0 GIT_UNUSED(name);
103 0 GIT_UNUSED(regexp);
104  
105 0 return config_error_readonly();
106 }
107  
108 0 static int config_snapshot_delete(git_config_backend *cfg, const char *name)
109 {
110 0 GIT_UNUSED(cfg);
111 0 GIT_UNUSED(name);
112  
113 0 return config_error_readonly();
114 }
115  
116 0 static int config_snapshot_lock(git_config_backend *_cfg)
117 {
118 0 GIT_UNUSED(_cfg);
119  
120 0 return config_error_readonly();
121 }
122  
123 0 static int config_snapshot_unlock(git_config_backend *_cfg, int success)
124 {
125 0 GIT_UNUSED(_cfg);
126 0 GIT_UNUSED(success);
127  
128 0 return config_error_readonly();
129 }
130  
131 1012 static void config_snapshot_free(git_config_backend *_backend)
132 {
133 1012 config_snapshot_backend *backend = GIT_CONTAINER_OF(_backend, config_snapshot_backend, parent);
134  
135 1012 ▶ if (backend == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (backend == NULL) 0 1012 1012
136 0 return;
137  
138 1012 git_config_entries_free(backend->entries);
139 1012 git_mutex_free(&backend->values_mutex);
140 1012 git__free(backend);
141 }
142  
143 1012 static int config_snapshot_open(git_config_backend *cfg, git_config_level_t level, const git_repository *repo)
144 {
145 1012 config_snapshot_backend *b = GIT_CONTAINER_OF(cfg, config_snapshot_backend, parent);
146 1012 git_config_entries *entries = NULL;
147 1012 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 1012 GIT_UNUSED(level);
153 1012 GIT_UNUSED(repo);
154  
155 2024 if ((error = git_config_entries_new(&entries)) < 0 ||
156 1012 (error = b->source->iterator(&it, b->source)) < 0)
157 0 goto out;
158  
159 8495 ▶ while ((error = git_config_next(&entry, it)) == 0)
Branch: 1 branch
BranchTrueFalseTotal
while ((error = git_config_next(&entry, it)) == 0) 7483 1012 8495
160 7483 ▶ if ((error = git_config_entries_dup_entry(entries, entry)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_config_entries_dup_entry(entries, entry)) < 0) 0 7483 7483
161 0 goto out;
162  
163 1012 ▶ if (error < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) { 1012 0 1012
164 1012 ▶ if (error != GIT_ITEROVER)
Branch: 1 branch
BranchTrueFalseTotal
if (error != GIT_ITEROVER) 0 1012 1012
165 0 goto out;
166 1012 error = 0;
167 }
168  
169 1012 b->entries = entries;
170  
171 1012 out:
172 1012 git_config_iterator_free(it);
173 1012 ▶ if (error)
Branch: 1 branch
BranchTrueFalseTotal
if (error) 0 1012 1012
174 0 git_config_entries_free(entries);
175 1012 return error;
176 }
177  
178 1012 int git_config_backend_snapshot(git_config_backend **out, git_config_backend *source)
179 {
180 config_snapshot_backend *backend;
181  
182 1012 backend = git__calloc(1, sizeof(config_snapshot_backend));
183 1012 ▶ GIT_ERROR_CHECK_ALLOC(backend);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(backend); 0 1012 1012
184  
185 1012 backend->parent.version = GIT_CONFIG_BACKEND_VERSION;
186 1012 git_mutex_init(&backend->values_mutex);
187  
188 1012 backend->source = source;
189  
190 1012 backend->parent.readonly = 1;
191 1012 backend->parent.version = GIT_CONFIG_BACKEND_VERSION;
192 1012 backend->parent.open = config_snapshot_open;
193 1012 backend->parent.get = config_snapshot_get;
194 1012 backend->parent.set = config_snapshot_set;
195 1012 backend->parent.set_multivar = config_snapshot_set_multivar;
196 1012 backend->parent.snapshot = git_config_backend_snapshot;
197 1012 backend->parent.del = config_snapshot_delete;
198 1012 backend->parent.del_multivar = config_snapshot_delete_multivar;
199 1012 backend->parent.iterator = config_snapshot_iterator;
200 1012 backend->parent.lock = config_snapshot_lock;
201 1012 backend->parent.unlock = config_snapshot_unlock;
202 1012 backend->parent.free = config_snapshot_free;
203  
204 1012 *out = &backend->parent;
205  
206 1012 return 0;
207 }
« deps/libgit2/src/libgit2/delta.c ↑ Summary deps/libgit2/src/libgit2/threadstate.c »