Skip to content

Commit 673af41

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2d7084 commit 673af41

File tree

14 files changed

+53
-1
lines changed

14 files changed

+53
-1
lines changed

compat/mingw.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "../git-compat-util.h"
24
#include "win32.h"
35
#include <aclapi.h>

compat/win32/path-utils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "../../git-compat-util.h"
24
#include "../../environment.h"
35

config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*
77
*/
88

9+
#define USE_THE_REPOSITORY_VARIABLE
10+
911
#include "git-compat-util.h"
1012
#include "abspath.h"
1113
#include "advice.h"

environment.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ int use_optional_locks(void);
102102
const char *get_git_namespace(void);
103103
const char *strip_namespace(const char *namespaced_ref);
104104

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
105127
void setup_git_env(const char *git_dir);
106128

107129
/*
@@ -213,4 +235,5 @@ extern const char *comment_line_str;
213235
extern char *comment_line_str_to_free;
214236
extern int auto_comment_line_char;
215237

216-
#endif
238+
# endif /* USE_THE_REPOSITORY_VARIABLE */
239+
#endif /* ENVIRONMENT_H */

name-hash.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*
66
* Copyright (C) 2008 Linus Torvalds
77
*/
8+
9+
#define USE_THE_REPOSITORY_VARIABLE
10+
811
#include "git-compat-util.h"
912
#include "environment.h"
1013
#include "gettext.h"

path.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Utilities for paths and pathnames
33
*/
44

5+
#define USE_THE_REPOSITORY_VARIABLE
6+
57
#include "git-compat-util.h"
68
#include "abspath.h"
79
#include "environment.h"

preload-index.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (C) 2008 Linus Torvalds
33
*/
4+
5+
#define USE_THE_REPOSITORY_VARIABLE
6+
47
#include "git-compat-util.h"
58
#include "pathspec.h"
69
#include "dir.h"

prompt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "parse.h"
35
#include "environment.h"

refs/files-backend.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "../git-compat-util.h"
24
#include "../copy.h"
35
#include "../environment.h"

sparse-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
#include "git-compat-util.h"
24
#include "environment.h"
35
#include "gettext.h"

0 commit comments

Comments
 (0)