Skip to content

Commit 47e83eb

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a248cf commit 47e83eb

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

dir.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,3 +2748,28 @@ void untracked_cache_add_to_index(struct index_state *istate,
27482748
{
27492749
untracked_cache_invalidate_path(istate, path);
27502750
}
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,5 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
335335
void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
336336
void add_untracked_cache(struct index_state *istate);
337337
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);
338339
#endif

submodule.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,31 +1222,6 @@ int merge_submodule(unsigned char result[20], const char *path,
12221222
return 0;
12231223
}
12241224

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-
12501225
int parallel_submodules(void)
12511226
{
12521227
return parallel_jobs;

submodule.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ int merge_submodule(unsigned char result[20], const char *path, const unsigned c
6565
int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name,
6666
struct string_list *needs_pushing);
6767
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);
6968
int parallel_submodules(void);
7069

7170
/*

0 commit comments

Comments
 (0)