]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: guard state depending on a repository
authorPatrick Steinhardt <ps@pks.im>
Thu, 12 Sep 2024 11:30:01 +0000 (13:30 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Sep 2024 17:15:42 +0000 (10:15 -0700)
In "environment.h" we have quite a lot of functions and variables that
either explicitly or implicitly depend on `the_repository`.

The implicit set of stateful declarations includes for example variables
which get populated when parsing a repository's Git configuration. This
set of variables is broken by design, as their state often depends on
the last repository config that has been parsed. So they may or may not
represent the state of `the_repository`.

Fixing that is quite a big undertaking, and later patches in this series
will demonstrate a solution for a first small set of those variables. So
for now, let's guard these with `USE_THE_REPOSITORY_VARIABLE` so that
callers are aware of the implicit dependency.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 files changed:
compat/mingw.c
compat/win32/path-utils.c
config.c
environment.h
name-hash.c
path.c
preload-index.c
prompt.c
refs/files-backend.c
sparse-index.c
statinfo.c
t/helper/test-path-utils.c
tree-diff.c
userdiff.c

index 29d3f09768c29a4aab37da49761ec7f3d3813e96..5c2080c04c1dd69b3460ff16db6f9d13003f7439 100644 (file)
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "../git-compat-util.h"
 #include "win32.h"
 #include <aclapi.h>
index b658ca3f811717fcdf5910af02163a29103e2891..966ef779b9ca9b36d50ddc16122b7dc726315fb7 100644 (file)
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "../../git-compat-util.h"
 #include "../../environment.h"
 
index 043e1c8a078c1e78affc721b1227dc56cb85d3f7..f3066c3747705821acf6b3a76291246ef9395a31 100644 (file)
--- a/config.c
+++ b/config.c
@@ -6,6 +6,8 @@
  *
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "advice.h"
index f1a7c645db5280a00df9921ce0444a5e993b77fb..934859e1c59a80af4e3db481e56fe7e2aa354029 100644 (file)
@@ -102,6 +102,28 @@ int use_optional_locks(void);
 const char *get_git_namespace(void);
 const char *strip_namespace(const char *namespaced_ref);
 
+/*
+ * TODO: All the below state either explicitly or implicitly relies on
+ * `the_repository`. We should eventually get rid of these and make the
+ * dependency on a repository explicit:
+ *
+ *   - `setup_git_env()` ideally shouldn't exist as it modifies global state,
+ *     namely the environment. The current process shouldn't ever access that
+ *     state via envvars though, but should instead consult a `struct
+ *     repository`. When spawning new processes, we would ideally also pass a
+ *     `struct repository` and then set up the environment variables for the
+ *     child process, only.
+ *
+ *   - `have_git_dir()` should not have to exist at all. Instead, we should
+ *     decide on whether or not we have a `struct repository`.
+ *
+ *   - All the global config variables should become tied to a repository. Like
+ *     this, we'd correctly honor repository-local configuration and be able to
+ *     distinguish configuration values from different repositories.
+ *
+ * Please do not add new global config variables here.
+ */
+# ifdef USE_THE_REPOSITORY_VARIABLE
 void setup_git_env(const char *git_dir);
 
 /*
@@ -213,4 +235,5 @@ extern const char *comment_line_str;
 extern char *comment_line_str_to_free;
 extern int auto_comment_line_char;
 
-#endif
+# endif /* USE_THE_REPOSITORY_VARIABLE */
+#endif /* ENVIRONMENT_H */
index 3a58ce03d9c4a6721941f0ff8b262b6ddb73acd2..95528e3bcd2a3e36cf72faa7ed629c3175492bbb 100644 (file)
@@ -5,6 +5,9 @@
  *
  * Copyright (C) 2008 Linus Torvalds
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
diff --git a/path.c b/path.c
index a3bf25b7defef28889c796314297a98653858503..93491bab141c5633691f5172e450052800da63ed 100644 (file)
--- a/path.c
+++ b/path.c
@@ -2,6 +2,8 @@
  * Utilities for paths and pathnames
  */
 
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "environment.h"
index 63fd35d64b141f6f1488c40c4fb34b1fe1e53ae0..7926eb09a695f7c5ea0e0de1e48690caf6c6fa6f 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * Copyright (C) 2008 Linus Torvalds
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "pathspec.h"
 #include "dir.h"
index 8935fe4dfb9414f101bf603aaf866ac6a1f6e027..f21c5bf1c7e42fd953650b6ef90a1fe0d00b588c 100644 (file)
--- a/prompt.c
+++ b/prompt.c
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "parse.h"
 #include "environment.h"
index 1cff65f6ae548b4f6a78b984a7ecc50c8e29969f..1bbb550f3af8e63f40048dec06a268d906ec82be 100644 (file)
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "../git-compat-util.h"
 #include "../copy.h"
 #include "../environment.h"
index 9958656ded1931fc6c293f02a7be255f6ecc855e..542ca5f411ca52f60f854246603a2cbdba910a02 100644 (file)
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "gettext.h"
index 3c6bc049c15d44c33c064fecbbd2236571b2dadb..30a164b0e68cf82b1b18bd944ff347ab5dc3b7b9 100644 (file)
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "environment.h"
 #include "statinfo.h"
index bf0e23ed50507b81eac512d8202bec582b5c3b4c..f57c8d706aa8c8bd80e5f551754d9f72efa92f00 100644 (file)
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "abspath.h"
 #include "environment.h"
index 9252481df3677c59c05c1896e960438dc0281baf..5eab8af631b78955589d1bb73031ecc854303c51 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * Helper functions for tree diff generation
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "diff.h"
 #include "diffcore.h"
index 989629149f668e68f116a109b5fd449de5d4b003..d43d8360d17227852f33e41fa41efdc1cfc4c74a 100644 (file)
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "git-compat-util.h"
 #include "config.h"
 #include "userdiff.h"