2008-10-26 12:42:25 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='diff.*.textconv tests'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
find_diff() {
|
|
|
|
sed '1,/^index /d' | sed '/^-- $/,$d'
|
|
|
|
}
|
|
|
|
|
|
|
|
cat >expect.binary <<'EOF'
|
|
|
|
Binary files a/file and b/file differ
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat >expect.text <<'EOF'
|
|
|
|
--- a/file
|
|
|
|
+++ b/file
|
|
|
|
@@ -1 +1,2 @@
|
|
|
|
0
|
|
|
|
+1
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat >hexdump <<'EOF'
|
|
|
|
#!/bin/sh
|
2012-06-13 00:49:59 +08:00
|
|
|
"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
|
2008-10-26 12:42:25 +08:00
|
|
|
EOF
|
|
|
|
chmod +x hexdump
|
|
|
|
|
|
|
|
test_expect_success 'setup binary file with history' '
|
|
|
|
printf "\\0\\n" >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m one &&
|
2008-12-02 16:31:01 +08:00
|
|
|
printf "\\01\\n" >>file &&
|
2008-10-26 12:42:25 +08:00
|
|
|
git add file &&
|
|
|
|
git commit -m two
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'file is considered binary by porcelain' '
|
|
|
|
git diff HEAD^ HEAD >diff &&
|
|
|
|
find_diff <diff >actual &&
|
|
|
|
test_cmp expect.binary actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'file is considered binary by plumbing' '
|
|
|
|
git diff-tree -p HEAD^ HEAD >diff &&
|
|
|
|
find_diff <diff >actual &&
|
|
|
|
test_cmp expect.binary actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'setup textconv filters' '
|
|
|
|
echo file diff=foo >.gitattributes &&
|
2010-01-02 06:15:18 +08:00
|
|
|
git config diff.foo.textconv "\"$(pwd)\""/hexdump &&
|
2008-10-26 12:42:25 +08:00
|
|
|
git config diff.fail.textconv false
|
|
|
|
'
|
|
|
|
|
refactor userdiff textconv code
The original implementation of textconv put the conversion
into fill_mmfile. This was a bad idea for a number of
reasons:
- it made the semantics of fill_mmfile unclear. In some
cases, it was allocating data (if a text conversion
occurred), and in some cases not (if we could use the
data directly from the filespec). But the caller had
no idea which had happened, and so didn't know whether
the memory should be freed
- similarly, the caller had no idea if a text conversion
had occurred, and so didn't know whether the contents
should be treated as binary or not. This meant that we
incorrectly guessed that text-converted content was
binary and didn't actually show it (unless the user
overrode us with "diff.foo.binary = false", which then
created problems in plumbing where the text conversion
did _not_ occur)
- not all callers of fill_mmfile want the text contents. In
particular, we don't really want diffstat, whitespace
checks, patch id generation, etc, to look at the
converted contents.
This patch pulls the conversion code directly into
builtin_diff, so that we only see the conversion when
generating an actual patch. We also then know whether we are
doing a conversion, so we can check the binary-ness and free
the data from the mmfile appropriately (the previous version
leaked quite badly when text conversion was used)
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-10-26 12:44:53 +08:00
|
|
|
test_expect_success 'diff produces text' '
|
2008-10-26 12:42:25 +08:00
|
|
|
git diff HEAD^ HEAD >diff &&
|
|
|
|
find_diff <diff >actual &&
|
|
|
|
test_cmp expect.text actual
|
|
|
|
'
|
|
|
|
|
2013-05-10 23:10:10 +08:00
|
|
|
test_expect_success 'show commit produces text' '
|
|
|
|
git show HEAD >diff &&
|
|
|
|
find_diff <diff >actual &&
|
|
|
|
test_cmp expect.text actual
|
|
|
|
'
|
|
|
|
|
2008-10-26 12:42:25 +08:00
|
|
|
test_expect_success 'diff-tree produces binary' '
|
|
|
|
git diff-tree -p HEAD^ HEAD >diff &&
|
|
|
|
find_diff <diff >actual &&
|
|
|
|
test_cmp expect.binary actual
|
|
|
|
'
|
|
|
|
|
refactor userdiff textconv code
The original implementation of textconv put the conversion
into fill_mmfile. This was a bad idea for a number of
reasons:
- it made the semantics of fill_mmfile unclear. In some
cases, it was allocating data (if a text conversion
occurred), and in some cases not (if we could use the
data directly from the filespec). But the caller had
no idea which had happened, and so didn't know whether
the memory should be freed
- similarly, the caller had no idea if a text conversion
had occurred, and so didn't know whether the contents
should be treated as binary or not. This meant that we
incorrectly guessed that text-converted content was
binary and didn't actually show it (unless the user
overrode us with "diff.foo.binary = false", which then
created problems in plumbing where the text conversion
did _not_ occur)
- not all callers of fill_mmfile want the text contents. In
particular, we don't really want diffstat, whitespace
checks, patch id generation, etc, to look at the
converted contents.
This patch pulls the conversion code directly into
builtin_diff, so that we only see the conversion when
generating an actual patch. We also then know whether we are
doing a conversion, so we can check the binary-ness and free
the data from the mmfile appropriately (the previous version
leaked quite badly when text conversion was used)
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-10-26 12:44:53 +08:00
|
|
|
test_expect_success 'log produces text' '
|
2008-10-26 12:42:25 +08:00
|
|
|
git log -1 -p >log &&
|
|
|
|
find_diff <log >actual &&
|
|
|
|
test_cmp expect.text actual
|
|
|
|
'
|
|
|
|
|
2008-10-26 12:45:55 +08:00
|
|
|
test_expect_success 'format-patch produces binary' '
|
2008-10-26 12:42:25 +08:00
|
|
|
git format-patch --no-binary --stdout HEAD^ >patch &&
|
|
|
|
find_diff <patch >actual &&
|
|
|
|
test_cmp expect.binary actual
|
|
|
|
'
|
|
|
|
|
2008-10-26 12:50:02 +08:00
|
|
|
test_expect_success 'status -v produces text' '
|
|
|
|
git reset --soft HEAD^ &&
|
|
|
|
git status -v >diff &&
|
|
|
|
find_diff <diff >actual &&
|
|
|
|
test_cmp expect.text actual &&
|
|
|
|
git reset --soft HEAD@{1}
|
|
|
|
'
|
|
|
|
|
2013-05-10 23:10:10 +08:00
|
|
|
test_expect_success 'show blob produces binary' '
|
|
|
|
git show HEAD:file >actual &&
|
|
|
|
printf "\\0\\n\\01\\n" >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2013-05-10 23:10:12 +08:00
|
|
|
test_expect_success 'show --textconv blob produces text' '
|
2013-05-10 23:10:10 +08:00
|
|
|
git show --textconv HEAD:file >actual &&
|
|
|
|
printf "0\\n1\\n" >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2013-05-10 23:10:12 +08:00
|
|
|
test_expect_success 'show --no-textconv blob produces binary' '
|
|
|
|
git show --no-textconv HEAD:file >actual &&
|
2013-05-10 23:10:10 +08:00
|
|
|
printf "\\0\\n\\01\\n" >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
diff_grep: use textconv buffers for add/deleted files
If you use "-G" to grep a diff, we will apply a configured
textconv filter to the data before generating the diff.
However, if the diff is an addition or deletion, we do not
bother running the diff at all, and just look for the token
in the added (or removed) content. This works because we
know that the diff must contain every line of content.
However, while we used the textconv-derived buffers in the
regular diff, we accidentally passed the original unmodified
buffers to regexec when checking the added or removed
content. This could lead to an incorrect answer.
Worse, in some cases we might have a textconv buffer but no
original buffer (e.g., if we pulled the textconv data from
cache, or if we reused a working tree file when generating
it). In that case, we could actually feed NULL to regexec
and segfault.
Reported-by: Peter Oberndorfer <kumbayo84@arcor.de>
Signed-off-by: Jeff King <peff@peff.net>
2012-10-28 19:40:00 +08:00
|
|
|
test_expect_success 'grep-diff (-G) operates on textconv data (add)' '
|
|
|
|
echo one >expect &&
|
|
|
|
git log --root --format=%s -G0 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'grep-diff (-G) operates on textconv data (modification)' '
|
|
|
|
echo two >expect &&
|
|
|
|
git log --root --format=%s -G1 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2012-10-28 20:27:12 +08:00
|
|
|
test_expect_success 'pickaxe (-S) operates on textconv data (add)' '
|
|
|
|
echo one >expect &&
|
|
|
|
git log --root --format=%s -S0 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pickaxe (-S) operates on textconv data (modification)' '
|
|
|
|
echo two >expect &&
|
|
|
|
git log --root --format=%s -S1 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2008-10-26 12:42:25 +08:00
|
|
|
cat >expect.stat <<'EOF'
|
2012-05-01 04:38:58 +08:00
|
|
|
file | Bin 2 -> 4 bytes
|
2012-02-01 20:55:07 +08:00
|
|
|
1 file changed, 0 insertions(+), 0 deletions(-)
|
2008-10-26 12:42:25 +08:00
|
|
|
EOF
|
refactor userdiff textconv code
The original implementation of textconv put the conversion
into fill_mmfile. This was a bad idea for a number of
reasons:
- it made the semantics of fill_mmfile unclear. In some
cases, it was allocating data (if a text conversion
occurred), and in some cases not (if we could use the
data directly from the filespec). But the caller had
no idea which had happened, and so didn't know whether
the memory should be freed
- similarly, the caller had no idea if a text conversion
had occurred, and so didn't know whether the contents
should be treated as binary or not. This meant that we
incorrectly guessed that text-converted content was
binary and didn't actually show it (unless the user
overrode us with "diff.foo.binary = false", which then
created problems in plumbing where the text conversion
did _not_ occur)
- not all callers of fill_mmfile want the text contents. In
particular, we don't really want diffstat, whitespace
checks, patch id generation, etc, to look at the
converted contents.
This patch pulls the conversion code directly into
builtin_diff, so that we only see the conversion when
generating an actual patch. We also then know whether we are
doing a conversion, so we can check the binary-ness and free
the data from the mmfile appropriately (the previous version
leaked quite badly when text conversion was used)
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-10-26 12:44:53 +08:00
|
|
|
test_expect_success 'diffstat does not run textconv' '
|
2008-10-26 12:42:25 +08:00
|
|
|
echo file diff=fail >.gitattributes &&
|
|
|
|
git diff --stat HEAD^ HEAD >actual &&
|
2021-02-11 09:53:53 +08:00
|
|
|
test_cmp expect.stat actual &&
|
2012-03-13 13:05:54 +08:00
|
|
|
|
|
|
|
head -n1 <expect.stat >expect.line1 &&
|
|
|
|
head -n1 <actual >actual.line1 &&
|
|
|
|
test_cmp expect.line1 actual.line1
|
2008-10-26 12:42:25 +08:00
|
|
|
'
|
|
|
|
# restore working setup
|
|
|
|
echo file diff=foo >.gitattributes
|
|
|
|
|
2018-05-21 10:01:41 +08:00
|
|
|
symlink=$(git rev-parse --short $(printf frotz | git hash-object --stdin))
|
|
|
|
cat >expect.typechange <<EOF
|
2008-10-26 12:42:25 +08:00
|
|
|
--- a/file
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1,2 +0,0 @@
|
|
|
|
-0
|
|
|
|
-1
|
|
|
|
diff --git a/file b/file
|
|
|
|
new file mode 120000
|
2018-05-21 10:01:41 +08:00
|
|
|
index 0000000..$symlink
|
2008-10-26 12:42:25 +08:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/file
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+frotz
|
|
|
|
\ No newline at end of file
|
|
|
|
EOF
|
2013-06-08 04:53:28 +08:00
|
|
|
|
2008-10-26 12:46:21 +08:00
|
|
|
test_expect_success 'textconv does not act on symlinks' '
|
2013-06-08 04:53:28 +08:00
|
|
|
rm -f file &&
|
|
|
|
test_ln_s_add frotz file &&
|
2008-10-26 12:42:25 +08:00
|
|
|
git commit -m typechange &&
|
|
|
|
git show >diff &&
|
|
|
|
find_diff <diff >actual &&
|
|
|
|
test_cmp expect.typechange actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|