mirror of
https://github.com/git/git.git
synced 2024-11-25 10:54:00 +08:00
d9bae1a178
Running a textconv filter can take a long time. It's particularly bad for a large file which needs to be spooled to disk, but even for small files, the fork+exec overhead can add up for something like "git log -p". This patch uses the notes-cache mechanism to keep a fast cache of textconv output. Caches are stored in refs/notes/textconv/$x, where $x is the userdiff driver defined in gitattributes. Caching is enabled only if diff.$x.cachetextconv is true. In my test repo, on a commit with 45 jpg and avi files changed and a textconv to show their exif tags: [before] $ time git show >/dev/null real 0m13.724s user 0m12.057s sys 0m1.624s [after, first run] $ git config diff.mfo.cachetextconv true $ time git show >/dev/null real 0m14.252s user 0m12.197s sys 0m1.800s [after, subsequent runs] $ time git show >/dev/null real 0m0.352s user 0m0.148s sys 0m0.200s So for a slight (3.8%) cost on the first run, we achieve an almost 40x speed up on subsequent runs. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
110 lines
2.3 KiB
Bash
Executable File
110 lines
2.3 KiB
Bash
Executable File
#!/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 &&
|
|
echo foo content 2 >foo.bin &&
|
|
echo bar content 2 >bar.bin &&
|
|
git commit -a -m two &&
|
|
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
|
|
index fcf9166..28283d5 100644
|
|
--- a/bar.bin
|
|
+++ b/bar.bin
|
|
@@ -1 +1 @@
|
|
-converted: bar content 1
|
|
+converted: bar content 2
|
|
diff --git a/foo.bin b/foo.bin
|
|
index d5b9fe3..1345db2 100644
|
|
--- 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
|
|
index fcf9166..28283d5 100644
|
|
--- 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
|
|
index d5b9fe3..1345db2 100644
|
|
--- 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
|
|
index fcf9166..28283d5 100644
|
|
--- 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
|
|
index d5b9fe3..1345db2 100644
|
|
--- 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
|
|
'
|
|
|
|
test_done
|