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

[PATCH 2/4] create_symref: if symlink fails, fall back to writing a "symbolic ref"

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 25, 2005, 23:40 UTC
Message-ID
<Pine.LNX.4.63.0510260139250.30576@wbgn013.biozentrum.uni-wuerzburg.de>

There are filesystems out there which do not understand symlinks, even if the OS is perfectly capable of writing them. So, do not fail right away, but try to write a symbolic ref first. If that fails, you can die().

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 refs.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

applies-to: ccd3f478f6bdf8174f7d5d24d54434e66fa9068e 2e920b7169ad9661385ba02412cdbdc4e69e00a1

diff --git a/refs.c b/refs.c
index 97506a4..8b544e0 100644
--- a/refs.c
+++ b/refs.c
@@ -116,14 +116,16 @@ const char *resolve_ref(const char *path
 
 int create_symref(const char *git_HEAD, const char *refs_heads_master)
 {
-#if USE_SYMLINK_HEAD
-	unlink(git_HEAD);
-	return symlink(refs_heads_master, git_HEAD);
-#else
 	const char *lockpath;
 	char ref[1000];
 	int fd, len, written;
 
+#if USE_SYMLINK_HEAD
+	unlink(git_HEAD);
+	if (!symlink(refs_heads_master, git_HEAD))
+		return 0;
+#endif
+
 	len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
 	if (sizeof(ref) <= len) {
 		error("refname too long: %s", refs_heads_master);
@@ -144,7 +146,6 @@ int create_symref(const char *git_HEAD, 
 		return -3;
 	}
 	return 0;
-#endif
 }
 
 int read_ref(const char *filename, unsigned char *sha1)
---
0.99.8.GIT
Message 1 of 1 in “create_symref: if symlink fails, fall back to writing a "symbolic ref"”
  1. 2/4 create_symref: if symlink fails, fall back to writing a "symbolic ref"Johannes Schindelin, Oct 25, 2005

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.