aboutsummaryrefslogtreecommitdiffstats
path: root/path.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-02-07 12:03:41 +0100
committerJunio C Hamano <gitster@pobox.com>2025-02-28 13:54:11 -0800
commit028f618658e34230e1d65678f14b6876e0f9856d (patch)
tree696b719e0dc2e67551193239522fbfb7113d1516 /path.c
parentenvironment: move access to "core.sharedRepository" into repo settings (diff)
downloadgit-028f618658e34230e1d65678f14b6876e0f9856d.tar.gz
git-028f618658e34230e1d65678f14b6876e0f9856d.zip
path: adjust last remaining users of `the_repository`
With the preceding refactorings we now only have a couple of implicit users of `the_repository` left in the "path" subsystem, all of which depend on global state via `calc_shared_perm()`. Make the dependency on `the_repository` explicit by passing the repo as a parameter instead and adjust callers accordingly. Note that this change bubbles up into a couple of subsystems that were previously declared as free from `the_repository`. Instead of marking all of them as `the_repository`-dependent again, we instead use the repository that is available in the calling context. There are three exceptions though with "copy.c", "pack-write.c" and "tempfile.c". Adjusting these would require us to adapt callsites all over the place, so this is left for a future iteration. Mark "path.c" as free from `the_repository`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r--path.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/path.c b/path.c
index a2f402baec..910756c8b3 100644
--- a/path.c
+++ b/path.c
@@ -2,8 +2,6 @@
* Utilities for paths and pathnames
*/
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "abspath.h"
#include "environment.h"
@@ -840,21 +838,22 @@ const char *enter_repo(const char *path, unsigned flags)
return NULL;
}
-int calc_shared_perm(int mode)
+int calc_shared_perm(struct repository *repo,
+ int mode)
{
int tweak;
- if (repo_settings_get_shared_repository(the_repository) < 0)
- tweak = -repo_settings_get_shared_repository(the_repository);
+ if (repo_settings_get_shared_repository(repo) < 0)
+ tweak = -repo_settings_get_shared_repository(repo);
else
- tweak = repo_settings_get_shared_repository(the_repository);
+ tweak = repo_settings_get_shared_repository(repo);
if (!(mode & S_IWUSR))
tweak &= ~0222;
if (mode & S_IXUSR)
/* Copy read bits to execute bits */
tweak |= (tweak & 0444) >> 2;
- if (repo_settings_get_shared_repository(the_repository) < 0)
+ if (repo_settings_get_shared_repository(repo) < 0)
mode = (mode & ~0777) | tweak;
else
mode |= tweak;
@@ -862,17 +861,17 @@ int calc_shared_perm(int mode)
return mode;
}
-
-int adjust_shared_perm(const char *path)
+int adjust_shared_perm(struct repository *repo,
+ const char *path)
{
int old_mode, new_mode;
- if (!repo_settings_get_shared_repository(the_repository))
+ if (!repo_settings_get_shared_repository(repo))
return 0;
if (get_st_mode_bits(path, &old_mode) < 0)
return -1;
- new_mode = calc_shared_perm(old_mode);
+ new_mode = calc_shared_perm(repo, old_mode);
if (S_ISDIR(old_mode)) {
/* Copy read bits to execute bits */
new_mode |= (new_mode & 0444) >> 2;
@@ -891,7 +890,7 @@ int adjust_shared_perm(const char *path)
return 0;
}
-void safe_create_dir(const char *dir, int share)
+void safe_create_dir(struct repository *repo, const char *dir, int share)
{
if (mkdir(dir, 0777) < 0) {
if (errno != EEXIST) {
@@ -899,7 +898,7 @@ void safe_create_dir(const char *dir, int share)
exit(1);
}
}
- else if (share && adjust_shared_perm(dir))
+ else if (share && adjust_shared_perm(repo, dir))
die(_("Could not make %s writable by group"), dir);
}