Merge branch 'jk/maint-http-init-not-in-result-handler'
[gitweb.git] / perl / Git / SVN.pm
index ec5e826468e1c64d82bb4261c3f83dd17c96a486..59215fa86e2c2902ec97b12bea70736f9c7c02c6 100644 (file)
@@ -362,6 +362,8 @@ sub init_remote_config {
 sub find_by_url { # repos_root and, path are optional
        my ($class, $full_url, $repos_root, $path) = @_;
 
+       $full_url = canonicalize_url($full_url);
+
        return undef unless defined $full_url;
        remove_username($full_url);
        remove_username($repos_root) if defined $repos_root;
@@ -400,6 +402,11 @@ sub find_by_url { # repos_root and, path are optional
                        }
                        $p =~ s#^\Q$z\E(?:/|$)#$prefix# or next;
                }
+
+               # remote fetch paths are not URI escaped.  Decode ours
+               # so they match
+               $p = uri_decode($p);
+
                foreach my $f (keys %$fetch) {
                        next if $f ne $p;
                        return Git::SVN->new($fetch->{$f}, $repo_id, $f);
@@ -453,7 +460,6 @@ sub new {
        }
        {
                my $path = $self->path;
-               $path =~ s{/+}{/}g;
                $path =~ s{\A/}{};
                $path =~ s{/\z}{};
                $self->path($path);
@@ -934,18 +940,18 @@ sub rewrite_uuid {
 sub metadata_url {
        my ($self) = @_;
        my $url = $self->rewrite_root || $self->url;
-       return add_path_to_url( $url, $self->path );
+       return canonicalize_url( add_path_to_url( $url, $self->path ) );
 }
 
 sub full_url {
        my ($self) = @_;
-       return add_path_to_url( $self->url, $self->path );
+       return canonicalize_url( add_path_to_url( $self->url, $self->path ) );
 }
 
 sub full_pushurl {
        my ($self) = @_;
        if ($self->{pushurl}) {
-               return add_path_to_url( $self->{pushurl}, $self->path );
+               return canonicalize_url( add_path_to_url( $self->{pushurl}, $self->path ) );
        } else {
                return $self->full_url;
        }
@@ -1113,7 +1119,7 @@ sub find_parent_branch {
        my $r = $i->{copyfrom_rev};
        my $repos_root = $self->ra->{repos_root};
        my $url = $self->ra->url;
-       my $new_url = add_path_to_url( $url, $branch_from );
+       my $new_url = canonicalize_url( add_path_to_url( $url, $branch_from ) );
        print STDERR  "Found possible branch point: ",
                      "$new_url => ", $self->full_url, ", $r\n"
                      unless $::_q > 1;
@@ -1628,6 +1634,24 @@ sub tie_for_persistent_memoization {
                Memoize::unmemoize 'has_no_changes';
        }
 
+       sub clear_memoized_mergeinfo_caches {
+               die "Only call this method in non-memoized context" if ($memoized);
+
+               my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
+               return unless -d $cache_path;
+
+               for my $cache_file (("$cache_path/lookup_svn_merge",
+                                    "$cache_path/check_cherry_pick",
+                                    "$cache_path/has_no_changes")) {
+                       for my $suffix (qw(yaml db)) {
+                               my $file = "$cache_file.$suffix";
+                               next unless -e $file;
+                               unlink($file) or die "unlink($file) failed: $!\n";
+                       }
+               }
+       }
+
+
        Memoize::memoize 'Git::SVN::repos_root';
 }
 
@@ -1655,7 +1679,6 @@ sub parents_exclude {
                                if ( $commit eq $excluded ) {
                                        push @excluded, $commit;
                                        $found++;
-                                       last;
                                }
                                else {
                                        push @new, $commit;
@@ -1689,14 +1712,14 @@ sub find_extra_svn_parents {
        my @merge_tips;
        my $url = $self->url;
        my $uuid = $self->ra_uuid;
-       my %ranges;
+       my @all_ranges;
        for my $merge ( @merges ) {
                my ($tip_commit, @ranges) =
                        lookup_svn_merge( $uuid, $url, $merge );
                unless (!$tip_commit or
                                grep { $_ eq $tip_commit } @$parents ) {
                        push @merge_tips, $tip_commit;
-                       $ranges{$tip_commit} = \@ranges;
+                       push @all_ranges, @ranges;
                } else {
                        push @merge_tips, undef;
                }
@@ -1711,8 +1734,6 @@ sub find_extra_svn_parents {
                my $spec = shift @merges;
                next unless $merge_tip and $excluded{$merge_tip};
 
-               my $ranges = $ranges{$merge_tip};
-
                # check out 'new' tips
                my $merge_base;
                eval {
@@ -1734,7 +1755,7 @@ sub find_extra_svn_parents {
                my (@incomplete) = check_cherry_pick(
                        $merge_base, $merge_tip,
                        $parents,
-                       @$ranges,
+                       @all_ranges,
                       );
 
                if ( @incomplete ) {
@@ -1869,7 +1890,9 @@ sub make_log_entry {
                $email ||= "$author\@$uuid";
                $commit_email ||= "$author\@$uuid";
        } elsif ($self->use_svnsync_props) {
-               my $full_url = add_path_to_url( $self->svnsync->{url}, $self->path );
+               my $full_url = canonicalize_url(
+                       add_path_to_url( $self->svnsync->{url}, $self->path )
+               );
                remove_username($full_url);
                my $uuid = $self->svnsync->{uuid};
                $log_entry{metadata} = "$full_url\@$rev $uuid";
@@ -2118,8 +2141,13 @@ sub rev_map_set {
 
        sysopen(my $fh, $db_lock, O_RDWR | O_CREAT)
             or croak "Couldn't open $db_lock: $!\n";
-       $update_ref eq 'reset' ? _rev_map_reset($fh, $rev, $commit) :
-                                _rev_map_set($fh, $rev, $commit);
+       if ($update_ref eq 'reset') {
+               clear_memoized_mergeinfo_caches();
+               _rev_map_reset($fh, $rev, $commit);
+       } else {
+               _rev_map_set($fh, $rev, $commit);
+       }
+
        if ($sync) {
                $fh->flush or die "Couldn't flush $db_lock: $!\n";
                $fh->sync or die "Couldn't sync $db_lock: $!\n";
@@ -2303,11 +2331,11 @@ sub path {
 
        if (@_) {
                my $path = shift;
-               $self->{path} = canonicalize_path($path);
+               $self->{_path} = canonicalize_path($path);
                return;
        }
 
-       return $self->{path};
+       return $self->{_path};
 }
 
 sub url {