Code

fill_textconv(): Don't get/put cache if sha1 is not valid
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Sat, 18 Dec 2010 14:54:12 +0000 (17:54 +0300)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Dec 2010 02:41:32 +0000 (18:41 -0800)
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>
diff.c
t/t8006-blame-textconv.sh

diff --git a/diff.c b/diff.c
index 8256f313e4a680308a7959bdd6544f5bd461846c..fa3b29d92e39cd35b30c1572acd06e2ba2708edd 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4388,7 +4388,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
                return df->size;
        }
 
-       if (driver->textconv_cache) {
+       if (driver->textconv_cache && df->sha1_valid) {
                *outbuf = notes_cache_get(driver->textconv_cache, df->sha1,
                                          &size);
                if (*outbuf)
@@ -4399,7 +4399,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
        if (!*outbuf)
                die("unable to read files to diff");
 
-       if (driver->textconv_cache) {
+       if (driver->textconv_cache && df->sha1_valid) {
                /* ignore errors, as we might be in a readonly repository */
                notes_cache_put(driver->textconv_cache, df->sha1, *outbuf,
                                size);
index fe9054184257d9c01f9ee0583a09c83bd35c0d50..ea64cd8d0f02a3a08dca7742a29331c85e7da384 100755 (executable)
@@ -81,8 +81,7 @@ cat >expected_one <<EOF
 (Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2
 EOF
 
-# one.bin is blamed as 'Not Committed yet'
-test_expect_failure 'blame --textconv works with textconvcache' '
+test_expect_success 'blame --textconv works with textconvcache' '
        git blame --textconv two.bin >blame &&
        find_blame <blame >result &&
        test_cmp expected result &&