Merge branch 'ab/clone-no-tags'
[gitweb.git] / environment.c
index a17d96aa85bd9196da9090c768090aeec8b6b8be..560408953c8f76a30a093a59505e52c828d8d20b 100644 (file)
@@ -217,6 +217,8 @@ const char *get_git_dir(void)
 
 const char *get_git_common_dir(void)
 {
+       if (!git_dir)
+               setup_git_env();
        return git_common_dir;
 }
 
@@ -277,7 +279,7 @@ char *get_object_directory(void)
        return git_object_dir;
 }
 
-int odb_mkstemp(char *template, size_t limit, const char *pattern)
+int odb_mkstemp(struct strbuf *template, const char *pattern)
 {
        int fd;
        /*
@@ -285,18 +287,16 @@ int odb_mkstemp(char *template, size_t limit, const char *pattern)
         * restrictive except to remove write permission.
         */
        int mode = 0444;
-       snprintf(template, limit, "%s/%s",
-                get_object_directory(), pattern);
-       fd = git_mkstemp_mode(template, mode);
+       git_path_buf(template, "objects/%s", pattern);
+       fd = git_mkstemp_mode(template->buf, mode);
        if (0 <= fd)
                return fd;
 
        /* slow path */
        /* some mkstemp implementations erase template on failure */
-       snprintf(template, limit, "%s/%s",
-                get_object_directory(), pattern);
-       safe_create_leading_directories(template);
-       return xmkstemp_mode(template, mode);
+       git_path_buf(template, "objects/%s", pattern);
+       safe_create_leading_directories(template->buf);
+       return xmkstemp_mode(template->buf, mode);
 }
 
 int odb_pack_keep(const char *name)