diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Isolate the git environment without a constructor
Diffstat (limited to 'source/cgit.c')
-rw-r--r--source/cgit.c21
1 file changed, 13 insertions, 8 deletions
diff --git a/source/cgit.c b/source/cgit.c
index f58aab3..c2c488d 100644
--- a/source/cgit.c
+++ b/source/cgit.c
@@ -22,15 +22,19 @@
const char *cgit_version = CGIT_VERSION;
-__attribute__((constructor))
-static void constructor_environment()
+/*
+ * Isolate git from the calling user's configuration. Ignore the system and
+ * global config and attributes, so a snapshot cannot be broken by something
+ * like a core.excludesfile pointing at a "~" path that git can no longer
+ * expand once HOME is unset below.
+ *
+ * Called at the top of cmd_main rather than from a constructor attribute.
+ * git-compat-util.h defines __attribute__ away on a compiler that does not
+ * support it, which would leave this silently never running. Nothing git does
+ * before cmd_main reads configuration, so an ordinary call is equivalent.
+ */
+static void isolate_git_environment(void)
{
- /*
- * Isolate git from the calling user's configuration. Ignore the
- * system and global config and attributes, so a snapshot cannot be
- * broken by something like a core.excludesfile pointing at a "~" path
- * that git can no longer expand once HOME is unset below.
- */
setenv("GIT_CONFIG_NOSYSTEM", "1", 1);
setenv("GIT_CONFIG_GLOBAL", "/dev/null", 1);
setenv("GIT_ATTR_NOSYSTEM", "1", 1);
@@ -1080,6 +1084,7 @@ int cmd_main(int argc, const char **argv)
const char *path;
int err, ttl;
+ isolate_git_environment();
cgit_init_filters();
atexit(cgit_cleanup_filters);
set_die_routine(cgit_die_routine);