Skip to content

Commit 6554b40

Browse files
committed
settings: localize global data
Move the settings global data teardown into its own separate function, instead of intermingled with the global state.
1 parent 521aa8c commit 6554b40

File tree

7 files changed

+39
-20
lines changed

7 files changed

+39
-20
lines changed

src/global.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "hash.h"
1212
#include "sysdir.h"
1313
#include "filter.h"
14+
#include "settings.h"
1415
#include "merge_driver.h"
1516
#include "pool.h"
1617
#include "streams/registry.h"
@@ -37,15 +38,14 @@ static git_global_init_fn git__init_callbacks[] = {
3738
git_openssl_stream_global_init,
3839
git_mbedtls_stream_global_init,
3940
git_mwindow_global_init,
40-
git_pool_global_init
41+
git_pool_global_init,
42+
git_settings_global_init
4143
};
4244

4345
static git_global_shutdown_fn git__shutdown_callbacks[ARRAY_SIZE(git__init_callbacks)];
4446

4547
static git_atomic git__n_shutdown_callbacks;
4648
static git_atomic git__n_inits;
47-
char *git__user_agent;
48-
char *git__ssl_ciphers;
4949

5050
void git__on_shutdown(git_global_shutdown_fn callback)
5151
{
@@ -93,9 +93,6 @@ static void shutdown_common(void)
9393
if (cb != NULL)
9494
cb();
9595
}
96-
97-
git__free(git__user_agent);
98-
git__free(git__ssl_ciphers);
9996
}
10097

10198
/**

src/global.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,4 @@ typedef void (*git_global_shutdown_fn)(void);
3535

3636
extern void git__on_shutdown(git_global_shutdown_fn callback);
3737

38-
extern const char *git_libgit2__user_agent(void);
39-
extern const char *git_libgit2__ssl_ciphers(void);
40-
4138
#endif

src/settings.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@
2929
#include "streams/openssl.h"
3030
#include "streams/mbedtls.h"
3131

32+
/* Declarations for tuneable settings */
33+
extern size_t git_mwindow__window_size;
34+
extern size_t git_mwindow__mapped_limit;
35+
extern size_t git_mwindow__file_limit;
36+
extern size_t git_indexer__max_objects;
37+
extern bool git_disable_pack_keep_file_checks;
38+
39+
char *git__user_agent;
40+
char *git__ssl_ciphers;
41+
42+
static void git_settings_global_shutdown(void)
43+
{
44+
git__free(git__user_agent);
45+
git__free(git__ssl_ciphers);
46+
}
47+
48+
int git_settings_global_init(void)
49+
{
50+
git__on_shutdown(git_settings_global_shutdown);
51+
return 0;
52+
}
53+
3254
int git_libgit2_version(int *major, int *minor, int *rev)
3355
{
3456
*major = LIBGIT2_VER_MAJOR;
@@ -56,13 +78,6 @@ int git_libgit2_features(void)
5678
;
5779
}
5880

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-
6681
static int config_level_to_sysdir(int config_level)
6782
{
6883
int val = -1;
@@ -88,9 +103,6 @@ static int config_level_to_sysdir(int config_level)
88103
return val;
89104
}
90105

91-
extern char *git__user_agent;
92-
extern char *git__ssl_ciphers;
93-
94106
const char *git_libgit2__user_agent(void)
95107
{
96108
return git__user_agent;

src/settings.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
extern int git_settings_global_init(void);
9+
10+
extern const char *git_libgit2__user_agent(void);
11+
extern const char *git_libgit2__ssl_ciphers(void);

src/streams/openssl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <ctype.h>
1313

1414
#include "global.h"
15+
#include "settings.h"
1516
#include "posix.h"
1617
#include "stream.h"
1718
#include "streams/socket.h"

src/transports/http.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define INCLUDE_transports_http_h__
1010

1111
#include "buffer.h"
12+
#include "settings.h"
1213
#include "httpclient.h"
1314

1415
#define GIT_HTTP_REPLAY_MAX 15

tests/core/useragent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "clar_libgit2.h"
2-
#include "global.h"
2+
#include "settings.h"
33

44
void test_core_useragent__get(void)
55
{

0 commit comments

Comments
 (0)