Skip to content

Commit 457f06d

Browse files
dschoJunio C Hamano
authored andcommitted
Introduce core.sharedrepository
If the config variable 'core.sharedrepository' is set, the directories $GIT_DIR/objects/ $GIT_DIR/objects/?? $GIT_DIR/objects/pack $GIT_DIR/refs $GIT_DIR/refs/heads $GIT_DIR/refs/heads/tags are set group writable (and g+s, since the git group may be not the primary group of all users). Since all files are written as lock files first, and then moved to their destination, they do not have to be group writable. Indeed, if this leads to problems you found a bug. Note that -- as in my first attempt -- the config variable is set in the function which checks the repository format. If this were done in git_default_config instead, a lot of programs would need to be modified to call git_config(git_default_config) first. [jc: git variables should be in environment.c unless there is a compelling reason to do otherwise.] Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 2414721 commit 457f06d

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ extern void rollback_index_file(struct cache_file *);
159159
extern int trust_executable_bit;
160160
extern int only_use_symrefs;
161161
extern int diff_rename_limit_default;
162+
extern int shared_repository;
162163

163164
#define GIT_REPO_VERSION 0
164165
extern int repository_format_version;
@@ -183,6 +184,7 @@ extern const unsigned char null_sha1[20];
183184

184185
int git_mkstemp(char *path, size_t n, const char *template);
185186

187+
int adjust_shared_perm(const char *path);
186188
int safe_create_leading_directories(char *path);
187189
char *safe_strncpy(char *, const char *, size_t);
188190
char *enter_repo(char *path, int strict);

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ int trust_executable_bit = 1;
1515
int only_use_symrefs = 0;
1616
int repository_format_version = 0;
1717
char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8";
18+
int shared_repository = 0;
1819

1920
static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
2021
*git_graft_file;

setup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ int check_repository_format_version(const char *var, const char *value)
180180
{
181181
if (strcmp(var, "core.repositoryformatversion") == 0)
182182
repository_format_version = git_config_int(var, value);
183+
else if (strcmp(var, "core.sharedrepository") == 0)
184+
shared_repository = git_config_bool(var, value);
183185
return 0;
184186
}
185187

sha1_file.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
4848
return 0;
4949
}
5050

51+
int adjust_shared_perm(const char *path)
52+
{
53+
struct stat st;
54+
int mode;
55+
56+
if (!shared_repository)
57+
return 0;
58+
if (lstat(path, &st) < 0)
59+
return -1;
60+
mode = st.st_mode;
61+
if (mode & S_IRUSR)
62+
mode |= S_IRGRP;
63+
if (mode & S_IWUSR)
64+
mode |= S_IWGRP;
65+
if (mode & S_IXUSR)
66+
mode |= S_IXGRP;
67+
if (S_ISDIR(mode))
68+
mode |= S_ISGID;
69+
if (chmod(path, mode) < 0)
70+
return -2;
71+
return 0;
72+
}
73+
5174
int safe_create_leading_directories(char *path)
5275
{
5376
char *pos = path;
@@ -59,11 +82,16 @@ int safe_create_leading_directories(char *path)
5982
if (!pos)
6083
break;
6184
*pos = 0;
62-
if (mkdir(path, 0777) < 0)
85+
if (mkdir(path, 0777) < 0) {
6386
if (errno != EEXIST) {
6487
*pos = '/';
6588
return -1;
6689
}
90+
}
91+
else if (adjust_shared_perm(path)) {
92+
*pos = '/';
93+
return -2;
94+
}
6795
*pos++ = '/';
6896
}
6997
return 0;
@@ -1255,6 +1283,8 @@ static int link_temp_to_file(const char *tmpfile, char *filename)
12551283
if (dir) {
12561284
*dir = 0;
12571285
mkdir(filename, 0777);
1286+
if (adjust_shared_perm(filename))
1287+
return -2;
12581288
*dir = '/';
12591289
if (!link(tmpfile, filename))
12601290
return 0;

0 commit comments

Comments
 (0)