Code

config option log.showroot to show the diff of root commits
[git.git] / path.c
diff --git a/path.c b/path.c
index 194e0b553f7a5c4fd99b348228112b308c5419b6..d2c076d7cbad3a16a002897d926cc13633be4f77 100644 (file)
--- a/path.c
+++ b/path.c
 #include "cache.h"
 #include <pwd.h>
 
-static char pathname[PATH_MAX];
 static char bad_path[] = "/bad-path/";
 
+static char *get_pathname(void)
+{
+       static char pathname_array[4][PATH_MAX];
+       static int index;
+       return pathname_array[3 & ++index];
+}
+
 static char *cleanup_path(char *path)
 {
        /* Clean it up */
@@ -31,6 +37,7 @@ char *mkpath(const char *fmt, ...)
 {
        va_list args;
        unsigned len;
+       char *pathname = get_pathname();
 
        va_start(args, fmt);
        len = vsnprintf(pathname, PATH_MAX, fmt, args);
@@ -43,6 +50,7 @@ char *mkpath(const char *fmt, ...)
 char *git_path(const char *fmt, ...)
 {
        const char *git_dir = get_git_dir();
+       char *pathname = get_pathname();
        va_list args;
        unsigned len;
 
@@ -77,25 +85,12 @@ int git_mkstemp(char *path, size_t len, const char *template)
                pch += n;
        }
 
-       safe_strncpy(pch, template, len);
+       strlcpy(pch, template, len);
 
        return mkstemp(path);
 }
 
 
-size_t safe_strncpy(char *dest, const char *src, size_t size)
-{
-       size_t ret = strlen(src);
-
-       if (size) {
-               size_t len = (ret >= size) ? size - 1 : ret;
-               memcpy(dest, src, len);
-               dest[len] = '\0';
-       }
-       return ret;
-}
-
-
 int validate_symref(const char *path)
 {
        struct stat st;
@@ -267,14 +262,24 @@ int adjust_shared_perm(const char *path)
                return -1;
        mode = st.st_mode;
        if (mode & S_IRUSR)
-               mode |= S_IRGRP;
+               mode |= (shared_repository == PERM_GROUP
+                        ? S_IRGRP
+                        : (shared_repository == PERM_EVERYBODY
+                           ? (S_IRGRP|S_IROTH)
+                           : 0));
+
        if (mode & S_IWUSR)
                mode |= S_IWGRP;
+
        if (mode & S_IXUSR)
-               mode |= S_IXGRP;
+               mode |= (shared_repository == PERM_GROUP
+                        ? S_IXGRP
+                        : (shared_repository == PERM_EVERYBODY
+                           ? (S_IXGRP|S_IXOTH)
+                           : 0));
        if (S_ISDIR(mode))
                mode |= S_ISGID;
-       if (chmod(path, mode) < 0)
+       if ((mode & st.st_mode) != mode && chmod(path, mode) < 0)
                return -2;
        return 0;
 }