2010-04-02 04:12:15 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='test textconv caching'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
cat >helper <<'EOF'
|
|
|
|
#!/bin/sh
|
|
|
|
sed 's/^/converted: /' "$@" >helper.out
|
|
|
|
cat helper.out
|
|
|
|
EOF
|
|
|
|
chmod +x helper
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
echo foo content 1 >foo.bin &&
|
|
|
|
echo bar content 1 >bar.bin &&
|
|
|
|
git add . &&
|
|
|
|
git commit -m one &&
|
2018-05-21 05:01:44 +03:00
|
|
|
foo1=$(git rev-parse --short HEAD:foo.bin) &&
|
|
|
|
bar1=$(git rev-parse --short HEAD:bar.bin) &&
|
2010-04-02 04:12:15 +04:00
|
|
|
echo foo content 2 >foo.bin &&
|
|
|
|
echo bar content 2 >bar.bin &&
|
|
|
|
git commit -a -m two &&
|
2018-05-21 05:01:44 +03:00
|
|
|
foo2=$(git rev-parse --short HEAD:foo.bin) &&
|
|
|
|
bar2=$(git rev-parse --short HEAD:bar.bin) &&
|
2010-04-02 04:12:15 +04:00
|
|
|
echo "*.bin diff=magic" >.gitattributes &&
|
|
|
|
git config diff.magic.textconv ./helper &&
|
|
|
|
git config diff.magic.cachetextconv true
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >expect <<EOF
|
|
|
|
diff --git a/bar.bin b/bar.bin
|
2018-05-21 05:01:44 +03:00
|
|
|
index $bar1..$bar2 100644
|
2010-04-02 04:12:15 +04:00
|
|
|
--- a/bar.bin
|
|
|
|
+++ b/bar.bin
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-converted: bar content 1
|
|
|
|
+converted: bar content 2
|
|
|
|
diff --git a/foo.bin b/foo.bin
|
2018-05-21 05:01:44 +03:00
|
|
|
index $foo1..$foo2 100644
|
2010-04-02 04:12:15 +04:00
|
|
|
--- a/foo.bin
|
|
|
|
+++ b/foo.bin
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-converted: foo content 1
|
|
|
|
+converted: foo content 2
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'first textconv works' '
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'cached textconv produces same output' '
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'cached textconv does not run helper' '
|
|
|
|
rm -f helper.out &&
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
! test -r helper.out
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >expect <<EOF
|
|
|
|
diff --git a/bar.bin b/bar.bin
|
2018-05-21 05:01:44 +03:00
|
|
|
index $bar1..$bar2 100644
|
2010-04-02 04:12:15 +04:00
|
|
|
--- a/bar.bin
|
|
|
|
+++ b/bar.bin
|
|
|
|
@@ -1,2 +1,2 @@
|
|
|
|
converted: other
|
|
|
|
-converted: bar content 1
|
|
|
|
+converted: bar content 2
|
|
|
|
diff --git a/foo.bin b/foo.bin
|
2018-05-21 05:01:44 +03:00
|
|
|
index $foo1..$foo2 100644
|
2010-04-02 04:12:15 +04:00
|
|
|
--- a/foo.bin
|
|
|
|
+++ b/foo.bin
|
|
|
|
@@ -1,2 +1,2 @@
|
|
|
|
converted: other
|
|
|
|
-converted: foo content 1
|
|
|
|
+converted: foo content 2
|
|
|
|
EOF
|
|
|
|
test_expect_success 'changing textconv invalidates cache' '
|
|
|
|
echo other >other &&
|
|
|
|
git config diff.magic.textconv "./helper other" &&
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >expect <<EOF
|
|
|
|
diff --git a/bar.bin b/bar.bin
|
2018-05-21 05:01:44 +03:00
|
|
|
index $bar1..$bar2 100644
|
2010-04-02 04:12:15 +04:00
|
|
|
--- a/bar.bin
|
|
|
|
+++ b/bar.bin
|
|
|
|
@@ -1,2 +1,2 @@
|
|
|
|
converted: other
|
|
|
|
-converted: bar content 1
|
|
|
|
+converted: bar content 2
|
|
|
|
diff --git a/foo.bin b/foo.bin
|
2018-05-21 05:01:44 +03:00
|
|
|
index $foo1..$foo2 100644
|
2010-04-02 04:12:15 +04:00
|
|
|
--- a/foo.bin
|
|
|
|
+++ b/foo.bin
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-converted: foo content 1
|
|
|
|
+converted: foo content 2
|
|
|
|
EOF
|
|
|
|
test_expect_success 'switching diff driver produces correct results' '
|
|
|
|
git config diff.moremagic.textconv ./helper &&
|
|
|
|
echo foo.bin diff=moremagic >>.gitattributes &&
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
logmsg_reencode: lazily load missing commit buffers
Usually a commit that makes it to logmsg_reencode will have
been parsed, and the commit->buffer struct member will be
valid. However, some code paths will free commit buffers
after having used them (for example, the log traversal
machinery will do so to keep memory usage down).
Most of the time this is fine; log should only show a commit
once, and then exits. However, there are some code paths
where this does not work. At least two are known:
1. A commit may be shown as part of a regular ref, and
then it may be shown again as part of a submodule diff
(e.g., if a repo contains refs to both the superproject
and subproject).
2. A notes-cache commit may be shown during "log --all",
and then later used to access a textconv cache during a
diff.
Lazily loading in logmsg_reencode does not necessarily catch
all such cases, but it should catch most of them. Users of
the commit buffer tend to be either parsing for structure
(in which they will call parse_commit, and either we will
already have parsed, or we will load commit->buffer lazily
there), or outputting (either to the user, or fetching a
part of the commit message via format_commit_message). In
the latter case, we should always be using logmsg_reencode
anyway (and typically we do so via the pretty-print
machinery).
If there are any cases that this misses, we can fix them up
to use logmsg_reencode (or handle them on a case-by-case
basis if that is inappropriate).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-26 13:44:28 +04:00
|
|
|
# The point here is to test that we can log the notes cache and still use it to
|
|
|
|
# produce a diff later (older versions of git would segfault on this). It's
|
|
|
|
# much more likely to come up in the real world with "log --all -p", but using
|
|
|
|
# --no-walk lets us reliably reproduce the order of traversal.
|
|
|
|
test_expect_success 'log notes cache and still use cache for -p' '
|
|
|
|
git log --no-walk -p refs/notes/textconv/magic HEAD
|
|
|
|
'
|
|
|
|
|
2010-04-02 04:12:15 +04:00
|
|
|
test_done
|