summaryrefslogtreecommitdiff
path: root/init-db.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2005-12-22 23:19:37 +0100
committerJunio C Hamano <junkio@cox.net>2005-12-24 00:21:10 -0800
commitaf6e277c5eddbcf82582b4bbd3e50b36aa61a20a (patch)
treec4229cadf91082470d3ec9d6532ec94b940ddb1a /init-db.c
parent457f06d68e427bbf4f1a921877441a622a05e5c4 (diff)
downloadgit-af6e277c5eddbcf82582b4bbd3e50b36aa61a20a.tar.gz
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>
Diffstat (limited to 'init-db.c')
-rw-r--r--init-db.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/init-db.c b/init-db.c
index ead37b5ed8..ff294960f2 100644
--- a/init-db.c
+++ b/init-db.c
@@ -9,7 +9,7 @@
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates/"
#endif
-static void safe_create_dir(const char *dir)
+static void safe_create_dir(const char *dir, int share)
{
if (mkdir(dir, 0777) < 0) {
if (errno != EEXIST) {
@@ -17,6 +17,8 @@ static void safe_create_dir(const char *dir)
exit(1);
}
}
+ else if (share && adjust_shared_perm(dir))
+ die("Could not make %s writable by group\n", dir);
}
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)
}
status = copy_fd(fdi, fdo);
close(fdo);
+
+ if (!status && adjust_shared_perm(dst))
+ return -1;
+
return status;
}
@@ -48,7 +54,7 @@ static void copy_templates_1(char *path, int baselen,
* with the way the namespace under .git/ is organized, should
* be really carefully chosen.
*/
- safe_create_dir(path);
+ safe_create_dir(path, 1);
while ((de = readdir(dir)) != NULL) {
struct stat st_git, st_template;
int namelen;
@@ -176,11 +182,11 @@ static void create_default_files(const char *git_dir, char *template_path)
* Create .git/refs/{heads,tags}
*/
strcpy(path + len, "refs");
- safe_create_dir(path);
+ safe_create_dir(path, 1);
strcpy(path + len, "refs/heads");
- safe_create_dir(path);
+ safe_create_dir(path, 1);
strcpy(path + len, "refs/tags");
- safe_create_dir(path);
+ safe_create_dir(path, 1);
/* First copy the templates -- we might have the default
* 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)
}
static const char init_db_usage[] =
-"git-init-db [--template=<template-directory>]";
+"git-init-db [--template=<template-directory>] [--shared]";
/*
* 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)
char *arg = argv[1];
if (!strncmp(arg, "--template=", 11))
template_dir = arg+11;
+ else if (!strcmp(arg, "--shared"))
+ shared_repository = 1;
else
die(init_db_usage);
}
@@ -251,7 +259,7 @@ int main(int argc, char **argv)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
fprintf(stderr, "defaulting to local storage area\n");
}
- safe_create_dir(git_dir);
+ safe_create_dir(git_dir, 0);
/* Check to see if the repository version is right.
* Note that a newly created repository does not have
@@ -270,10 +278,14 @@ int main(int argc, char **argv)
path = xmalloc(len + 40);
memcpy(path, sha1_dir, len);
- safe_create_dir(sha1_dir);
+ safe_create_dir(sha1_dir, 1);
strcpy(path+len, "/pack");
- safe_create_dir(path);
+ safe_create_dir(path, 1);
strcpy(path+len, "/info");
- safe_create_dir(path);
+ safe_create_dir(path, 1);
+
+ if (shared_repository)
+ git_config_set("core.sharedRepository", "true");
+
return 0;
}