aboutsummaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorHeikki Orsila <heikki.orsila@iki.fi>2008-04-16 11:34:24 +0300
committerJunio C Hamano <gitster@pobox.com>2008-04-16 18:23:54 -0700
commit06cbe8550324e0fd2290839bf3b9a92aa53b70ab (patch)
treee455c3b2f28bd57e3d166f8bf1f11bab5cf7ae1e /setup.c
parenta17b1d2f0b3128be6f116bf22b58244b310d27b9 (diff)
downloadgit-06cbe8550324e0fd2290839bf3b9a92aa53b70ab.tar.gz
git-06cbe8550324e0fd2290839bf3b9a92aa53b70ab.tar.xz
Make core.sharedRepository more generic
git init --shared=0xxx, where '0xxx' is an octal number, will create a repository with file modes set to '0xxx'. Users with a safe umask value (0077) can use this option to force file modes. For example, '0640' is a group-readable but not group-writable regardless of user's umask value. Values compatible with old Git versions are written as they were before, for compatibility reasons. That is, "1" for "group" and "2" for "everybody". "git config core.sharedRepository 0xxx" is also handled. Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/setup.c b/setup.c
index 3d2d9580f..1b4fa6a8c 100644
--- a/setup.c
+++ b/setup.c
@@ -428,21 +428,53 @@ const char *setup_git_directory_gently(int *nongit_ok)
int git_config_perm(const char *var, const char *value)
{
- if (value) {
- int i;
- if (!strcmp(value, "umask"))
- return PERM_UMASK;
- if (!strcmp(value, "group"))
- return PERM_GROUP;
- if (!strcmp(value, "all") ||
- !strcmp(value, "world") ||
- !strcmp(value, "everybody"))
- return PERM_EVERYBODY;
- i = atoi(value);
- if (i > 1)
- return i;
+ int i;
+ char *endptr;
+
+ if (value == NULL)
+ return PERM_GROUP;
+
+ if (!strcmp(value, "umask"))
+ return PERM_UMASK;
+ if (!strcmp(value, "group"))
+ return PERM_GROUP;
+ if (!strcmp(value, "all") ||
+ !strcmp(value, "world") ||
+ !strcmp(value, "everybody"))
+ return PERM_EVERYBODY;
+
+ /* Parse octal numbers */
+ i = strtol(value, &endptr, 8);
+
+ /* If not an octal number, maybe true/false? */
+ if (*endptr != 0)
+ return git_config_bool(var, value) ? PERM_GROUP : PERM_UMASK;
+
+ /*
+ * Treat values 0, 1 and 2 as compatibility cases, otherwise it is
+ * a chmod value.
+ */
+ switch (i) {
+ case PERM_UMASK: /* 0 */
+ return PERM_UMASK;
+ case OLD_PERM_GROUP: /* 1 */
+ return PERM_GROUP;
+ case OLD_PERM_EVERYBODY: /* 2 */
+ return PERM_EVERYBODY;
}
- return git_config_bool(var, value);
+
+ /* A filemode value was given: 0xxx */
+
+ if ((i & 0600) != 0600)
+ die("Problem with core.sharedRepository filemode value "
+ "(0%.3o).\nThe owner of files must always have "
+ "read and write permissions.", i);
+
+ /*
+ * Mask filemode value. Others can not get write permission.
+ * x flags for directories are handled separately.
+ */
+ return i & 0666;
}
int check_repository_format_version(const char *var, const char *value)