about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorGavin Lambert <github@mirality.co.nz>2016-10-25 17:30:11 +0200
committerEric Wong <e@80x24.org>2016-10-27 20:17:36 +0000
commita2c761ce5b7a5fd8b505b036f3509a9e6617dee8 (patch)
tree4f72fdf95256d708ca983079d4ccafffa3a104c4
parent2cc2e70264e0fcba04f9ef791d144bbc8b501206 (diff)
downloadgit-svn-svn-cache.tar.gz
Reusing cached data speeds up git-svn by quite a fair bit. However, if
the YAML module is unavailable, the caches are written to disk in an
architecture-dependent manner. That leads to problems when upgrading,
say, from 32-bit to 64-bit Git for Windows.

Let's just try to read those caches back if we detect the absence of the
YAML module and the presence of the file, and delete the file if it
could not be read back correctly.

Note that the only way to catch the error when the memoized cache could
not be read back is to put the call inside an `eval { ... }` block
because it would die otherwise; the `eval` block should also return `1`
in case of success explicitly since the function reading back the cached
data does not return an appropriate value to test for success.

This fixes https://github.com/git-for-windows/git/issues/233.

[ew: import "retrieve" explictly, check unlink result]

Signed-off-by: Gavin Lambert <github@mirality.co.nz>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Eric Wong <e@80x24.org>
-rw-r--r--perl/Git/SVN.pm12
1 files changed, 11 insertions, 1 deletions
diff --git a/perl/Git/SVN.pm b/perl/Git/SVN.pm
index 018beb85a0..b3c146011a 100644
--- a/perl/Git/SVN.pm
+++ b/perl/Git/SVN.pm
@@ -1658,7 +1658,17 @@ sub tie_for_persistent_memoization {
         if ($memo_backend > 0) {
                 tie %$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
         } else {
-                tie %$hash => 'Memoize::Storable', "$path.db", 'nstore';
+                # first verify that any existing file can actually be loaded
+                # (it may have been saved by an incompatible version)
+                my $db = "$path.db";
+                if (-e $db) {
+                        use Storable qw(retrieve);
+
+                        if (!eval { retrieve($db); 1 }) {
+                                unlink $db or die "unlink $db failed: $!";
+                        }
+                }
+                tie %$hash => 'Memoize::Storable', $db, 'nstore';
         }
 }