submodule: use absolute path for computing relative path connecting
The current caller of connect_work_tree_and_git_dir passes an absolute path for the `git_dir` parameter. In the future patch we will also pass in relative path for `git_dir`. Extend the functionality of connect_work_tree_and_git_dir to take relative paths for parameters. We could work around this in the future patch by computing the absolute path for the git_dir in the calling site, however accepting relative paths for either parameter makes the API for this function much harder to misuse. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Dec 8, 2016 at 13:03 UTC
90c0011619bd4cd4b14c366ab7a9affacb43276a
1 file changed
+7
-6
submodule.c
+7
-6
@@ -1223,27 +1223,28 @@ int merge_submodule(unsigned char result[20], const char *path,
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)
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
- const char *real_work_tree = xstrdup(real_path(work_tree));
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",
1235
- relative_path(git_dir, real_work_tree, &rel_path));
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",
1241
- relative_path(real_work_tree, git_dir,
1242
- &rel_path));
1242
+ relative_path(work_tree, git_dir, &rel_path));
1243
1244
strbuf_release(&file_name);
1245
strbuf_release(&rel_path);
1246
- free((void *)real_work_tree);
1246
+ free(work_tree);
1247
+ free(git_dir);
1248
}
1249
1250
int parallel_submodules(void)