line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 "common.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#ifdef GIT_OPENSSL |
11
|
|
|
|
|
|
|
# include |
12
|
|
|
|
|
|
|
#endif |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#ifdef GIT_MBEDTLS |
15
|
|
|
|
|
|
|
# include |
16
|
|
|
|
|
|
|
#endif |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#include |
19
|
|
|
|
|
|
|
#include "alloc.h" |
20
|
|
|
|
|
|
|
#include "sysdir.h" |
21
|
|
|
|
|
|
|
#include "cache.h" |
22
|
|
|
|
|
|
|
#include "global.h" |
23
|
|
|
|
|
|
|
#include "object.h" |
24
|
|
|
|
|
|
|
#include "odb.h" |
25
|
|
|
|
|
|
|
#include "refs.h" |
26
|
|
|
|
|
|
|
#include "index.h" |
27
|
|
|
|
|
|
|
#include "transports/smart.h" |
28
|
|
|
|
|
|
|
#include "transports/http.h" |
29
|
|
|
|
|
|
|
#include "streams/openssl.h" |
30
|
|
|
|
|
|
|
#include "streams/mbedtls.h" |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
int git_libgit2_version(int *major, int *minor, int *rev) |
33
|
|
|
|
|
|
|
{ |
34
|
0
|
|
|
|
|
|
*major = LIBGIT2_VER_MAJOR; |
35
|
0
|
|
|
|
|
|
*minor = LIBGIT2_VER_MINOR; |
36
|
0
|
|
|
|
|
|
*rev = LIBGIT2_VER_REVISION; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
|
int git_libgit2_features(void) |
42
|
|
|
|
|
|
|
{ |
43
|
1
|
|
|
|
|
|
return 0 |
44
|
|
|
|
|
|
|
#ifdef GIT_THREADS |
45
|
|
|
|
|
|
|
| GIT_FEATURE_THREADS |
46
|
|
|
|
|
|
|
#endif |
47
|
|
|
|
|
|
|
#ifdef GIT_HTTPS |
48
|
|
|
|
|
|
|
| GIT_FEATURE_HTTPS |
49
|
|
|
|
|
|
|
#endif |
50
|
|
|
|
|
|
|
#if defined(GIT_SSH) |
51
|
|
|
|
|
|
|
| GIT_FEATURE_SSH |
52
|
|
|
|
|
|
|
#endif |
53
|
|
|
|
|
|
|
#if defined(GIT_USE_NSEC) |
54
|
|
|
|
|
|
|
| GIT_FEATURE_NSEC |
55
|
|
|
|
|
|
|
#endif |
56
|
|
|
|
|
|
|
; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
/* Declarations for tuneable settings */ |
60
|
|
|
|
|
|
|
extern size_t git_mwindow__window_size; |
61
|
|
|
|
|
|
|
extern size_t git_mwindow__mapped_limit; |
62
|
|
|
|
|
|
|
extern size_t git_indexer__max_objects; |
63
|
|
|
|
|
|
|
extern bool git_disable_pack_keep_file_checks; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
static int config_level_to_sysdir(int config_level) |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
|
int val = -1; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
switch (config_level) { |
70
|
|
|
|
|
|
|
case GIT_CONFIG_LEVEL_SYSTEM: |
71
|
0
|
|
|
|
|
|
val = GIT_SYSDIR_SYSTEM; |
72
|
0
|
|
|
|
|
|
break; |
73
|
|
|
|
|
|
|
case GIT_CONFIG_LEVEL_XDG: |
74
|
0
|
|
|
|
|
|
val = GIT_SYSDIR_XDG; |
75
|
0
|
|
|
|
|
|
break; |
76
|
|
|
|
|
|
|
case GIT_CONFIG_LEVEL_GLOBAL: |
77
|
0
|
|
|
|
|
|
val = GIT_SYSDIR_GLOBAL; |
78
|
0
|
|
|
|
|
|
break; |
79
|
|
|
|
|
|
|
case GIT_CONFIG_LEVEL_PROGRAMDATA: |
80
|
0
|
|
|
|
|
|
val = GIT_SYSDIR_PROGRAMDATA; |
81
|
0
|
|
|
|
|
|
break; |
82
|
|
|
|
|
|
|
default: |
83
|
0
|
|
|
|
|
|
git_error_set( |
84
|
|
|
|
|
|
|
GIT_ERROR_INVALID, "invalid config path selector %d", config_level); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return val; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
extern char *git__user_agent; |
91
|
|
|
|
|
|
|
extern char *git__ssl_ciphers; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
const char *git_libgit2__user_agent(void) |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
|
return git__user_agent; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
86
|
|
|
|
|
|
const char *git_libgit2__ssl_ciphers(void) |
99
|
|
|
|
|
|
|
{ |
100
|
86
|
|
|
|
|
|
return git__ssl_ciphers; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
int git_libgit2_opts(int key, ...) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
|
int error = 0; |
106
|
|
|
|
|
|
|
va_list ap; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
va_start(ap, key); |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
switch (key) { |
111
|
|
|
|
|
|
|
case GIT_OPT_SET_MWINDOW_SIZE: |
112
|
0
|
0
|
|
|
|
|
git_mwindow__window_size = va_arg(ap, size_t); |
113
|
0
|
|
|
|
|
|
break; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
case GIT_OPT_GET_MWINDOW_SIZE: |
116
|
0
|
0
|
|
|
|
|
*(va_arg(ap, size_t *)) = git_mwindow__window_size; |
117
|
0
|
|
|
|
|
|
break; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT: |
120
|
0
|
0
|
|
|
|
|
git_mwindow__mapped_limit = va_arg(ap, size_t); |
121
|
0
|
|
|
|
|
|
break; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
case GIT_OPT_GET_MWINDOW_MAPPED_LIMIT: |
124
|
0
|
0
|
|
|
|
|
*(va_arg(ap, size_t *)) = git_mwindow__mapped_limit; |
125
|
0
|
|
|
|
|
|
break; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
case GIT_OPT_GET_SEARCH_PATH: |
128
|
0
|
0
|
|
|
|
|
if ((error = config_level_to_sysdir(va_arg(ap, int))) >= 0) { |
|
|
0
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
git_buf *out = va_arg(ap, git_buf *); |
130
|
|
|
|
|
|
|
const git_buf *tmp; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
git_buf_sanitize(out); |
133
|
0
|
0
|
|
|
|
|
if ((error = git_sysdir_get(&tmp, error)) < 0) |
134
|
0
|
|
|
|
|
|
break; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
error = git_buf_sets(out, tmp->ptr); |
137
|
|
|
|
|
|
|
} |
138
|
0
|
|
|
|
|
|
break; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
case GIT_OPT_SET_SEARCH_PATH: |
141
|
0
|
0
|
|
|
|
|
if ((error = config_level_to_sysdir(va_arg(ap, int))) >= 0) |
|
|
0
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
error = git_sysdir_set(error, va_arg(ap, const char *)); |
143
|
0
|
|
|
|
|
|
break; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
case GIT_OPT_SET_CACHE_OBJECT_LIMIT: |
146
|
|
|
|
|
|
|
{ |
147
|
0
|
0
|
|
|
|
|
git_object_t type = (git_object_t)va_arg(ap, int); |
148
|
0
|
0
|
|
|
|
|
size_t size = va_arg(ap, size_t); |
149
|
0
|
|
|
|
|
|
error = git_cache_set_max_object_size(type, size); |
150
|
0
|
|
|
|
|
|
break; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
case GIT_OPT_SET_CACHE_MAX_SIZE: |
154
|
0
|
0
|
|
|
|
|
git_cache__max_storage = va_arg(ap, ssize_t); |
155
|
0
|
|
|
|
|
|
break; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_CACHING: |
158
|
0
|
0
|
|
|
|
|
git_cache__enabled = (va_arg(ap, int) != 0); |
159
|
0
|
|
|
|
|
|
break; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
case GIT_OPT_GET_CACHED_MEMORY: |
162
|
0
|
0
|
|
|
|
|
*(va_arg(ap, ssize_t *)) = git_cache__current_storage.val; |
163
|
0
|
0
|
|
|
|
|
*(va_arg(ap, ssize_t *)) = git_cache__max_storage; |
164
|
0
|
|
|
|
|
|
break; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
case GIT_OPT_GET_TEMPLATE_PATH: |
167
|
|
|
|
|
|
|
{ |
168
|
0
|
0
|
|
|
|
|
git_buf *out = va_arg(ap, git_buf *); |
169
|
|
|
|
|
|
|
const git_buf *tmp; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
git_buf_sanitize(out); |
172
|
0
|
0
|
|
|
|
|
if ((error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0) |
173
|
0
|
|
|
|
|
|
break; |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
error = git_buf_sets(out, tmp->ptr); |
176
|
|
|
|
|
|
|
} |
177
|
0
|
|
|
|
|
|
break; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
case GIT_OPT_SET_TEMPLATE_PATH: |
180
|
0
|
0
|
|
|
|
|
error = git_sysdir_set(GIT_SYSDIR_TEMPLATE, va_arg(ap, const char *)); |
181
|
0
|
|
|
|
|
|
break; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
case GIT_OPT_SET_SSL_CERT_LOCATIONS: |
184
|
|
|
|
|
|
|
#ifdef GIT_OPENSSL |
185
|
|
|
|
|
|
|
{ |
186
|
0
|
0
|
|
|
|
|
const char *file = va_arg(ap, const char *); |
187
|
0
|
0
|
|
|
|
|
const char *path = va_arg(ap, const char *); |
188
|
0
|
|
|
|
|
|
error = git_openssl__set_cert_location(file, path); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
#elif defined(GIT_MBEDTLS) |
191
|
|
|
|
|
|
|
{ |
192
|
|
|
|
|
|
|
const char *file = va_arg(ap, const char *); |
193
|
|
|
|
|
|
|
const char *path = va_arg(ap, const char *); |
194
|
|
|
|
|
|
|
if (file) |
195
|
|
|
|
|
|
|
error = git_mbedtls__set_cert_location(file, 0); |
196
|
|
|
|
|
|
|
if (error && path) |
197
|
|
|
|
|
|
|
error = git_mbedtls__set_cert_location(path, 1); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
#else |
200
|
|
|
|
|
|
|
git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support certificate locations"); |
201
|
|
|
|
|
|
|
error = -1; |
202
|
|
|
|
|
|
|
#endif |
203
|
0
|
|
|
|
|
|
break; |
204
|
|
|
|
|
|
|
case GIT_OPT_SET_USER_AGENT: |
205
|
0
|
|
|
|
|
|
git__free(git__user_agent); |
206
|
0
|
0
|
|
|
|
|
git__user_agent = git__strdup(va_arg(ap, const char *)); |
207
|
0
|
0
|
|
|
|
|
if (!git__user_agent) { |
208
|
0
|
|
|
|
|
|
git_error_set_oom(); |
209
|
0
|
|
|
|
|
|
error = -1; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
break; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_STRICT_OBJECT_CREATION: |
215
|
0
|
0
|
|
|
|
|
git_object__strict_input_validation = (va_arg(ap, int) != 0); |
216
|
0
|
|
|
|
|
|
break; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION: |
219
|
0
|
0
|
|
|
|
|
git_reference__enable_symbolic_ref_target_validation = (va_arg(ap, int) != 0); |
220
|
0
|
|
|
|
|
|
break; |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
case GIT_OPT_SET_SSL_CIPHERS: |
223
|
|
|
|
|
|
|
#if (GIT_OPENSSL || GIT_MBEDTLS) |
224
|
|
|
|
|
|
|
{ |
225
|
0
|
|
|
|
|
|
git__free(git__ssl_ciphers); |
226
|
0
|
0
|
|
|
|
|
git__ssl_ciphers = git__strdup(va_arg(ap, const char *)); |
227
|
0
|
0
|
|
|
|
|
if (!git__ssl_ciphers) { |
228
|
0
|
|
|
|
|
|
git_error_set_oom(); |
229
|
0
|
|
|
|
|
|
error = -1; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
#else |
233
|
|
|
|
|
|
|
git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support custom ciphers"); |
234
|
|
|
|
|
|
|
error = -1; |
235
|
|
|
|
|
|
|
#endif |
236
|
0
|
|
|
|
|
|
break; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
case GIT_OPT_GET_USER_AGENT: |
239
|
|
|
|
|
|
|
{ |
240
|
0
|
0
|
|
|
|
|
git_buf *out = va_arg(ap, git_buf *); |
241
|
0
|
|
|
|
|
|
git_buf_sanitize(out); |
242
|
0
|
|
|
|
|
|
error = git_buf_sets(out, git__user_agent); |
243
|
|
|
|
|
|
|
} |
244
|
0
|
|
|
|
|
|
break; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_OFS_DELTA: |
247
|
0
|
0
|
|
|
|
|
git_smart__ofs_delta_enabled = (va_arg(ap, int) != 0); |
248
|
0
|
|
|
|
|
|
break; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_FSYNC_GITDIR: |
251
|
0
|
0
|
|
|
|
|
git_repository__fsync_gitdir = (va_arg(ap, int) != 0); |
252
|
0
|
|
|
|
|
|
break; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
case GIT_OPT_GET_WINDOWS_SHAREMODE: |
255
|
|
|
|
|
|
|
#ifdef GIT_WIN32 |
256
|
|
|
|
|
|
|
*(va_arg(ap, unsigned long *)) = git_win32__createfile_sharemode; |
257
|
|
|
|
|
|
|
#endif |
258
|
0
|
|
|
|
|
|
break; |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
case GIT_OPT_SET_WINDOWS_SHAREMODE: |
261
|
|
|
|
|
|
|
#ifdef GIT_WIN32 |
262
|
|
|
|
|
|
|
git_win32__createfile_sharemode = va_arg(ap, unsigned long); |
263
|
|
|
|
|
|
|
#endif |
264
|
0
|
|
|
|
|
|
break; |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION: |
267
|
0
|
0
|
|
|
|
|
git_odb__strict_hash_verification = (va_arg(ap, int) != 0); |
268
|
0
|
|
|
|
|
|
break; |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
case GIT_OPT_SET_ALLOCATOR: |
271
|
0
|
0
|
|
|
|
|
error = git_allocator_setup(va_arg(ap, git_allocator *)); |
272
|
0
|
|
|
|
|
|
break; |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY: |
275
|
0
|
0
|
|
|
|
|
git_index__enforce_unsaved_safety = (va_arg(ap, int) != 0); |
276
|
0
|
|
|
|
|
|
break; |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
case GIT_OPT_SET_PACK_MAX_OBJECTS: |
279
|
0
|
0
|
|
|
|
|
git_indexer__max_objects = va_arg(ap, size_t); |
280
|
0
|
|
|
|
|
|
break; |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
case GIT_OPT_GET_PACK_MAX_OBJECTS: |
283
|
0
|
0
|
|
|
|
|
*(va_arg(ap, size_t *)) = git_indexer__max_objects; |
284
|
0
|
|
|
|
|
|
break; |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS: |
287
|
0
|
0
|
|
|
|
|
git_disable_pack_keep_file_checks = (va_arg(ap, int) != 0); |
288
|
0
|
|
|
|
|
|
break; |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE: |
291
|
0
|
0
|
|
|
|
|
git_http__expect_continue = (va_arg(ap, int) != 0); |
292
|
0
|
|
|
|
|
|
break; |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
default: |
295
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_INVALID, "invalid option key"); |
296
|
0
|
|
|
|
|
|
error = -1; |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
0
|
|
|
|
|
|
va_end(ap); |
300
|
|
|
|
|
|
|
|
301
|
0
|
|
|
|
|
|
return error; |
302
|
|
|
|
|
|
|
} |