diff: on win32, treat fake "symlinks" specially On platforms that lack `core.symlinks`, we should not go looking for symbolic links and `p_readlink` their target. Instead, we should examine the file's contents.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/src/diff_file.c b/src/diff_file.c
index c603628..ecc34cf 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -259,10 +259,35 @@ static int diff_file_content_load_blob(
return error;
}
+static int diff_file_content_load_workdir_symlink_fake(
+ git_diff_file_content *fc, git_buf *path)
+{
+ git_buf target = GIT_BUF_INIT;
+ int error;
+
+ if ((error = git_futils_readbuffer(&target, path->ptr)) < 0)
+ return error;
+
+ fc->map.len = git_buf_len(&target);
+ fc->map.data = git_buf_detach(&target);
+ fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
+
+ git_buf_free(&target);
+ return error;
+}
+
static int diff_file_content_load_workdir_symlink(
git_diff_file_content *fc, git_buf *path)
{
ssize_t alloc_len, read_len;
+ int symlink_supported, error;
+
+ if ((error = git_repository__cvar(
+ &symlink_supported, fc->repo, GIT_CVAR_SYMLINKS)) < 0)
+ return -1;
+
+ if (!symlink_supported)
+ return diff_file_content_load_workdir_symlink_fake(fc, path);
/* link path on disk could be UTF-16, so prepare a buffer that is
* big enough to handle some UTF-8 data expansion