1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-28 04:49:43 +01:00

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>
This commit is contained in:
Patrick Steinhardt 2024-09-12 13:30:01 +02:00 committed by Junio C Hamano
parent f2d70847bd
commit 673af418d0
14 changed files with 53 additions and 1 deletions

View file

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "../git-compat-util.h"
#include "win32.h"
#include <aclapi.h>

View file

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "../../git-compat-util.h"
#include "../../environment.h"

View file

@ -6,6 +6,8 @@
*
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"

View 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 */

View 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"

2
path.c
View file

@ -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"

View 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"

View file

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "parse.h"
#include "environment.h"

View file

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "../git-compat-util.h"
#include "../copy.h"
#include "../environment.h"

View file

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"

View file

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "environment.h"
#include "statinfo.h"

View file

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "test-tool.h"
#include "abspath.h"
#include "environment.h"

View 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"

View file

@ -1,3 +1,5 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "config.h"
#include "userdiff.h"