move connect_work_tree_and_git_dir to dir.h

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>

Stefan Beller committed Dec 12, 2016 at 11:04 UTC 47e83eb3b7d5410769d7f4d3930ba7fa12915680
4 files changed +26 -26
dir.c
+25
@@ -2748,3 +2748,28 @@ void untracked_cache_add_to_index(struct index_state *istate,
2748 {
2749 untracked_cache_invalidate_path(istate, path);
2750 }
2751 +
2752 +/* Update gitfile and core.worktree setting to connect work tree and git dir */
2753 +void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
2754 +{
2755 + struct strbuf file_name = STRBUF_INIT;
2756 + struct strbuf rel_path = STRBUF_INIT;
2757 + char *git_dir = xstrdup(real_path(git_dir_));
2758 + char *work_tree = xstrdup(real_path(work_tree_));
2759 +
2760 + /* Update gitfile */
2761 + strbuf_addf(&file_name, "%s/.git", work_tree);
2762 + write_file(file_name.buf, "gitdir: %s",
2763 + relative_path(git_dir, work_tree, &rel_path));
2764 +
2765 + /* Update core.worktree setting */
2766 + strbuf_reset(&file_name);
2767 + strbuf_addf(&file_name, "%s/config", git_dir);
2768 + git_config_set_in_file(file_name.buf, "core.worktree",
2769 + relative_path(work_tree, git_dir, &rel_path));
2770 +
2771 + strbuf_release(&file_name);
2772 + strbuf_release(&rel_path);
2773 + free(work_tree);
2774 + free(git_dir);
2775 +}
dir.h
+1
@@ -335,4 +335,5 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
335 void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
336 void add_untracked_cache(struct index_state *istate);
337 void remove_untracked_cache(struct index_state *istate);
338 +extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
339 #endif
submodule.c
-25
@@ -1222,31 +1222,6 @@ int merge_submodule(unsigned char result[20], const char *path,
1222 return 0;
1223 }
1224
1225 -/* Update gitfile and core.worktree setting to connect work tree and git dir */
1226 -void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
1227 -{
1228 - struct strbuf file_name = STRBUF_INIT;
1229 - struct strbuf rel_path = STRBUF_INIT;
1230 - char *git_dir = xstrdup(real_path(git_dir_));
1231 - char *work_tree = xstrdup(real_path(work_tree_));
1232 -
1233 - /* Update gitfile */
1234 - strbuf_addf(&file_name, "%s/.git", work_tree);
1235 - write_file(file_name.buf, "gitdir: %s",
1236 - relative_path(git_dir, work_tree, &rel_path));
1237 -
1238 - /* Update core.worktree setting */
1239 - strbuf_reset(&file_name);
1240 - strbuf_addf(&file_name, "%s/config", git_dir);
1241 - git_config_set_in_file(file_name.buf, "core.worktree",
1242 - relative_path(work_tree, git_dir, &rel_path));
1243 -
1244 - strbuf_release(&file_name);
1245 - strbuf_release(&rel_path);
1246 - free(work_tree);
1247 - free(git_dir);
1248 -}
1249 -
1225 int parallel_submodules(void)
1226 {
1227 return parallel_jobs;
submodule.h
-1
@@ -65,7 +65,6 @@ int merge_submodule(unsigned char result[20], const char *path, const unsigned c
65 int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name,
66 struct string_list *needs_pushing);
67 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
68 -void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
68 int parallel_submodules(void);
69
70 /*