{"thread":{"id":"2932","subject":"[PATCH] Handle symlinks graciously","startedAt":"2005-12-26T21:31:42Z","lastAt":"2005-12-27T02:33:53Z","messageCount":3,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"14048","messageId":"Pine.LNX.4.63.0512262231350.21076@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2932","inReplyTo":null,"subject":"[PATCH] Handle symlinks graciously","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-26T21:31:42Z","receivedAt":"2005-12-26T21:31:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis patch converts a stat() to an lstat() call, thereby fixing the case\nwhen the date of a symlink was not the same as the one recorded in the\nindex. The included test case demonstrates this.\n\nThis is for the case that the symlink points to a non-existing file. If\nthe file exists, worse things than just an error message happen.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tA few weeks ago I hunted a bug in t4004 on OS X, just to discover\n\tthat it only occurred rarely. The problem is when the atime or mtime\n\tdiffer: in this case, diff-index would try to stat() the symlink,\n\tnot lstat() it.\n\n diff.c                  |    2 +\n t/t4011-diff-symlink.sh |   84 +++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 85 insertions(+), 1 deletions(-)\n create mode 100755 t/t4011-diff-symlink.sh\n\nbd43cfdf69d99c3552fab5a375d9a72657d3bcad\ndiff --git a/diff.c b/diff.c\nindex c815918..6f064df 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -650,7 +650,7 @@ static void diff_fill_sha1_info(struct d\n \tif (DIFF_FILE_VALID(one)) {\n \t\tif (!one->sha1_valid) {\n \t\t\tstruct stat st;\n-\t\t\tif (stat(one->path, &st) < 0)\n+\t\t\tif (lstat(one->path, &st) < 0)\n \t\t\t\tdie(\"stat %s\", one->path);\n \t\t\tif (index_path(one->sha1, one->path, &st, 0))\n \t\t\t\tdie(\"cannot hash %s\\n\", one->path);\ndiff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh\nnew file mode 100755\nindex 0000000..9e70063\n--- /dev/null\n+++ b/t/t4011-diff-symlink.sh\n@@ -0,0 +1,84 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2005 Johannes Schindelin\n+#\n+\n+test_description='Test diff of symlinks.\n+\n+'\n+. ./test-lib.sh\n+. ../diff-lib.sh\n+\n+cat > expected << EOF\n+diff --git a/frotz b/frotz\n+new file mode 120000\n+index 0000000..7c465af\n+--- /dev/null\n++++ b/frotz\n+@@ -0,0 +1 @@\n++xyzzy\n+\\ No newline at end of file\n+EOF\n+\n+test_expect_success \\\n+    'diff new symlink' \\\n+    'ln -s xyzzy frotz &&\n+    git-update-index &&\n+    tree=$(git-write-tree) &&\n+    git-update-index --add frotz &&\n+    GIT_DIFF_OPTS=--unified=0 git-diff-index -M -p $tree > current &&\n+    compare_diff_patch current expected'\n+\n+test_expect_success \\\n+    'diff unchanged symlink' \\\n+    'tree=$(git-write-tree) &&\n+    test -z \"$(git-diff-index --name-only $tree)\"'\n+\n+cat > expected << EOF\n+diff --git a/frotz b/frotz\n+deleted file mode 120000\n+index 7c465af..0000000\n+--- a/frotz\n++++ /dev/null\n+@@ -1 +0,0 @@\n+-xyzzy\n+\\ No newline at end of file\n+EOF\n+\n+test_expect_success \\\n+    'diff removed symlink' \\\n+    'rm frotz &&\n+    git-diff-index -M -p $tree > current &&\n+    compare_diff_patch current expected'\n+\n+cat > expected << EOF\n+diff --git a/frotz b/frotz\n+EOF\n+\n+test_expect_success \\\n+    'diff identical, but newly created symlink' \\\n+    'sleep 1 &&\n+    ln -s xyzzy frotz &&\n+    git-diff-index -M -p $tree > current &&\n+    compare_diff_patch current expected'\n+\n+cat > expected << EOF\n+diff --git a/frotz b/frotz\n+index 7c465af..df1db54 120000\n+--- a/frotz\n++++ b/frotz\n+@@ -1 +1 @@\n+-xyzzy\n+\\ No newline at end of file\n++yxyyz\n+\\ No newline at end of file\n+EOF\n+\n+test_expect_success \\\n+    'diff different symlink' \\\n+    'rm frotz &&\n+    ln -s yxyyz frotz &&\n+    git-diff-index -M -p $tree > current &&\n+    compare_diff_patch current expected'\n+\n+test_done\n-- \n1.0.GIT\n"},{"id":"14051","messageId":"Pine.LNX.4.63.0512270000070.347@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2932","inReplyTo":"Pine.LNX.4.63.0512262231350.21076@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Handle symlinks graciously","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-26T23:00:58Z","receivedAt":"2005-12-26T23:00:58Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nto make the test t4011 pass all the time, this little patch is needed on \ntop:\n\ndiff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh\nindex 9e70063..e3ebf38 100755\n--- a/t/t4011-diff-symlink.sh\n+++ b/t/t4011-diff-symlink.sh\n@@ -32,6 +32,7 @@ test_expect_success \\\n test_expect_success \\\n     'diff unchanged symlink' \\\n     'tree=$(git-write-tree) &&\n+    git-update-index frotz &&\n     test -z \"$(git-diff-index --name-only $tree)\"'\n \n cat > expected << EOF\n\nCiao,\nDscho\n"},{"id":"14057","messageId":"7v8xu7feum.fsf@assigned-by-dhcp.cox.net","threadId":"2932","inReplyTo":"Pine.LNX.4.63.0512262231350.21076@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Handle symlinks graciously","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-27T02:33:53Z","receivedAt":"2005-12-27T02:33:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Good catch; thanks.\n"}]}