[PATCH] git-init-db: initialize shared repositories with --shared
From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:42:15
Subsystem:
the rest · Maintainer:
Linus Torvalds
Now you can say
git-init-db --shared
if you want other users to be able to push into that repository.
Signed-off-by: Johannes Schindelin <redacted>
---
So, I lied in my last message. This patch actually changes the
modes of the $GIT_DIR/{objects,objects/pack,refs,refs/heads,
refs/tags} directories.
I just forgot to commit this before sending the patch :-(
cache.h | 1 +
init-db.c | 36 ++++++++++++++++++++++++++----------
sha1_file.c | 2 +-
3 files changed, 28 insertions(+), 11 deletions(-)
e60956946509622bda221cea567f841568f4cd20diff --git a/cache.h b/cache.h
index 0f875dd..63acc72 100644
--- a/cache.h
+++ b/cache.h@@ -184,6 +184,7 @@ extern const unsigned char null_sha1[20] int git_mkstemp(char *path, size_t n, const char *template); +int make_group_writable(const char *path); int safe_create_leading_directories(char *path); char *safe_strncpy(char *, const char *, size_t); char *enter_repo(char *path, int strict);
diff --git a/init-db.c b/init-db.c
index c58b92d..b66b5cd 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,11 @@ static void safe_create_dir(const char * exit(1); } } + + if (shared_repository && share && make_group_writable(dir)) { + fprintf(stderr, "Could not make %s writable by group\n", dir); + exit(2); + } } static int copy_file(const char *dst, const char *src, int mode)
@@ -32,6 +37,11 @@ static int copy_file(const char *dst, co } status = copy_fd(fdi, fdo); close(fdo); + + if (shared_repository && !status && (mode & 0200) && + make_group_writable(dst)) + return -1; + return status; }
@@ -48,7 +58,7 @@ static void copy_templates_1(char *path, * with the way the namespace under .git/ is organized, should * be really carefully chosen. */ - safe_create_dir(path); + safe_create_dir(path, 0); while ((de = readdir(dir)) != NULL) { struct stat st_git, st_template; int namelen;
@@ -176,11 +186,11 @@ static void create_default_files(const c * 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 +230,7 @@ static void create_default_files(const c } 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 +249,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 +263,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 +282,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, 0); + + if (shared_repository) + git_config_set("core.sharedRepository", "true"); + return 0; }
diff --git a/sha1_file.c b/sha1_file.c
index e109a07..10d63f1 100644
--- a/sha1_file.c
+++ b/sha1_file.c@@ -48,7 +48,7 @@ int get_sha1_hex(const char *hex, unsign return 0; } -static int make_group_writable(const char *path) +int make_group_writable(const char *path) { struct stat st;
--
1.0.GIT