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 <normalperson@yhbt.net> Signed-off-by: Andrew Myrick <amyrick@apple.com>
Andrew Myrick committed
Jan 30, 2010 at 03:14 UTC
8bff7c5383ed833bd1df9c8d85c00a27af3e5b02
1 file changed
+36
-4
git-svn.perl
+36
-4
@@ -1656,6 +1656,7 @@ use File::Path qw/mkpath/;
1656
use File::Copy qw/copy/;
1657
use IPC::Open3;
1658
use Memoize; # core since 5.8.0, Jul 2002
1659
+use Memoize::Storable;
1660
1661
my ($_gc_nr, $_gc_period);
1662
@@ -3116,10 +3117,39 @@ sub has_no_changes {
3117
command_oneline("rev-parse", "$commit~1^{tree}"));
3118
}
3119
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
+ }
3153
}
3154
3155
sub parents_exclude {
@@ -3163,6 +3193,8 @@ sub find_extra_svn_parents {
3193
my ($self, $ed, $mergeinfo, $parents) = @_;
3194
# aha! svk:merge property changed...
3195
3196
+ memoize_svn_mergeinfo_functions();
3197
+
3198
# We first search for merged tips which are not in our
3199
# history. Then, we figure out which git revisions are in
3200
# that tip, but not this revision. If all of those revisions