@matheusbsbs / matheus-bagliano / commits / 457f06d68e
Fork 0

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>

Johannes Schindelin committed Dec 22, 2005 at 23:13 UTC 457f06d68e427bbf4f1a921877441a622a05e5c4
4 files changed +36 -1
cache.h
+2
@@ -159,6 +159,7 @@ extern void rollback_index_file(struct cache_file *);
159 extern int trust_executable_bit;
160 extern int only_use_symrefs;
161 extern int diff_rename_limit_default;
162 +extern int shared_repository;
163
164 #define GIT_REPO_VERSION 0
165 extern int repository_format_version;
@@ -183,6 +184,7 @@ extern const unsigned char null_sha1[20];
184
185 int git_mkstemp(char *path, size_t n, const char *template);
186
187 +int adjust_shared_perm(const char *path);
188 int safe_create_leading_directories(char *path);
189 char *safe_strncpy(char *, const char *, size_t);
190 char *enter_repo(char *path, int strict);
environment.c
+1
@@ -15,6 +15,7 @@ int trust_executable_bit = 1;
15 int only_use_symrefs = 0;
16 int repository_format_version = 0;
17 char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8";
18 +int shared_repository = 0;
19
20 static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
21 *git_graft_file;
setup.c
+2
@@ -180,6 +180,8 @@ int check_repository_format_version(const char *var, const char *value)
180 {
181 if (strcmp(var, "core.repositoryformatversion") == 0)
182 repository_format_version = git_config_int(var, value);
183 + else if (strcmp(var, "core.sharedrepository") == 0)
184 + shared_repository = git_config_bool(var, value);
185 return 0;
186 }
187
sha1_file.c
+31 -1
@@ -48,6 +48,29 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
48 return 0;
49 }
50
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 +
74 int safe_create_leading_directories(char *path)
75 {
76 char *pos = path;
@@ -59,11 +82,16 @@ int safe_create_leading_directories(char *path)
82 if (!pos)
83 break;
84 *pos = 0;
62 - if (mkdir(path, 0777) < 0)
85 + if (mkdir(path, 0777) < 0) {
86 if (errno != EEXIST) {
87 *pos = '/';
88 return -1;
89 }
90 + }
91 + else if (adjust_shared_perm(path)) {
92 + *pos = '/';
93 + return -2;
94 + }
95 *pos++ = '/';
96 }
97 return 0;
@@ -1255,6 +1283,8 @@ static int link_temp_to_file(const char *tmpfile, char *filename)
1283 if (dir) {
1284 *dir = 0;
1285 mkdir(filename, 0777);
1286 + if (adjust_shared_perm(filename))
1287 + return -2;
1288 *dir = '/';
1289 if (!link(tmpfile, filename))
1290 return 0;