1
From f39fef0a43e4c755837593229a39828e45611e77 Mon Sep 17 00:00:00 2001
2
From: "Michael G. Schwern" <schwern@pobox.com>
3
Date: Sat, 28 Jul 2012 02:38:29 -0700
4
Subject: git-svn: add join_paths() to safely concatenate paths
6
Otherwise you might wind up with things like...
10
my $path = $path1 . '/' . $path2;
12
creating '/foo'. Or this...
16
my $path = $path1 . '/' . $path2;
20
Could have used File::Spec, but I'm shying away from it due to SVN
21
1.7's pickiness about paths. Felt it would be better to have our own
22
we can control completely.
25
[jn: drop unused unit test]
27
Signed-off-by: Eric Wong <normalperson@yhbt.net>
28
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
30
git-svn.perl | 38 ++++++++++++++++++++++++++++++++++----
31
1 file changed, 34 insertions(+), 4 deletions(-)
33
diff --git a/git-svn.perl b/git-svn.perl
34
index 045105b..e7d0fb8 100755
37
@@ -1285,6 +1285,38 @@ sub _canonicalize_url_ourselves {
43
+ my $new_path = join_paths(@paths);
45
+Appends @paths together into a single path. Any empty paths are ignored.
52
+ @paths = grep { defined $_ && length $_ } @paths;
54
+ return '' unless @paths;
55
+ return $paths[0] if @paths == 1;
57
+ my $new_path = shift @paths;
58
+ $new_path =~ s{/+$}{};
60
+ my $last_path = pop @paths;
61
+ $last_path =~ s{^/+}{};
63
+ for my $path (@paths) {
66
+ $new_path .= "/$path";
69
+ return $new_path .= "/$last_path";
75
# Helper for cmd_propget and cmd_proplist below.
76
@@ -1298,7 +1330,7 @@ sub get_svnprops {
77
$path = $cmd_dir_prefix . $path;
78
fatal("No such file or directory: $path") unless -e $path;
79
my $is_dir = -d $path ? 1 : 0;
80
- $path = $gs->{path} . '/' . $path;
81
+ $path = join_paths($gs->{path}, $path);
83
# canonicalize the path (otherwise libsvn will abort or fail to
85
@@ -2342,9 +2374,7 @@ sub init_remote_config {
87
my $old_path = $self->path;
88
$url =~ s!^\Q$min_url\E(/|$)!!;
89
- if (length $old_path) {
90
- $url .= "/$old_path";
92
+ $url = ::join_paths($url, $old_path);