git-svn: add join_paths() to safely concatenate paths

Otherwise you might wind up with things like...

    my $path1 = undef;
    my $path2 = 'foo';
    my $path = $path1 . '/' . $path2;

creating '/foo'.  Or this...

    my $path1 = 'foo/';
    my $path2 = 'bar';
    my $path = $path1 . '/' . $path2;

creating 'foo//bar'.

Could have used File::Spec, but I'm shying away from it due to SVN
1.7's pickiness about paths.  Felt it would be better to have our own
we can control completely.

[ew: commit title]

Signed-off-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
Michael G. Schwern
2012-07-28 02:38:29 -07:00
committed by Eric Wong
parent 280ad88aa0
commit ca475a61f8
4 changed files with 72 additions and 5 deletions

View File

@ -23,7 +23,11 @@ use Git qw(
command_output_pipe
command_close_pipe
);
use Git::SVN::Utils qw(fatal can_compress);
use Git::SVN::Utils qw(
fatal
can_compress
join_paths
);
my $can_use_yaml;
BEGIN {
@ -316,9 +320,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;
}