@matheusbsbs / matheus-bagliano / commits / 303958dc42
Fork 0

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>

Johannes Schindelin committed Oct 26, 2005 at 01:40 UTC 303958dc42d451aead0e1b9cf7b9836831a05f4b
1 file changed +7 -5
refs.c
+7 -5
@@ -116,14 +116,17 @@ const char *resolve_ref(const char *path, unsigned char *sha1, int reading)
116
117 int create_symref(const char *git_HEAD, const char *refs_heads_master)
118 {
119 -#if USE_SYMLINK_HEAD
120 - unlink(git_HEAD);
121 - return symlink(refs_heads_master, git_HEAD);
122 -#else
119 const char *lockpath;
120 char ref[1000];
121 int fd, len, written;
122
123 +#if USE_SYMLINK_HEAD
124 + unlink(git_HEAD);
125 + if (!symlink(refs_heads_master, git_HEAD))
126 + return 0;
127 + fprintf(stderr, "no symlink - falling back to symbolic ref\n");
128 +#endif
129 +
130 len = snprintf(ref, sizeof(ref), "ref: %s\n", refs_heads_master);
131 if (sizeof(ref) <= len) {
132 error("refname too long: %s", refs_heads_master);
@@ -144,7 +147,6 @@ int create_symref(const char *git_HEAD, const char *refs_heads_master)
147 return -3;
148 }
149 return 0;
147 -#endif
150 }
151
152 int read_ref(const char *filename, unsigned char *sha1)