Skip to content

Commit 9ec09b0

Browse files
navytuxgitster
authored andcommitted
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 <[email protected]> Cc: Clément Poulain <[email protected]> Cc: Diane Gasselin <[email protected]> Cc: Jeff King <[email protected]> Signed-off-by: Kirill Smelkov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b1b14ec commit 9ec09b0

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,7 +4388,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
43884388
return df->size;
43894389
}
43904390

4391-
if (driver->textconv_cache) {
4391+
if (driver->textconv_cache && df->sha1_valid) {
43924392
*outbuf = notes_cache_get(driver->textconv_cache, df->sha1,
43934393
&size);
43944394
if (*outbuf)
@@ -4399,7 +4399,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
43994399
if (!*outbuf)
44004400
die("unable to read files to diff");
44014401

4402-
if (driver->textconv_cache) {
4402+
if (driver->textconv_cache && df->sha1_valid) {
44034403
/* ignore errors, as we might be in a readonly repository */
44044404
notes_cache_put(driver->textconv_cache, df->sha1, *outbuf,
44054405
size);

t/t8006-blame-textconv.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ cat >expected_one <<EOF
8181
(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
8282
EOF
8383

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' '
8685
git blame --textconv two.bin >blame &&
8786
find_blame <blame >result &&
8887
test_cmp expected result &&

0 commit comments

Comments
 (0)