git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv5 1/5] submodule: use absolute path for computing relative path connecting

From
Stefan Beller <sbeller@google.com>
Date
Dec 7, 2016, 21:01 UTC
Message-ID
<20161207210157.18932-2-sbeller@google.com>
In-Reply-To
<20161207210157.18932-1-sbeller@google.com>

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>
---
 submodule.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/submodule.c b/submodule.c
index 6f7d883de9..66c5ce5a24 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1227,23 +1227,25 @@ 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;
-	const char *real_work_tree = xstrdup(real_path(work_tree));
+	char *real_git_dir = xstrdup(real_path(git_dir));
+	char *real_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, real_work_tree, &rel_path));
+		   relative_path(real_git_dir, real_work_tree, &rel_path));
 
 	/* Update core.worktree setting */
 	strbuf_reset(&file_name);
-	strbuf_addf(&file_name, "%s/config", git_dir);
+	strbuf_addf(&file_name, "%s/config", real_git_dir);
 	git_config_set_in_file(file_name.buf, "core.worktree",
-			       relative_path(real_work_tree, git_dir,
+			       relative_path(real_work_tree, real_git_dir,
 					     &rel_path));
 
 	strbuf_release(&file_name);
 	strbuf_release(&rel_path);
-	free((void *)real_work_tree);
+	free(real_work_tree);
+	free(real_git_dir);
 }
 
 int parallel_submodules(void)
-- 
2.11.0.rc2.28.g2af45f1.dirty
Previous: Duy NguyenNext: Junio C Hamano
Message 13 of 16 in “[PATCHv5 0/5] submodule embedgitdirs”
  1. Stefan BellerDec 7, 2016
  2. 2/5 submodule helper: support super prefixStefan Beller, Dec 7, 2016
  3. 3/5 test-lib-functions.sh: teach test_commit -C <dir>Stefan Beller, Dec 7, 2016
  4. 4/5 worktree: get worktrees from submodulesStefan Beller, Dec 7, 2016
  5. Junio C HamanoDec 7, 2016
  6. Stefan BellerDec 7, 2016
  7. Brandon WilliamsDec 8, 2016
  8. 5/5 submodule: add embed-git-dir functionStefan Beller, Dec 7, 2016
  9. Junio C HamanoDec 7, 2016
  10. Stefan BellerDec 7, 2016
  11. Brandon WilliamsDec 8, 2016
  12. Duy NguyenDec 8, 2016
  13. 1/5 submodule: use absolute path for computing relative path connectingStefan Beller, Dec 7, 2016
  14. Junio C HamanoDec 7, 2016
  15. Junio C HamanoDec 7, 2016
  16. Stefan BellerDec 7, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.