mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
f1ce861c34
commit
028f618658
25
path.c
25
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user