@@ -1033,6 +1033,7 @@ LIB_OBJS += fsmonitor-ipc.o
LIB_OBJS += fsmonitor-settings.o
LIB_OBJS += gettext.o
LIB_OBJS += git-zlib.o
+LIB_OBJS += global-config.o
LIB_OBJS += gpg-interface.o
LIB_OBJS += graph.o
LIB_OBJS += grep.o
@@ -12,6 +12,7 @@
#include "shallow.h"
#include "trace.h"
#include "trace2.h"
+#include "global-config.h"
#define RUN_SETUP (1<<0)
#define RUN_SETUP_GENTLY (1<<1)
@@ -443,6 +444,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
if (!help && p->option & NEED_WORK_TREE)
setup_work_tree();
+ /* At this point, we can allow loading config. */
+ declare_config_available();
+
trace_argv_printf(argv, "trace: built-in: git");
trace2_cmd_name(p->cmd);
trace2_cmd_list_config();
new file mode 100644
@@ -0,0 +1,44 @@
+#include "git-compat-util.h"
+#include "global-config.h"
+#include "config.h"
+
+static int global_ints[] = {
+ [INT_CONFIG_NONE] = 0, /* unused*/
+};
+
+/* Bitmask for the enum. */
+static uint64_t global_ints_initialized;
+
+static const char *global_int_names[] = {
+ [INT_CONFIG_NONE] = NULL, /* unused*/
+};
+
+static int config_available;
+
+void declare_config_available(void)
+{
+ config_available = 1;
+}
+
+int get_int_config_global(enum int_config_key key)
+{
+ uint64_t key_index;
+
+ if (key < 0 || key >= sizeof(global_ints))
+ BUG("invalid int_config_key %d", key);
+
+ key_index = (uint64_t)1 << key;
+
+ /*
+ * Is it too early to load from config?
+ * Have we already loaded from config?
+ */
+ if (!config_available || (global_ints_initialized & key_index))
+ return global_ints[key];
+ global_ints_initialized |= key_index;
+
+ /* Try getting a boolean value before trying an int. */
+ if (git_config_get_maybe_bool(global_int_names[key], &global_ints[key]) < 0)
+ git_config_get_int(global_int_names[key], &global_ints[key]);
+ return global_ints[key];
+}
new file mode 100644
@@ -0,0 +1,25 @@
+#ifndef GLOBAL_CONFIG_H
+#define GLOBAL_CONFIG_H
+
+enum int_config_key {
+ INT_CONFIG_NONE = 0,
+};
+
+/**
+ * During initial process loading, the config system is not quite available.
+ * The config global system needs an indicator that the process is ready
+ * to read config. Before this method is called, it will return the
+ * default values.
+ */
+void declare_config_available(void);
+
+/**
+ * Given a config key (by enum), return its value.
+ *
+ * If declare_config_available() has not been called, then this returns
+ * the default value. Otherwise, it guarantees that the value has been
+ * filled from config before returning the value.
+ */
+int get_int_config_global(enum int_config_key key);
+
+#endif /* GLOBAL_CONFIG_H */
@@ -3,6 +3,7 @@
#include "test-tool-utils.h"
#include "trace2.h"
#include "parse-options.h"
+#include "global-config.h"
static const char * const test_tool_usage[] = {
"test-tool [-C <directory>] <command [<arguments>...]]",
@@ -127,6 +128,8 @@ int cmd_main(int argc, const char **argv)
if (working_directory && chdir(working_directory) < 0)
die("Could not cd to '%s'", working_directory);
+ declare_config_available();
+
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
if (!strcmp(cmds[i].name, argv[1])) {
argv++;