File tree 5 files changed +37
-0
lines changed 5 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,7 @@ typedef enum {
145
145
GIT_OPT_GET_TEMPLATE_PATH ,
146
146
GIT_OPT_SET_TEMPLATE_PATH ,
147
147
GIT_OPT_SET_SSL_CERT_LOCATIONS ,
148
+ GIT_OPT_SET_USER_AGENT ,
148
149
} git_libgit2_opt_t ;
149
150
150
151
/**
@@ -240,6 +241,8 @@ typedef enum {
240
241
* >
241
242
* > Either parameter may be `NULL`, but not both.
242
243
*
244
+ * * opts(GIT_OPT_SET_USER_AGENT, const char *user_agent)
245
+ *
243
246
* @param option Option key
244
247
* @param ... value to set the option
245
248
* @return 0 on success, <0 on failure
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ static git_mutex *openssl_locks;
31
31
static git_global_shutdown_fn git__shutdown_callbacks [MAX_SHUTDOWN_CB ];
32
32
static git_atomic git__n_shutdown_callbacks ;
33
33
static git_atomic git__n_inits ;
34
+ char * git__user_agent ;
34
35
35
36
void git__on_shutdown (git_global_shutdown_fn callback )
36
37
{
@@ -269,6 +270,8 @@ int git_libgit2_shutdown(void)
269
270
git_win32__crtdbg_stacktrace_cleanup ();
270
271
git_win32__stack_cleanup ();
271
272
#endif
273
+
274
+ git__free (git__user_agent );
272
275
}
273
276
274
277
/* Exit the lock */
@@ -369,6 +372,7 @@ int git_libgit2_shutdown(void)
369
372
370
373
git__global_state_cleanup (ptr );
371
374
git__free (ptr );
375
+ git__free (git__user_agent );
372
376
373
377
pthread_key_delete (_tls_key );
374
378
git_mutex_free (& git__mwindow_mutex );
@@ -423,6 +427,7 @@ int git_libgit2_shutdown(void)
423
427
git__shutdown ();
424
428
git__global_state_cleanup (& __state );
425
429
uninit_ssl ();
430
+ git__free (git__user_agent );
426
431
427
432
return 0 ;
428
433
}
Original file line number Diff line number Diff line change @@ -35,4 +35,6 @@ extern void git__on_shutdown(git_global_shutdown_fn callback);
35
35
36
36
extern void git__free_tls_data (void );
37
37
38
+ extern const char * git_libgit2__user_agent (void );
39
+
38
40
#endif
Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ static int config_level_to_sysdir(int config_level)
57
57
return val ;
58
58
}
59
59
60
+ extern char * git__user_agent ;
61
+
62
+ const char * git_libgit2__user_agent ()
63
+ {
64
+ return git__user_agent ;
65
+ }
66
+
60
67
int git_libgit2_opts (int key , ...)
61
68
{
62
69
int error = 0 ;
@@ -152,6 +159,15 @@ int git_libgit2_opts(int key, ...)
152
159
giterr_set (GITERR_NET , "Cannot set certificate locations: OpenSSL is not enabled" );
153
160
error = -1 ;
154
161
#endif
162
+ break ;
163
+ case GIT_OPT_SET_USER_AGENT :
164
+ git__free (git__user_agent );
165
+ git__user_agent = git__strdup (va_arg (ap , const char * ));
166
+ if (!git__user_agent ) {
167
+ giterr_set_oom ();
168
+ error = -1 ;
169
+ }
170
+
155
171
break ;
156
172
}
157
173
Original file line number Diff line number Diff line change
1
+ #include "clar_libgit2.h"
2
+ #include "global.h"
3
+
4
+ void test_core_useragent__get (void )
5
+ {
6
+ const char * custom_name = "super duper git" ;
7
+
8
+ cl_assert_equal_p (NULL , git_libgit2__user_agent ());
9
+ cl_git_pass (git_libgit2_opts (GIT_OPT_SET_USER_AGENT , custom_name ));
10
+ cl_assert_equal_s (custom_name , git_libgit2__user_agent ());
11
+ }
You can’t perform that action at this time.
0 commit comments