move connect_work_tree_and_git_dir to dir.h
authorStefan Beller <sbeller@google.com>
Mon, 12 Dec 2016 19:04:34 +0000 (11:04 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Dec 2016 23:15:07 +0000 (15:15 -0800)
That function was primarily used by submodule code, but the function
itself is not inherently about submodules. In the next patch we'll
introduce relocate_git_dir, which can be used by worktrees as well,
so find a neutral middle ground in dir.h.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
dir.h
submodule.c
submodule.h
diff --git a/dir.c b/dir.c
index bfa8c8a9a51297c3a969c8706467504cb11ce51b..e0efd3c2c3de4eb3f8683564b626355af51a67fc 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -2748,3 +2748,28 @@ void untracked_cache_add_to_index(struct index_state *istate,
 {
        untracked_cache_invalidate_path(istate, path);
 }
+
+/* Update gitfile and core.worktree setting to connect work tree and git dir */
+void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
+{
+       struct strbuf file_name = STRBUF_INIT;
+       struct strbuf rel_path = STRBUF_INIT;
+       char *git_dir = xstrdup(real_path(git_dir_));
+       char *work_tree = xstrdup(real_path(work_tree_));
+
+       /* Update gitfile */
+       strbuf_addf(&file_name, "%s/.git", work_tree);
+       write_file(file_name.buf, "gitdir: %s",
+                  relative_path(git_dir, work_tree, &rel_path));
+
+       /* Update core.worktree setting */
+       strbuf_reset(&file_name);
+       strbuf_addf(&file_name, "%s/config", git_dir);
+       git_config_set_in_file(file_name.buf, "core.worktree",
+                              relative_path(work_tree, git_dir, &rel_path));
+
+       strbuf_release(&file_name);
+       strbuf_release(&rel_path);
+       free(work_tree);
+       free(git_dir);
+}
diff --git a/dir.h b/dir.h
index 97c83bb383a6b1fb5ce58d5e81dead570b73ac43..051674a4316905c1c65eb8817de94a1eebf006e2 100644 (file)
--- a/dir.h
+++ b/dir.h
@@ -335,4 +335,5 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
 void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
 void add_untracked_cache(struct index_state *istate);
 void remove_untracked_cache(struct index_state *istate);
+extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
 #endif
index d4f7afe2f1ad539be760a5a4bd3eb342106a007b..0bb50b4b620a8e4223741775899feec2046be89a 100644 (file)
@@ -1222,31 +1222,6 @@ int merge_submodule(unsigned char result[20], const char *path,
        return 0;
 }
 
-/* Update gitfile and core.worktree setting to connect work tree and git dir */
-void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
-{
-       struct strbuf file_name = STRBUF_INIT;
-       struct strbuf rel_path = STRBUF_INIT;
-       char *git_dir = xstrdup(real_path(git_dir_));
-       char *work_tree = xstrdup(real_path(work_tree_));
-
-       /* Update gitfile */
-       strbuf_addf(&file_name, "%s/.git", work_tree);
-       write_file(file_name.buf, "gitdir: %s",
-                  relative_path(git_dir, work_tree, &rel_path));
-
-       /* Update core.worktree setting */
-       strbuf_reset(&file_name);
-       strbuf_addf(&file_name, "%s/config", git_dir);
-       git_config_set_in_file(file_name.buf, "core.worktree",
-                              relative_path(work_tree, git_dir, &rel_path));
-
-       strbuf_release(&file_name);
-       strbuf_release(&rel_path);
-       free(work_tree);
-       free(git_dir);
-}
-
 int parallel_submodules(void)
 {
        return parallel_jobs;
index d9e197a948fdab44b7a5df4161a5df9c3a2938ff..4e3bf469b4f340e87b1210cd55738bbc229cafa7 100644 (file)
@@ -65,7 +65,6 @@ int merge_submodule(unsigned char result[20], const char *path, const unsigned c
 int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name,
                struct string_list *needs_pushing);
 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
-void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
 int parallel_submodules(void);
 
 /*