Merge branch 'mm/mediawiki-usability'
[gitweb.git] / git-svn.perl
index 24c0af2e3ae02c22e8be1869b06049058f668b60..6673d21f841c7f5a4806bc7785c5ae7755f9297b 100755 (executable)
@@ -367,9 +367,9 @@ package main;
 eval {
        Git::SVN::verify_remotes_sanity();
        $cmd{$cmd}->[0]->(@ARGV);
+       post_fetch_checkout();
 };
 fatal $@ if $@;
-post_fetch_checkout();
 exit 0;
 
 ####################### primary functions ######################
@@ -1598,8 +1598,8 @@ sub rebase_cmd {
 
 sub post_fetch_checkout {
        return if $_no_checkout;
+       return if verify_ref('HEAD^0');
        my $gs = $Git::SVN::_head or return;
-       return if verify_ref('refs/heads/master^0');
 
        # look for "trunk" ref if it exists
        my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}};
@@ -1612,9 +1612,8 @@ sub post_fetch_checkout {
                }
        }
 
-       my $valid_head = verify_ref('HEAD^0');
-       command_noisy(qw(update-ref refs/heads/master), $gs->refname);
-       return if ($valid_head || !verify_ref('HEAD^0'));
+       command_noisy(qw(update-ref HEAD), $gs->refname);
+       return unless verify_ref('HEAD^0');
 
        return if $ENV{GIT_DIR} !~ m#^(?:.*/)?\.git$#;
        my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index";
@@ -2055,6 +2054,10 @@ package Git::SVN;
 use Memoize;  # core since 5.8.0, Jul 2002
 use Memoize::Storable;
 use POSIX qw(:signal_h);
+my $can_use_yaml;
+BEGIN {
+       $can_use_yaml = eval { require Git::SVN::Memoize::YAML; 1};
+}
 
 my ($_gc_nr, $_gc_period);
 
@@ -3577,6 +3580,17 @@ sub has_no_changes {
                command_oneline("rev-parse", "$commit~1^{tree}"));
 }
 
+sub tie_for_persistent_memoization {
+       my $hash = shift;
+       my $path = shift;
+
+       if ($can_use_yaml) {
+               tie %$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
+       } else {
+               tie %$hash => 'Memoize::Storable', "$path.db", 'nstore';
+       }
+}
+
 # The GIT_DIR environment variable is not always set until after the command
 # line arguments are processed, so we can't memoize in a BEGIN block.
 {
@@ -3589,22 +3603,26 @@ sub has_no_changes {
                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';
+               my %lookup_svn_merge_cache;
+               my %check_cherry_pick_cache;
+               my %has_no_changes_cache;
+
+               tie_for_persistent_memoization(\%lookup_svn_merge_cache,
+                   "$cache_path/lookup_svn_merge");
                memoize 'lookup_svn_merge',
                        SCALAR_CACHE => 'FAULT',
                        LIST_CACHE => ['HASH' => \%lookup_svn_merge_cache],
                ;
 
-               tie my %check_cherry_pick_cache => 'Memoize::Storable',
-                   "$cache_path/check_cherry_pick.db", 'nstore';
+               tie_for_persistent_memoization(\%check_cherry_pick_cache,
+                   "$cache_path/check_cherry_pick");
                memoize 'check_cherry_pick',
                        SCALAR_CACHE => 'FAULT',
                        LIST_CACHE => ['HASH' => \%check_cherry_pick_cache],
                ;
 
-               tie my %has_no_changes_cache => 'Memoize::Storable',
-                   "$cache_path/has_no_changes.db", 'nstore';
+               tie_for_persistent_memoization(\%has_no_changes_cache,
+                   "$cache_path/has_no_changes");
                memoize 'has_no_changes',
                        SCALAR_CACHE => ['HASH' => \%has_no_changes_cache],
                        LIST_CACHE => 'FAULT',