diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-13 10:39:33 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-11 14:43:35 +0100 |
commit | 6554b40e42df831d7fc9c623d34b2738227dd8a2 (patch) | |
tree | 52b0fdeedbdd39ae8b45d833fdd41a5d6bc32716 | |
parent | 521aa8c1c04c25a57b82e1279a4e91d8a07436aa (diff) | |
download | libgit2-6554b40e42df831d7fc9c623d34b2738227dd8a2.tar.gz |
settings: localize global data
Move the settings global data teardown into its own separate function,
instead of intermingled with the global state.
-rw-r--r-- | src/global.c | 9 | ||||
-rw-r--r-- | src/global.h | 3 | ||||
-rw-r--r-- | src/settings.c | 32 | ||||
-rw-r--r-- | src/settings.h | 11 | ||||
-rw-r--r-- | src/streams/openssl.c | 1 | ||||
-rw-r--r-- | src/transports/http.h | 1 | ||||
-rw-r--r-- | tests/core/useragent.c | 2 |
7 files changed, 39 insertions, 20 deletions
diff --git a/src/global.c b/src/global.c index d2a25a504..06429776c 100644 --- a/src/global.c +++ b/src/global.c @@ -11,6 +11,7 @@ #include "hash.h" #include "sysdir.h" #include "filter.h" +#include "settings.h" #include "merge_driver.h" #include "pool.h" #include "streams/registry.h" @@ -37,15 +38,14 @@ static git_global_init_fn git__init_callbacks[] = { git_openssl_stream_global_init, git_mbedtls_stream_global_init, git_mwindow_global_init, - git_pool_global_init + git_pool_global_init, + git_settings_global_init }; static git_global_shutdown_fn git__shutdown_callbacks[ARRAY_SIZE(git__init_callbacks)]; static git_atomic git__n_shutdown_callbacks; static git_atomic git__n_inits; -char *git__user_agent; -char *git__ssl_ciphers; void git__on_shutdown(git_global_shutdown_fn callback) { @@ -93,9 +93,6 @@ static void shutdown_common(void) if (cb != NULL) cb(); } - - git__free(git__user_agent); - git__free(git__ssl_ciphers); } /** diff --git a/src/global.h b/src/global.h index db41dad1f..2a7c7274c 100644 --- a/src/global.h +++ b/src/global.h @@ -35,7 +35,4 @@ typedef void (*git_global_shutdown_fn)(void); extern void git__on_shutdown(git_global_shutdown_fn callback); -extern const char *git_libgit2__user_agent(void); -extern const char *git_libgit2__ssl_ciphers(void); - #endif diff --git a/src/settings.c b/src/settings.c index 69ebcb7ab..0426093ea 100644 --- a/src/settings.c +++ b/src/settings.c @@ -29,6 +29,28 @@ #include "streams/openssl.h" #include "streams/mbedtls.h" +/* Declarations for tuneable settings */ +extern size_t git_mwindow__window_size; +extern size_t git_mwindow__mapped_limit; +extern size_t git_mwindow__file_limit; +extern size_t git_indexer__max_objects; +extern bool git_disable_pack_keep_file_checks; + +char *git__user_agent; +char *git__ssl_ciphers; + +static void git_settings_global_shutdown(void) +{ + git__free(git__user_agent); + git__free(git__ssl_ciphers); +} + +int git_settings_global_init(void) +{ + git__on_shutdown(git_settings_global_shutdown); + return 0; +} + int git_libgit2_version(int *major, int *minor, int *rev) { *major = LIBGIT2_VER_MAJOR; @@ -56,13 +78,6 @@ int git_libgit2_features(void) ; } -/* Declarations for tuneable settings */ -extern size_t git_mwindow__window_size; -extern size_t git_mwindow__mapped_limit; -extern size_t git_mwindow__file_limit; -extern size_t git_indexer__max_objects; -extern bool git_disable_pack_keep_file_checks; - static int config_level_to_sysdir(int config_level) { int val = -1; @@ -88,9 +103,6 @@ static int config_level_to_sysdir(int config_level) return val; } -extern char *git__user_agent; -extern char *git__ssl_ciphers; - const char *git_libgit2__user_agent(void) { return git__user_agent; diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 000000000..dc42ce939 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,11 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ + +extern int git_settings_global_init(void); + +extern const char *git_libgit2__user_agent(void); +extern const char *git_libgit2__ssl_ciphers(void); diff --git a/src/streams/openssl.c b/src/streams/openssl.c index 6a490d17d..58265c1ec 100644 --- a/src/streams/openssl.c +++ b/src/streams/openssl.c @@ -12,6 +12,7 @@ #include <ctype.h> #include "global.h" +#include "settings.h" #include "posix.h" #include "stream.h" #include "streams/socket.h" diff --git a/src/transports/http.h b/src/transports/http.h index c02109cec..5c360b883 100644 --- a/src/transports/http.h +++ b/src/transports/http.h @@ -9,6 +9,7 @@ #define INCLUDE_transports_http_h__ #include "buffer.h" +#include "settings.h" #include "httpclient.h" #define GIT_HTTP_REPLAY_MAX 15 diff --git a/tests/core/useragent.c b/tests/core/useragent.c index c6c5220b2..2ce935bf5 100644 --- a/tests/core/useragent.c +++ b/tests/core/useragent.c @@ -1,5 +1,5 @@ #include "clar_libgit2.h" -#include "global.h" +#include "settings.h" void test_core_useragent__get(void) { |