Skip to content

Commit 3b059de

Browse files
kevin-wormdscho
authored andcommitted
Refactor early config parsing
The Trace2 machinery wishes to parse the system and the global config early. To this end, it taps into the `common-main` framework to run first thing. There are more Git features that could benefit from such a handling, most notably the Windows-specific `core.longPaths` setting: If a user has worktrees whose path already requires long paths support, we cannot wait until we parse the the config settings in the usual way because the gitdir discovery needs to happen first and would fail because any `core.longPaths` setting in, say, `~/.gitconfig` would not have been parsed yet. To that end, let's refactor Trace2's early config parsing so that other users can tap into it, too. Signed-off-by: Kevin Worm <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 590ade5 commit 3b059de

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

common-main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "cache.h"
2+
#include "config.h"
23
#include "exec-cmd.h"
34
#include "attr.h"
5+
#include "trace2/tr2_sysenv.h"
46

57
/*
68
* Many parts of Git have subprograms communicate via pipe, expect the
@@ -23,6 +25,11 @@ static void restore_sigpipe_to_default(void)
2325
signal(SIGPIPE, SIG_DFL);
2426
}
2527

28+
static int read_very_early_config_cb(const char *key, const char *value, void *d)
29+
{
30+
return tr2_sysenv_cb(key, value, d);
31+
}
32+
2633
int main(int argc, const char **argv)
2734
{
2835
int result;
@@ -46,7 +53,10 @@ int main(int argc, const char **argv)
4653

4754
attr_start();
4855

56+
read_very_early_config(read_very_early_config_cb, NULL);
57+
4958
trace2_initialize();
59+
5060
trace2_cmd_start(argv);
5161
trace2_collect_process_info(TRACE2_PROCESS_INFO_STARTUP);
5262

trace2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void trace2_initialize_fl(const char *file, int line)
158158
if (trace2_enabled)
159159
return;
160160

161-
tr2_sysenv_load();
161+
tr2_sysenv_check_size();
162162

163163
if (!tr2_tgt_want_builtins())
164164
return;

trace2/tr2_sysenv.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ static struct tr2_sysenv_entry tr2_sysenv_settings[] = {
5757
};
5858
/* clang-format on */
5959

60-
static int tr2_sysenv_cb(const char *key, const char *value, void *d)
60+
/*
61+
* Load Trace2 settings from the system config (usually "/etc/gitconfig"
62+
* unless we were built with a runtime-prefix). These are intended to
63+
* define the default values for Trace2 as requested by the administrator.
64+
*
65+
* Then override with the Trace2 settings from the global config.
66+
*/
67+
int tr2_sysenv_cb(const char *key, const char *value, void *d)
6168
{
6269
int k;
6370

@@ -75,19 +82,10 @@ static int tr2_sysenv_cb(const char *key, const char *value, void *d)
7582
return 0;
7683
}
7784

78-
/*
79-
* Load Trace2 settings from the system config (usually "/etc/gitconfig"
80-
* unless we were built with a runtime-prefix). These are intended to
81-
* define the default values for Trace2 as requested by the administrator.
82-
*
83-
* Then override with the Trace2 settings from the global config.
84-
*/
85-
void tr2_sysenv_load(void)
85+
void tr2_sysenv_check_size(void)
8686
{
8787
if (ARRAY_SIZE(tr2_sysenv_settings) != TR2_SYSENV_MUST_BE_LAST)
8888
BUG("tr2_sysenv_settings size is wrong");
89-
90-
read_very_early_config(tr2_sysenv_cb, NULL);
9189
}
9290

9391
/*

trace2/tr2_sysenv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ enum tr2_sysenv_variable {
3030
TR2_SYSENV_MUST_BE_LAST
3131
};
3232

33-
void tr2_sysenv_load(void);
33+
int tr2_sysenv_cb(const char *key, const char *value, void *d);
34+
void tr2_sysenv_check_size(void);
3435

3536
const char *tr2_sysenv_get(enum tr2_sysenv_variable);
3637
const char *tr2_sysenv_display_name(enum tr2_sysenv_variable var);

0 commit comments

Comments
 (0)