{"thread":{"id":"2912","subject":"[PATCH] git-init-db: initialize shared repositories with --shared","startedAt":"2005-12-22T22:19:37Z","lastAt":"2005-12-22T22:19:37Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"13963","messageId":"Pine.LNX.4.63.0512222318570.12217@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2912","inReplyTo":null,"subject":"[PATCH] git-init-db: initialize shared repositories with --shared","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-22T22:19:37Z","receivedAt":"2005-12-22T22:19:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nNow you can say\n\n\tgit-init-db --shared\n\nif you want other users to be able to push into that repository.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tSo, I lied in my last message. This patch actually changes the\n\tmodes of the $GIT_DIR/{objects,objects/pack,refs,refs/heads,\n\trefs/tags} directories.\n\n\tI just forgot to commit this before sending the patch :-(\n\n cache.h     |    1 +\n init-db.c   |   36 ++++++++++++++++++++++++++----------\n sha1_file.c |    2 +-\n 3 files changed, 28 insertions(+), 11 deletions(-)\n\ne60956946509622bda221cea567f841568f4cd20\ndiff --git a/cache.h b/cache.h\nindex 0f875dd..63acc72 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -184,6 +184,7 @@ extern const unsigned char null_sha1[20]\n \n int git_mkstemp(char *path, size_t n, const char *template);\n \n+int make_group_writable(const char *path);\n int safe_create_leading_directories(char *path);\n char *safe_strncpy(char *, const char *, size_t);\n char *enter_repo(char *path, int strict);\ndiff --git a/init-db.c b/init-db.c\nindex c58b92d..b66b5cd 100644\n--- a/init-db.c\n+++ b/init-db.c\n@@ -9,7 +9,7 @@\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates/\"\n #endif\n \n-static void safe_create_dir(const char *dir)\n+static void safe_create_dir(const char *dir, int share)\n {\n \tif (mkdir(dir, 0777) < 0) {\n \t\tif (errno != EEXIST) {\n@@ -17,6 +17,11 @@ static void safe_create_dir(const char *\n \t\t\texit(1);\n \t\t}\n \t}\n+\n+\tif (shared_repository && share && make_group_writable(dir)) {\n+\t\tfprintf(stderr, \"Could not make %s writable by group\\n\", dir);\n+\t\texit(2);\n+\t}\n }\n \n static int copy_file(const char *dst, const char *src, int mode)\n@@ -32,6 +37,11 @@ static int copy_file(const char *dst, co\n \t}\n \tstatus = copy_fd(fdi, fdo);\n \tclose(fdo);\n+\n+\tif (shared_repository && !status && (mode & 0200) &&\n+\t\t\tmake_group_writable(dst))\n+\t\treturn -1;\n+\n \treturn status;\n }\n \n@@ -48,7 +58,7 @@ static void copy_templates_1(char *path,\n \t * with the way the namespace under .git/ is organized, should\n \t * be really carefully chosen.\n \t */\n-\tsafe_create_dir(path);\n+\tsafe_create_dir(path, 0);\n \twhile ((de = readdir(dir)) != NULL) {\n \t\tstruct stat st_git, st_template;\n \t\tint namelen;\n@@ -176,11 +186,11 @@ static void create_default_files(const c\n \t * Create .git/refs/{heads,tags}\n \t */\n \tstrcpy(path + len, \"refs\");\n-\tsafe_create_dir(path);\n+\tsafe_create_dir(path, 1);\n \tstrcpy(path + len, \"refs/heads\");\n-\tsafe_create_dir(path);\n+\tsafe_create_dir(path, 1);\n \tstrcpy(path + len, \"refs/tags\");\n-\tsafe_create_dir(path);\n+\tsafe_create_dir(path, 1);\n \n \t/* First copy the templates -- we might have the default\n \t * config file there, in which case we would want to read\n@@ -220,7 +230,7 @@ static void create_default_files(const c\n }\n \n static const char init_db_usage[] =\n-\"git-init-db [--template=<template-directory>]\";\n+\"git-init-db [--template=<template-directory>] [--shared]\";\n \n /*\n  * If you want to, you can share the DB area with any number of branches.\n@@ -239,6 +249,8 @@ int main(int argc, char **argv)\n \t\tchar *arg = argv[1];\n \t\tif (!strncmp(arg, \"--template=\", 11))\n \t\t\ttemplate_dir = arg+11;\n+\t\telse if (!strcmp(arg, \"--shared\"))\n+\t\t\tshared_repository = 1;\n \t\telse\n \t\t\tdie(init_db_usage);\n \t}\n@@ -251,7 +263,7 @@ int main(int argc, char **argv)\n \t\tgit_dir = DEFAULT_GIT_DIR_ENVIRONMENT;\n \t\tfprintf(stderr, \"defaulting to local storage area\\n\");\n \t}\n-\tsafe_create_dir(git_dir);\n+\tsafe_create_dir(git_dir, 0);\n \n \t/* Check to see if the repository version is right.\n \t * Note that a newly created repository does not have\n@@ -270,10 +282,14 @@ int main(int argc, char **argv)\n \tpath = xmalloc(len + 40);\n \tmemcpy(path, sha1_dir, len);\n \n-\tsafe_create_dir(sha1_dir);\n+\tsafe_create_dir(sha1_dir, 1);\n \tstrcpy(path+len, \"/pack\");\n-\tsafe_create_dir(path);\n+\tsafe_create_dir(path, 1);\n \tstrcpy(path+len, \"/info\");\n-\tsafe_create_dir(path);\n+\tsafe_create_dir(path, 0);\n+\n+\tif (shared_repository)\n+\t\tgit_config_set(\"core.sharedRepository\", \"true\");\n+\n \treturn 0;\n }\ndiff --git a/sha1_file.c b/sha1_file.c\nindex e109a07..10d63f1 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -48,7 +48,7 @@ int get_sha1_hex(const char *hex, unsign\n \treturn 0;\n }\n \n-static int make_group_writable(const char *path)\n+int make_group_writable(const char *path)\n {\n \tstruct stat st;\n \n-- \n1.0.GIT\n"}]}