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_mwindow__file_limit; |
63
|
|
|
|
|
|
|
extern size_t git_indexer__max_objects; |
64
|
|
|
|
|
|
|
extern bool git_disable_pack_keep_file_checks; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
static int config_level_to_sysdir(int config_level) |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
|
|
|
int val = -1; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
switch (config_level) { |
71
|
|
|
|
|
|
|
case GIT_CONFIG_LEVEL_SYSTEM: |
72
|
0
|
|
|
|
|
|
val = GIT_SYSDIR_SYSTEM; |
73
|
0
|
|
|
|
|
|
break; |
74
|
|
|
|
|
|
|
case GIT_CONFIG_LEVEL_XDG: |
75
|
0
|
|
|
|
|
|
val = GIT_SYSDIR_XDG; |
76
|
0
|
|
|
|
|
|
break; |
77
|
|
|
|
|
|
|
case GIT_CONFIG_LEVEL_GLOBAL: |
78
|
0
|
|
|
|
|
|
val = GIT_SYSDIR_GLOBAL; |
79
|
0
|
|
|
|
|
|
break; |
80
|
|
|
|
|
|
|
case GIT_CONFIG_LEVEL_PROGRAMDATA: |
81
|
0
|
|
|
|
|
|
val = GIT_SYSDIR_PROGRAMDATA; |
82
|
0
|
|
|
|
|
|
break; |
83
|
|
|
|
|
|
|
default: |
84
|
0
|
|
|
|
|
|
git_error_set( |
85
|
|
|
|
|
|
|
GIT_ERROR_INVALID, "invalid config path selector %d", config_level); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return val; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
extern char *git__user_agent; |
92
|
|
|
|
|
|
|
extern char *git__ssl_ciphers; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
const char *git_libgit2__user_agent(void) |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
|
|
|
return git__user_agent; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
86
|
|
|
|
|
|
const char *git_libgit2__ssl_ciphers(void) |
100
|
|
|
|
|
|
|
{ |
101
|
86
|
|
|
|
|
|
return git__ssl_ciphers; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
int git_libgit2_opts(int key, ...) |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
|
|
|
int error = 0; |
107
|
|
|
|
|
|
|
va_list ap; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
va_start(ap, key); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
switch (key) { |
112
|
|
|
|
|
|
|
case GIT_OPT_SET_MWINDOW_SIZE: |
113
|
0
|
0
|
|
|
|
|
git_mwindow__window_size = va_arg(ap, size_t); |
114
|
0
|
|
|
|
|
|
break; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
case GIT_OPT_GET_MWINDOW_SIZE: |
117
|
0
|
0
|
|
|
|
|
*(va_arg(ap, size_t *)) = git_mwindow__window_size; |
118
|
0
|
|
|
|
|
|
break; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT: |
121
|
0
|
0
|
|
|
|
|
git_mwindow__mapped_limit = va_arg(ap, size_t); |
122
|
0
|
|
|
|
|
|
break; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
case GIT_OPT_GET_MWINDOW_MAPPED_LIMIT: |
125
|
0
|
0
|
|
|
|
|
*(va_arg(ap, size_t *)) = git_mwindow__mapped_limit; |
126
|
0
|
|
|
|
|
|
break; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
case GIT_OPT_SET_MWINDOW_FILE_LIMIT: |
129
|
0
|
0
|
|
|
|
|
git_mwindow__file_limit = va_arg(ap, size_t); |
130
|
0
|
|
|
|
|
|
break; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
case GIT_OPT_GET_MWINDOW_FILE_LIMIT: |
133
|
0
|
0
|
|
|
|
|
*(va_arg(ap, size_t *)) = git_mwindow__file_limit; |
134
|
0
|
|
|
|
|
|
break; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
case GIT_OPT_GET_SEARCH_PATH: |
137
|
0
|
0
|
|
|
|
|
if ((error = config_level_to_sysdir(va_arg(ap, int))) >= 0) { |
|
|
0
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
git_buf *out = va_arg(ap, git_buf *); |
139
|
|
|
|
|
|
|
const git_buf *tmp; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
git_buf_sanitize(out); |
142
|
0
|
0
|
|
|
|
|
if ((error = git_sysdir_get(&tmp, error)) < 0) |
143
|
0
|
|
|
|
|
|
break; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
error = git_buf_sets(out, tmp->ptr); |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
break; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
case GIT_OPT_SET_SEARCH_PATH: |
150
|
0
|
0
|
|
|
|
|
if ((error = config_level_to_sysdir(va_arg(ap, int))) >= 0) |
|
|
0
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
error = git_sysdir_set(error, va_arg(ap, const char *)); |
152
|
0
|
|
|
|
|
|
break; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
case GIT_OPT_SET_CACHE_OBJECT_LIMIT: |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
0
|
|
|
|
|
git_object_t type = (git_object_t)va_arg(ap, int); |
157
|
0
|
0
|
|
|
|
|
size_t size = va_arg(ap, size_t); |
158
|
0
|
|
|
|
|
|
error = git_cache_set_max_object_size(type, size); |
159
|
0
|
|
|
|
|
|
break; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
case GIT_OPT_SET_CACHE_MAX_SIZE: |
163
|
0
|
0
|
|
|
|
|
git_cache__max_storage = va_arg(ap, ssize_t); |
164
|
0
|
|
|
|
|
|
break; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_CACHING: |
167
|
0
|
0
|
|
|
|
|
git_cache__enabled = (va_arg(ap, int) != 0); |
168
|
0
|
|
|
|
|
|
break; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
case GIT_OPT_GET_CACHED_MEMORY: |
171
|
0
|
0
|
|
|
|
|
*(va_arg(ap, ssize_t *)) = git_cache__current_storage.val; |
172
|
0
|
0
|
|
|
|
|
*(va_arg(ap, ssize_t *)) = git_cache__max_storage; |
173
|
0
|
|
|
|
|
|
break; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
case GIT_OPT_GET_TEMPLATE_PATH: |
176
|
|
|
|
|
|
|
{ |
177
|
0
|
0
|
|
|
|
|
git_buf *out = va_arg(ap, git_buf *); |
178
|
|
|
|
|
|
|
const git_buf *tmp; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
git_buf_sanitize(out); |
181
|
0
|
0
|
|
|
|
|
if ((error = git_sysdir_get(&tmp, GIT_SYSDIR_TEMPLATE)) < 0) |
182
|
0
|
|
|
|
|
|
break; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
error = git_buf_sets(out, tmp->ptr); |
185
|
|
|
|
|
|
|
} |
186
|
0
|
|
|
|
|
|
break; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
case GIT_OPT_SET_TEMPLATE_PATH: |
189
|
0
|
0
|
|
|
|
|
error = git_sysdir_set(GIT_SYSDIR_TEMPLATE, va_arg(ap, const char *)); |
190
|
0
|
|
|
|
|
|
break; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
case GIT_OPT_SET_SSL_CERT_LOCATIONS: |
193
|
|
|
|
|
|
|
#ifdef GIT_OPENSSL |
194
|
|
|
|
|
|
|
{ |
195
|
0
|
0
|
|
|
|
|
const char *file = va_arg(ap, const char *); |
196
|
0
|
0
|
|
|
|
|
const char *path = va_arg(ap, const char *); |
197
|
0
|
|
|
|
|
|
error = git_openssl__set_cert_location(file, path); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
#elif defined(GIT_MBEDTLS) |
200
|
|
|
|
|
|
|
{ |
201
|
|
|
|
|
|
|
const char *file = va_arg(ap, const char *); |
202
|
|
|
|
|
|
|
const char *path = va_arg(ap, const char *); |
203
|
|
|
|
|
|
|
if (file) |
204
|
|
|
|
|
|
|
error = git_mbedtls__set_cert_location(file, 0); |
205
|
|
|
|
|
|
|
if (error && path) |
206
|
|
|
|
|
|
|
error = git_mbedtls__set_cert_location(path, 1); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
#else |
209
|
|
|
|
|
|
|
git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support certificate locations"); |
210
|
|
|
|
|
|
|
error = -1; |
211
|
|
|
|
|
|
|
#endif |
212
|
0
|
|
|
|
|
|
break; |
213
|
|
|
|
|
|
|
case GIT_OPT_SET_USER_AGENT: |
214
|
0
|
|
|
|
|
|
git__free(git__user_agent); |
215
|
0
|
0
|
|
|
|
|
git__user_agent = git__strdup(va_arg(ap, const char *)); |
216
|
0
|
0
|
|
|
|
|
if (!git__user_agent) { |
217
|
0
|
|
|
|
|
|
git_error_set_oom(); |
218
|
0
|
|
|
|
|
|
error = -1; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
break; |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_STRICT_OBJECT_CREATION: |
224
|
0
|
0
|
|
|
|
|
git_object__strict_input_validation = (va_arg(ap, int) != 0); |
225
|
0
|
|
|
|
|
|
break; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION: |
228
|
0
|
0
|
|
|
|
|
git_reference__enable_symbolic_ref_target_validation = (va_arg(ap, int) != 0); |
229
|
0
|
|
|
|
|
|
break; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
case GIT_OPT_SET_SSL_CIPHERS: |
232
|
|
|
|
|
|
|
#if (GIT_OPENSSL || GIT_MBEDTLS) |
233
|
|
|
|
|
|
|
{ |
234
|
0
|
|
|
|
|
|
git__free(git__ssl_ciphers); |
235
|
0
|
0
|
|
|
|
|
git__ssl_ciphers = git__strdup(va_arg(ap, const char *)); |
236
|
0
|
0
|
|
|
|
|
if (!git__ssl_ciphers) { |
237
|
0
|
|
|
|
|
|
git_error_set_oom(); |
238
|
0
|
|
|
|
|
|
error = -1; |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
#else |
242
|
|
|
|
|
|
|
git_error_set(GIT_ERROR_SSL, "TLS backend doesn't support custom ciphers"); |
243
|
|
|
|
|
|
|
error = -1; |
244
|
|
|
|
|
|
|
#endif |
245
|
0
|
|
|
|
|
|
break; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
case GIT_OPT_GET_USER_AGENT: |
248
|
|
|
|
|
|
|
{ |
249
|
0
|
0
|
|
|
|
|
git_buf *out = va_arg(ap, git_buf *); |
250
|
0
|
|
|
|
|
|
git_buf_sanitize(out); |
251
|
0
|
|
|
|
|
|
error = git_buf_sets(out, git__user_agent); |
252
|
|
|
|
|
|
|
} |
253
|
0
|
|
|
|
|
|
break; |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_OFS_DELTA: |
256
|
0
|
0
|
|
|
|
|
git_smart__ofs_delta_enabled = (va_arg(ap, int) != 0); |
257
|
0
|
|
|
|
|
|
break; |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_FSYNC_GITDIR: |
260
|
0
|
0
|
|
|
|
|
git_repository__fsync_gitdir = (va_arg(ap, int) != 0); |
261
|
0
|
|
|
|
|
|
break; |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
case GIT_OPT_GET_WINDOWS_SHAREMODE: |
264
|
|
|
|
|
|
|
#ifdef GIT_WIN32 |
265
|
|
|
|
|
|
|
*(va_arg(ap, unsigned long *)) = git_win32__createfile_sharemode; |
266
|
|
|
|
|
|
|
#endif |
267
|
0
|
|
|
|
|
|
break; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
case GIT_OPT_SET_WINDOWS_SHAREMODE: |
270
|
|
|
|
|
|
|
#ifdef GIT_WIN32 |
271
|
|
|
|
|
|
|
git_win32__createfile_sharemode = va_arg(ap, unsigned long); |
272
|
|
|
|
|
|
|
#endif |
273
|
0
|
|
|
|
|
|
break; |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION: |
276
|
0
|
0
|
|
|
|
|
git_odb__strict_hash_verification = (va_arg(ap, int) != 0); |
277
|
0
|
|
|
|
|
|
break; |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
case GIT_OPT_SET_ALLOCATOR: |
280
|
0
|
0
|
|
|
|
|
error = git_allocator_setup(va_arg(ap, git_allocator *)); |
281
|
0
|
|
|
|
|
|
break; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY: |
284
|
0
|
0
|
|
|
|
|
git_index__enforce_unsaved_safety = (va_arg(ap, int) != 0); |
285
|
0
|
|
|
|
|
|
break; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
case GIT_OPT_SET_PACK_MAX_OBJECTS: |
288
|
0
|
0
|
|
|
|
|
git_indexer__max_objects = va_arg(ap, size_t); |
289
|
0
|
|
|
|
|
|
break; |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
case GIT_OPT_GET_PACK_MAX_OBJECTS: |
292
|
0
|
0
|
|
|
|
|
*(va_arg(ap, size_t *)) = git_indexer__max_objects; |
293
|
0
|
|
|
|
|
|
break; |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS: |
296
|
0
|
0
|
|
|
|
|
git_disable_pack_keep_file_checks = (va_arg(ap, int) != 0); |
297
|
0
|
|
|
|
|
|
break; |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
case GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE: |
300
|
0
|
0
|
|
|
|
|
git_http__expect_continue = (va_arg(ap, int) != 0); |
301
|
0
|
|
|
|
|
|
break; |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
default: |
304
|
0
|
|
|
|
|
|
git_error_set(GIT_ERROR_INVALID, "invalid option key"); |
305
|
0
|
|
|
|
|
|
error = -1; |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
0
|
|
|
|
|
|
va_end(ap); |
309
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
|
return error; |
311
|
|
|
|
|
|
|
} |