Re: git-svn: copes poorly with .git/svn dir from older perl
(please cc me on replies)
Hi perl group,
A quick Memoize::Storable question that came up in a git-svn bug.
GSR wrote[1]:
> Perl & Git were updated recently (lots of updates going on in Sid),
> and that seems to have caused a similar issue, end of import failed
> with:
>
> ---8<---
> Byte order is not compatible at ../../lib/Storable.pm (autosplit into ../../lib/auto/Storable/_retrieve.al) line 380, at /usr/share/perl/5.12.3/Memoize/Storable.pm line 21
>
> Could not unmemoize function `lookup_svn_merge', because it was not memoized to begin with at /usr/lib/git-core/git-svn line 3213
> END failed--call queue aborted at /usr/lib/git-core/git-svn line 40.
The relevant code from git-svn.perl looks roughly like so (see
/usr/lib/git-core/git-svn for the real thing). At memoize time:
return if $memoized;
$memoized = 1;
my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
mkpath([$cache_path]) unless -d $cache_path;
tie my %lookup_svn_merge_cache => 'Memoize::Storable',
"$cache_path/lookup_svn_merge.db", 'nstore';
memoize 'lookup_svn_merge',
SCALAR_CACHE => 'FAULT',
LIST_CACHE => ['HASH' => \%lookup_svn_merge_cache],
;
At unmemoize time:
return if not $memoized;
$memoized = 0;
Memoize::unmemoize 'lookup_svn_merge';
My question: I would like to remove the stale .git/svn/.caches
automatically when errors of this kind ("... is not compatible")
occur. The manual for Storable says:
By default, Storable will attempt to do the right thing, by
"croak()"ing if it encounters data that it cannot deserialize.
I do not want to set $Storable::interwork_56_64bit, but just to trap and
silence errors like this and generate a new cache. Is there some variant
on
eval {
tie ...;
memoize ...;
}
if ($@) {
die unless $@ =~ /is not compatible/;
print STDERR "$@: discarding cache\n";
rmtree([$cache_path]);
mkpath([$cache_path]);
... try again ...
}
that would work well?
Alternatively, is there some other simple serialization format (YAML?)
in core perl that might allow keeping the cache with less fuss? (An
answer like "don't ask me; ask on perl monks" would be fine, too. The
most interesting thread I could find in a quick search was [2].)
This subject is beyond my experience, hence I'm relying on your
advice. Thoughts welcome.
Regards,
Jonathan
[1] http://bugs.debian.org/587650
[2] http://perlmonks.org/?node_id=881140
Reply to: