Skip to content

Commit 8bff7c5

Browse files
andrewmyrickEric Wong
authored andcommitted
git-svn: persistent memoization
Make memoization of the svn:mergeinfo processing functions persistent with Memoize::Storable so that the memoization tables don't need to be regenerated every time the user runs git-svn fetch. The Memoize::Storable hashes are stored in ENV{GIT_DIR}/svn/.caches. [ew: changed caches path to avoid conflicts with old repos] [ew: File::Path::{make_path => mkpath} for compatibility] [ew: line-wrapped at 80 chars] Acked-by: Eric Wong <[email protected]> Signed-off-by: Andrew Myrick <[email protected]>
1 parent 4d0cc22 commit 8bff7c5

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

git-svn.perl

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ package Git::SVN;
16561656
use File::Copy qw/copy/;
16571657
use IPC::Open3;
16581658
use Memoize; # core since 5.8.0, Jul 2002
1659+
use Memoize::Storable;
16591660

16601661
my ($_gc_nr, $_gc_period);
16611662

@@ -3116,10 +3117,39 @@ sub has_no_changes {
31163117
command_oneline("rev-parse", "$commit~1^{tree}"));
31173118
}
31183119

3119-
BEGIN {
3120-
memoize 'lookup_svn_merge';
3121-
memoize 'check_cherry_pick';
3122-
memoize 'has_no_changes';
3120+
# The GIT_DIR environment variable is not always set until after the command
3121+
# line arguments are processed, so we can't memoize in a BEGIN block.
3122+
{
3123+
my $memoized = 0;
3124+
3125+
sub memoize_svn_mergeinfo_functions {
3126+
return if $memoized;
3127+
$memoized = 1;
3128+
3129+
my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
3130+
mkpath([$cache_path]) unless -d $cache_path;
3131+
3132+
tie my %lookup_svn_merge_cache => 'Memoize::Storable',
3133+
"$cache_path/lookup_svn_merge.db", 'nstore';
3134+
memoize 'lookup_svn_merge',
3135+
SCALAR_CACHE => 'FAULT',
3136+
LIST_CACHE => ['HASH' => \%lookup_svn_merge_cache],
3137+
;
3138+
3139+
tie my %check_cherry_pick_cache => 'Memoize::Storable',
3140+
"$cache_path/check_cherry_pick.db", 'nstore';
3141+
memoize 'check_cherry_pick',
3142+
SCALAR_CACHE => 'FAULT',
3143+
LIST_CACHE => ['HASH' => \%check_cherry_pick_cache],
3144+
;
3145+
3146+
tie my %has_no_changes_cache => 'Memoize::Storable',
3147+
"$cache_path/has_no_changes.db", 'nstore';
3148+
memoize 'has_no_changes',
3149+
SCALAR_CACHE => ['HASH' => \%has_no_changes_cache],
3150+
LIST_CACHE => 'FAULT',
3151+
;
3152+
}
31233153
}
31243154

31253155
sub parents_exclude {
@@ -3163,6 +3193,8 @@ sub find_extra_svn_parents {
31633193
my ($self, $ed, $mergeinfo, $parents) = @_;
31643194
# aha! svk:merge property changed...
31653195

3196+
memoize_svn_mergeinfo_functions();
3197+
31663198
# We first search for merged tips which are not in our
31673199
# history. Then, we figure out which git revisions are in
31683200
# that tip, but not this revision. If all of those revisions

0 commit comments

Comments
 (0)