path: implement common_dir handling in git_pathdup_submodule()
[gitweb.git] / setup.c
diff --git a/setup.c b/setup.c
index feb85651ef4f9808505ae96b5fd954fd84642403..e41e5e1a82e3cbd9e0168e158b336f621116adc7 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -228,15 +228,22 @@ void verify_non_filename(const char *prefix, const char *arg)
 }
 
 int get_common_dir(struct strbuf *sb, const char *gitdir)
+{
+       const char *git_env_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
+       if (git_env_common_dir) {
+               strbuf_addstr(sb, git_env_common_dir);
+               return 1;
+       } else {
+               return get_common_dir_noenv(sb, gitdir);
+       }
+}
+
+int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)
 {
        struct strbuf data = STRBUF_INIT;
        struct strbuf path = STRBUF_INIT;
-       const char *git_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
        int ret = 0;
-       if (git_common_dir) {
-               strbuf_addstr(sb, git_common_dir);
-               return 1;
-       }
+
        strbuf_addf(&path, "%s/commondir", gitdir);
        if (file_exists(path.buf)) {
                if (strbuf_read_file(&data, path.buf, 0) <= 0)
@@ -402,9 +409,9 @@ static void update_linked_gitdir(const char *gitfile, const char *gitdir)
        struct strbuf path = STRBUF_INIT;
        struct stat st;
 
-       strbuf_addf(&path, "%s/gitfile", gitdir);
+       strbuf_addf(&path, "%s/gitdir", gitdir);
        if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL))
-               write_file_gently(path.buf, "%s\n", gitfile);
+               write_file(path.buf, "%s", gitfile);
        strbuf_release(&path);
 }