summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2005-10-26 01:40:31 +0200
committerJunio C Hamano <junkio@cox.net>2005-10-25 23:46:15 -0700
commit303958dc42d451aead0e1b9cf7b9836831a05f4b (patch)
treeaca610711c650866e3118ff09c085fe270ffdced /refs.c
parentf89ad67fb054bead054bc92b4d0d4d007248b611 (diff)
downloadgit-303958dc42d451aead0e1b9cf7b9836831a05f4b.tar.gz
create_symref: if symlink fails, fall back to writing a "symbolic ref"
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/refs.c b/refs.c
index 97506a4ebd..a52b038eef 100644
--- a/refs.c
+++ b/refs.c
@@ -116,14 +116,17 @@ const char *resolve_ref(const char *path, unsigned char *sha1, int reading)
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;
+ fprintf(stderr, "no symlink - falling back to symbolic ref\n");
+#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 +147,6 @@ int create_symref(const char *git_HEAD, const char *refs_heads_master)
return -3;
}
return 0;
-#endif
}
int read_ref(const char *filename, unsigned char *sha1)