git-init-db: initialize shared repositories with --shared
Now you can say git-init-db --shared if you want other users to be able to push into that repository. [jc: info/ and objects/info/ need to be group writable if the repository is shared --- otherwise packs and refs files cannot be updated.] 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:19 UTC
af6e277c5eddbcf82582b4bbd3e50b36aa61a20a
1 file changed
+22
-10
init-db.c
+22
-10
@@ -9,7 +9,7 @@
9
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates/"
10
#endif
11
12
-static void safe_create_dir(const char *dir)
12
+static void safe_create_dir(const char *dir, int share)
13
{
14
if (mkdir(dir, 0777) < 0) {
15
if (errno != EEXIST) {
@@ -17,6 +17,8 @@ static void safe_create_dir(const char *dir)
17
exit(1);
18
}
19
}
20
+ else if (share && adjust_shared_perm(dir))
21
+ die("Could not make %s writable by group\n", dir);
22
}
23
24
static int copy_file(const char *dst, const char *src, int mode)
@@ -32,6 +34,10 @@ static int copy_file(const char *dst, const char *src, int mode)
34
}
35
status = copy_fd(fdi, fdo);
36
close(fdo);
37
+
38
+ if (!status && adjust_shared_perm(dst))
39
+ return -1;
40
+
41
return status;
42
}
43
@@ -48,7 +54,7 @@ static void copy_templates_1(char *path, int baselen,
54
* with the way the namespace under .git/ is organized, should
55
* be really carefully chosen.
56
*/
51
- safe_create_dir(path);
57
+ safe_create_dir(path, 1);
58
while ((de = readdir(dir)) != NULL) {
59
struct stat st_git, st_template;
60
int namelen;
@@ -176,11 +182,11 @@ static void create_default_files(const char *git_dir, char *template_path)
182
* Create .git/refs/{heads,tags}
183
*/
184
strcpy(path + len, "refs");
179
- safe_create_dir(path);
185
+ safe_create_dir(path, 1);
186
strcpy(path + len, "refs/heads");
181
- safe_create_dir(path);
187
+ safe_create_dir(path, 1);
188
strcpy(path + len, "refs/tags");
183
- safe_create_dir(path);
189
+ safe_create_dir(path, 1);
190
191
/* First copy the templates -- we might have the default
192
* config file there, in which case we would want to read
@@ -220,7 +226,7 @@ static void create_default_files(const char *git_dir, char *template_path)
226
}
227
228
static const char init_db_usage[] =
223
-"git-init-db [--template=<template-directory>]";
229
+"git-init-db [--template=<template-directory>] [--shared]";
230
231
/*
232
* If you want to, you can share the DB area with any number of branches.
@@ -239,6 +245,8 @@ int main(int argc, char **argv)
245
char *arg = argv[1];
246
if (!strncmp(arg, "--template=", 11))
247
template_dir = arg+11;
248
+ else if (!strcmp(arg, "--shared"))
249
+ shared_repository = 1;
250
else
251
die(init_db_usage);
252
}
@@ -251,7 +259,7 @@ int main(int argc, char **argv)
259
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
260
fprintf(stderr, "defaulting to local storage area\n");
261
}
254
- safe_create_dir(git_dir);
262
+ safe_create_dir(git_dir, 0);
263
264
/* Check to see if the repository version is right.
265
* Note that a newly created repository does not have
@@ -270,10 +278,14 @@ int main(int argc, char **argv)
278
path = xmalloc(len + 40);
279
memcpy(path, sha1_dir, len);
280
273
- safe_create_dir(sha1_dir);
281
+ safe_create_dir(sha1_dir, 1);
282
strcpy(path+len, "/pack");
275
- safe_create_dir(path);
283
+ safe_create_dir(path, 1);
284
strcpy(path+len, "/info");
277
- safe_create_dir(path);
285
+ safe_create_dir(path, 1);
286
+
287
+ if (shared_repository)
288
+ git_config_set("core.sharedRepository", "true");
289
+
290
return 0;
291
}