fetch-pack: eliminate spurious error messages
[gitweb.git] / perl / Git / SVN.pm
index fc1ac07136af343ba2a373163870b195cea080d4..acb25394f433bc4043f835be4944b13785d46356 100644 (file)
@@ -23,7 +23,14 @@ package Git::SVN;
     command_output_pipe
     command_close_pipe
 );
-use Git::SVN::Utils qw(fatal can_compress);
+use Git::SVN::Utils qw(
+       fatal
+       can_compress
+       join_paths
+       canonicalize_path
+       canonicalize_url
+       add_path_to_url
+);
 
 my $can_use_yaml;
 BEGIN {
@@ -195,9 +202,9 @@ sub read_all_remotes {
                } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
                        $r->{$1}->{svm} = {};
                } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
-                       $r->{$1}->{url} = $2;
+                       $r->{$1}->{url} = canonicalize_url($2);
                } elsif (m!^(.+)\.pushurl=\s*(.*)\s*$!) {
-                       $r->{$1}->{pushurl} = $2;
+                       $r->{$1}->{pushurl} = canonicalize_url($2);
                } elsif (m!^(.+)\.ignore-refs=\s*(.*)\s*$!) {
                        $r->{$1}->{ignore_refs_regex} = $2;
                } elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) {
@@ -290,7 +297,7 @@ sub find_existing_remote {
 
 sub init_remote_config {
        my ($self, $url, $no_write) = @_;
-       $url =~ s!/+$!!; # strip trailing slash
+       $url = canonicalize_url($url);
        my $r = read_all_remotes();
        my $existing = find_existing_remote($url, $r);
        if ($existing) {
@@ -316,9 +323,7 @@ sub init_remote_config {
                        }
                        my $old_path = $self->path;
                        $url =~ s!^\Q$min_url\E(/|$)!!;
-                       if (length $old_path) {
-                               $url .= "/$old_path";
-                       }
+                       $url = join_paths($url, $old_path);
                        $self->path($url);
                        $url = $min_url;
                }
@@ -357,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;
@@ -395,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);
@@ -448,7 +460,6 @@ sub new {
        }
        {
                my $path = $self->path;
-               $path =~ s{/+}{/}g;
                $path =~ s{\A/}{};
                $path =~ s{/\z}{};
                $self->path($path);
@@ -560,8 +571,7 @@ sub _set_svm_vars {
                # username is of no interest
                $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
 
-               my $replace = $ra->url;
-               $replace .= "/$path" if length $path;
+               my $replace = add_path_to_url($ra->url, $path);
 
                my $section = "svn-remote.$self->{repo_id}";
                tmp_config("$section.svm-source", $src);
@@ -578,7 +588,7 @@ sub _set_svm_vars {
        my $path = $self->path;
        my %tried;
        while (length $path) {
-               my $try = $self->url . "/$path";
+               my $try = add_path_to_url($self->url, $path);
                unless ($tried{$try}) {
                        return $ra if $self->read_svm_props($ra, $path, $r);
                        $tried{$try} = 1;
@@ -587,7 +597,7 @@ sub _set_svm_vars {
        }
        die "Path: '$path' should be ''\n" if $path ne '';
        return $ra if $self->read_svm_props($ra, $path, $r);
-       $tried{$self->url."/$path"} = 1;
+       $tried{ add_path_to_url($self->url, $path) } = 1;
 
        if ($ra->{repos_root} eq $self->url) {
                die @err, (map { "  $_\n" } keys %tried), "\n";
@@ -599,7 +609,7 @@ sub _set_svm_vars {
        $path = $ra->{svn_path};
        $ra = Git::SVN::Ra->new($ra->{repos_root});
        while (length $path) {
-               my $try = $ra->url ."/$path";
+               my $try = add_path_to_url($ra->url, $path);
                unless ($tried{$try}) {
                        $ok = $self->read_svm_props($ra, $path, $r);
                        last if $ok;
@@ -609,7 +619,7 @@ sub _set_svm_vars {
        }
        die "Path: '$path' should be ''\n" if $path ne '';
        $ok ||= $self->read_svm_props($ra, $path, $r);
-       $tried{$ra->url ."/$path"} = 1;
+       $tried{ add_path_to_url($ra->url, $path) } = 1;
        if (!$ok) {
                die @err, (map { "  $_\n" } keys %tried), "\n";
        }
@@ -929,20 +939,19 @@ sub rewrite_uuid {
 
 sub metadata_url {
        my ($self) = @_;
-       ($self->rewrite_root || $self->url) .
-          (length $self->path ? '/' . $self->path : '');
+       my $url = $self->rewrite_root || $self->url;
+       return canonicalize_url( add_path_to_url( $url, $self->path ) );
 }
 
 sub full_url {
        my ($self) = @_;
-       $self->url . (length $self->path ? '/' . $self->path : '');
+       return canonicalize_url( add_path_to_url( $self->url, $self->path ) );
 }
 
 sub full_pushurl {
        my ($self) = @_;
        if ($self->{pushurl}) {
-               return $self->{pushurl} . (length $self->path ? '/' .
-                      $self->path : '');
+               return canonicalize_url( add_path_to_url( $self->{pushurl}, $self->path ) );
        } else {
                return $self->full_url;
        }
@@ -1110,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 = $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;
@@ -1439,12 +1448,11 @@ sub find_extra_svk_parents {
        for my $ticket ( @tickets ) {
                my ($uuid, $path, $rev) = split /:/, $ticket;
                if ( $uuid eq $self->ra_uuid ) {
-                       my $url = $self->url;
-                       my $repos_root = $url;
+                       my $repos_root = $self->url;
                        my $branch_from = $path;
                        $branch_from =~ s{^/}{};
-                       my $gs = $self->other_gs($repos_root."/".$branch_from,
-                                                $url,
+                       my $gs = $self->other_gs(add_path_to_url( $repos_root, $branch_from ),
+                                                $repos_root,
                                                 $branch_from,
                                                 $rev,
                                                 $self->{ref_id});
@@ -1626,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';
 }
 
@@ -1867,8 +1893,9 @@ sub make_log_entry {
                $email ||= "$author\@$uuid";
                $commit_email ||= "$author\@$uuid";
        } elsif ($self->use_svnsync_props) {
-               my $full_url = $self->svnsync->{url};
-               $full_url .= "/".$self->path if length $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";
@@ -2117,8 +2144,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";
@@ -2302,7 +2334,7 @@ sub path {
 
        if (@_) {
                my $path = shift;
-               $self->{path} = $path;
+               $self->{path} = canonicalize_path($path);
                return;
        }
 
@@ -2314,7 +2346,7 @@ sub url {
 
        if (@_) {
                my $url = shift;
-               $self->{url} = $url;
+               $self->{url} = canonicalize_url($url);
                return;
        }