Git fork

environment: guard state depending on a repository

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>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
673af418 f2d70847

+53 -1
+2
compat/mingw.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "../git-compat-util.h" 2 4 #include "win32.h" 3 5 #include <aclapi.h>
+2
compat/win32/path-utils.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "../../git-compat-util.h" 2 4 #include "../../environment.h" 3 5
+2
config.c
··· 6 6 * 7 7 */ 8 8 9 + #define USE_THE_REPOSITORY_VARIABLE 10 + 9 11 #include "git-compat-util.h" 10 12 #include "abspath.h" 11 13 #include "advice.h"
+24 -1
environment.h
··· 102 102 const char *get_git_namespace(void); 103 103 const char *strip_namespace(const char *namespaced_ref); 104 104 105 + /* 106 + * TODO: All the below state either explicitly or implicitly relies on 107 + * `the_repository`. We should eventually get rid of these and make the 108 + * dependency on a repository explicit: 109 + * 110 + * - `setup_git_env()` ideally shouldn't exist as it modifies global state, 111 + * namely the environment. The current process shouldn't ever access that 112 + * state via envvars though, but should instead consult a `struct 113 + * repository`. When spawning new processes, we would ideally also pass a 114 + * `struct repository` and then set up the environment variables for the 115 + * child process, only. 116 + * 117 + * - `have_git_dir()` should not have to exist at all. Instead, we should 118 + * decide on whether or not we have a `struct repository`. 119 + * 120 + * - All the global config variables should become tied to a repository. Like 121 + * this, we'd correctly honor repository-local configuration and be able to 122 + * distinguish configuration values from different repositories. 123 + * 124 + * Please do not add new global config variables here. 125 + */ 126 + # ifdef USE_THE_REPOSITORY_VARIABLE 105 127 void setup_git_env(const char *git_dir); 106 128 107 129 /* ··· 213 235 extern char *comment_line_str_to_free; 214 236 extern int auto_comment_line_char; 215 237 216 - #endif 238 + # endif /* USE_THE_REPOSITORY_VARIABLE */ 239 + #endif /* ENVIRONMENT_H */
+3
name-hash.c
··· 5 5 * 6 6 * Copyright (C) 2008 Linus Torvalds 7 7 */ 8 + 9 + #define USE_THE_REPOSITORY_VARIABLE 10 + 8 11 #include "git-compat-util.h" 9 12 #include "environment.h" 10 13 #include "gettext.h"
+2
path.c
··· 2 2 * Utilities for paths and pathnames 3 3 */ 4 4 5 + #define USE_THE_REPOSITORY_VARIABLE 6 + 5 7 #include "git-compat-util.h" 6 8 #include "abspath.h" 7 9 #include "environment.h"
+3
preload-index.c
··· 1 1 /* 2 2 * Copyright (C) 2008 Linus Torvalds 3 3 */ 4 + 5 + #define USE_THE_REPOSITORY_VARIABLE 6 + 4 7 #include "git-compat-util.h" 5 8 #include "pathspec.h" 6 9 #include "dir.h"
+2
prompt.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "parse.h" 3 5 #include "environment.h"
+2
refs/files-backend.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "../git-compat-util.h" 2 4 #include "../copy.h" 3 5 #include "../environment.h"
+2
sparse-index.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "environment.h" 3 5 #include "gettext.h"
+2
statinfo.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "environment.h" 3 5 #include "statinfo.h"
+2
t/helper/test-path-utils.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "test-tool.h" 2 4 #include "abspath.h" 3 5 #include "environment.h"
+3
tree-diff.c
··· 1 1 /* 2 2 * Helper functions for tree diff generation 3 3 */ 4 + 5 + #define USE_THE_REPOSITORY_VARIABLE 6 + 4 7 #include "git-compat-util.h" 5 8 #include "diff.h" 6 9 #include "diffcore.h"
+2
userdiff.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "git-compat-util.h" 2 4 #include "config.h" 3 5 #include "userdiff.h"