@matheusbsbs / matheus-bagliano / commits / ab3b7b9a6e
Fork 0

blame,cat-file: Demonstrate --textconv is wrongly running converter on symlinks

git blame --textconv is wrongly calling the textconv filter on symlinks: symlinks are stored as blobs whose content is the target of the link, and blame calls the textconv filter on a temporary file filled-in with the content of this blob. For example: $ git blame -C -C regular-file.pdf Error: May not be a PDF file (continuing anyway) Error: PDF file is damaged - attempting to reconstruct xref table... Error: Couldn't find trailer dictionary Error: Couldn't read xref table Warning: program returned non-zero exit code #1 fatal: unable to read files to diff That errors come from pdftotext run on symlink.pdf being extracted to /tmp/ with one-line plain-text content pointing to link destination. So several failures are demonstrated here: - git cat-file --textconv :symlink.bin # also HEAD:symlink.bin - git blame --textconv symlink.bin - git blame -C -C --textconv regular-file # but also looks on symlink.bin At present they all fail with something like. E: /tmp/j3ELEs_symlink.bin is not "binary" file NOTE: git diff doesn't try to textconv the pathnames, it runs the textual diff without textconv, which is the expected behavior. Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru> Reviewed-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kirill Smelkov committed Sep 29, 2010 at 15:35 UTC ab3b7b9a6e3bf5793520f06eb76fb03ffe8231cb
2 files changed +78
t/t8006-blame-textconv.sh
+49
@@ -17,10 +17,16 @@ chmod +x helper
17 test_expect_success 'setup ' '
18 echo "bin: test 1" >one.bin &&
19 echo "bin: test number 2" >two.bin &&
20 + if test_have_prereq SYMLINKS; then
21 + ln -s one.bin symlink.bin
22 + fi &&
23 git add . &&
24 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
25 echo "bin: test 1 version 2" >one.bin &&
26 echo "bin: test number 2 version 2" >>two.bin &&
27 + if test_have_prereq SYMLINKS; then
28 + ln -sf two.bin symlink.bin
29 + fi &&
30 GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
31 '
32
@@ -78,4 +84,47 @@ test_expect_success 'blame from previous revision' '
84 test_cmp expected result
85 '
86
87 +cat >expected <<EOF
88 +(Number2 2010-01-01 20:00:00 +0000 1) two.bin
89 +EOF
90 +
91 +test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' '
92 + git blame --no-textconv symlink.bin >blame &&
93 + find_blame <blame >result &&
94 + test_cmp expected result
95 +'
96 +
97 +# fails with '...symlink.bin is not "binary" file'
98 +test_expect_failure SYMLINKS 'blame --textconv (on symlink)' '
99 + git blame --textconv symlink.bin >blame &&
100 + find_blame <blame >result &&
101 + test_cmp expected result
102 +'
103 +
104 +# cp two.bin three.bin and make small tweak
105 +# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin)
106 +test_expect_success SYMLINKS 'make another new commit' '
107 + cat >three.bin <<\EOF &&
108 +bin: test number 2
109 +bin: test number 2 version 2
110 +bin: test number 2 version 3
111 +bin: test number 3
112 +EOF
113 + git add three.bin &&
114 + GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00"
115 +'
116 +
117 +# fails with '...symlink.bin is not "binary" file'
118 +test_expect_failure SYMLINKS 'blame on last commit (-C -C, symlink)' '
119 + git blame -C -C three.bin >blame &&
120 + find_blame <blame >result &&
121 + cat >expected <<\EOF &&
122 +(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2
123 +(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2
124 +(Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3
125 +(Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3
126 +EOF
127 + test_cmp expected result
128 +'
129 +
130 test_done
t/t8007-cat-file-textconv.sh
+29
@@ -12,6 +12,9 @@ chmod +x helper
12
13 test_expect_success 'setup ' '
14 echo "bin: test" >one.bin &&
15 + if test_have_prereq SYMLINKS; then
16 + ln -s one.bin symlink.bin
17 + fi &&
18 git add . &&
19 GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
20 echo "bin: test version 2" >one.bin &&
@@ -68,4 +71,30 @@ test_expect_success 'cat-file --textconv on previous commit' '
71 git cat-file --textconv HEAD^:one.bin >result &&
72 test_cmp expected result
73 '
74 +
75 +test_expect_success SYMLINKS 'cat-file without --textconv (symlink)' '
76 + git cat-file blob :symlink.bin >result &&
77 + printf "%s" "one.bin" >expected
78 + test_cmp expected result
79 +'
80 +
81 +
82 +# fails because cat-file tries to run converter on symlink.bin
83 +test_expect_failure SYMLINKS 'cat-file --textconv on index (symlink)' '
84 + ! git cat-file --textconv :symlink.bin 2>result &&
85 + cat >expected <<\EOF &&
86 +fatal: git cat-file --textconv: unable to run textconv on :symlink.bin
87 +EOF
88 + test_cmp expected result
89 +'
90 +
91 +# fails because cat-file tries to run converter on symlink.bin
92 +test_expect_failure SYMLINKS 'cat-file --textconv on HEAD (symlink)' '
93 + ! git cat-file --textconv HEAD:symlink.bin 2>result &&
94 + cat >expected <<EOF &&
95 +fatal: git cat-file --textconv: unable to run textconv on HEAD:symlink.bin
96 +EOF
97 + test_cmp expected result
98 +'
99 +
100 test_done