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

[PATCH 3/5] Teach resolve_gitlink_ref() about the .git file

From
LHLars Hjemli <hjemli@gmail.com>
Date
Feb 18, 2008, 10:44 UTC
Message-ID
<1203331463-13857-4-git-send-email-hjemli@gmail.com>
In-Reply-To
<1203331463-13857-3-git-send-email-hjemli@gmail.com>

When .git in a submodule is a file, resolve_gitlink_ref() needs to pick up the real GIT_DIR of the submodule from that file.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
 refs.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/refs.c b/refs.c
index 67d2a50..56de5cf 100644
--- a/refs.c
+++ b/refs.c
@@ -351,6 +351,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *re
 {
 	int len = strlen(path), retval;
 	char *gitdir;
+	const char *tmp;
 
 	while (len && path[len-1] == '/')
 		len--;
@@ -358,9 +359,19 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *re
 		return -1;
 	gitdir = xmalloc(len + MAXREFLEN + 8);
 	memcpy(gitdir, path, len);
-	memcpy(gitdir + len, "/.git/", 7);
-
-	retval = resolve_gitlink_ref_recursive(gitdir, len+6, refname, result, 0);
+	memcpy(gitdir + len, "/.git", 6);
+	len += 5;
+
+	tmp = read_gitfile_gently(gitdir);
+	if (tmp) {
+		free(gitdir);
+		len = strlen(tmp);
+		gitdir = xmalloc(len + MAXREFLEN + 3);
+		memcpy(gitdir, tmp, len);
+	}
+	gitdir[len] = '/';
+	gitdir[++len] = '\0';
+	retval = resolve_gitlink_ref_recursive(gitdir, len, refname, result, 0);
 	free(gitdir);
 	return retval;
 }
-- 
1.5.4.1.188.g3ea1f5
Previous: Lars HjemliNext: Lars Hjemli
Message 4 of 18 in “Introduce the .gitfile”
  1. 0/5 Introduce the .gitfileLars Hjemli, Feb 18, 2008
  2. 1/5 Simplify setup of $GIT_DIR in git-sh-setup.shLars Hjemli, Feb 18, 2008
  3. 2/5 Add platform-independent .git "symlink"Lars Hjemli, Feb 18, 2008
  4. 3/5 Teach resolve_gitlink_ref() about the .git fileLars Hjemli, Feb 18, 2008
  5. 4/5 git-submodule: prepare for the .git-fileLars Hjemli, Feb 18, 2008
  6. 5/5 Teach GIT-VERSION-GEN about the .git fileLars Hjemli, Feb 18, 2008
  7. Johannes SchindelinFeb 18, 2008
  8. Lars HjemliFeb 18, 2008
  9. Jakub NarebskiFeb 18, 2008
  10. Johannes SchindelinFeb 18, 2008
  11. Lars HjemliFeb 18, 2008
  12. 2/5 Add platform-independent .git "symlink"Lars Hjemli, Feb 18, 2008
  13. Johannes SchindelinFeb 18, 2008
  14. Johannes SchindelinFeb 18, 2008
  15. Lars HjemliFeb 18, 2008
  16. Johannes SchindelinFeb 18, 2008
  17. Lars HjemliFeb 18, 2008
  18. Johannes SchindelinFeb 18, 2008

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.