fill_textconv(): Don't get/put cache if sha1 is not valid
When blaming files in the working tree, the filespec is marked with !sha1_valid, as we have not given the contents an object name yet. The function to cache textconv results (keyed on the object name), however, didn't check this condition, and ended up on storing the cached result under a random object name. Cc: Axel Bonnet <axel.bonnet@ensimag.imag.fr> Cc: Clément Poulain <clement.poulain@ensimag.imag.fr> Cc: Diane Gasselin <diane.gasselin@ensimag.imag.fr> Cc: Jeff King <peff@peff.net> Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kirill Smelkov committed
Dec 18, 2010 at 17:54 UTC
9ec09b0495f5e672223025f5e681371034da2538
2 files changed
+3
-4
diff.c
+2
-2
@@ -4388,7 +4388,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
4388
return df->size;
4389
}
4390
4391
- if (driver->textconv_cache) {
4391
+ if (driver->textconv_cache && df->sha1_valid) {
4392
*outbuf = notes_cache_get(driver->textconv_cache, df->sha1,
4393
&size);
4394
if (*outbuf)
@@ -4399,7 +4399,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
4399
if (!*outbuf)
4400
die("unable to read files to diff");
4401
4402
- if (driver->textconv_cache) {
4402
+ if (driver->textconv_cache && df->sha1_valid) {
4403
/* ignore errors, as we might be in a readonly repository */
4404
notes_cache_put(driver->textconv_cache, df->sha1, *outbuf,
4405
size);
t/t8006-blame-textconv.sh
+1
-2
@@ -81,8 +81,7 @@ cat >expected_one <<EOF
81
(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
82
EOF
83
84
-# one.bin is blamed as 'Not Committed yet'
85
-test_expect_failure 'blame --textconv works with textconvcache' '
84
+test_expect_success 'blame --textconv works with textconvcache' '
85
git blame --textconv two.bin >blame &&
86
find_blame <blame >result &&
87
test_cmp expected result &&