git-svn: replace URL escapes with canonicalization
The old hand-rolled URL escape functions were inferior to canonicalization functions. Continuing to move towards getting everything canonicalizing the same way. * Git::SVN->init_remote_config and Git::SVN::Ra->minimize_url both have to canonicalize the same way else init_remote_config will incorrectly think they're different URLs causing t9107-git-svn-migrate.sh to fail. [ew: commit title] Signed-off-by: Eric Wong <normalperson@yhbt.net>
Michael G. Schwern committed
Jul 28, 2012 at 02:47 UTC
9c27a57b2da502b7dd3736013b7a185fb6e5064e
3 files changed
+9
-44
git-svn.perl
+3
-21
@@ -1412,24 +1412,6 @@ sub cmd_commit_diff {
1412
}
1413
}
1414
1415
-sub escape_uri_only {
1416
- my ($uri) = @_;
1417
- my @tmp;
1418
- foreach (split m{/}, $uri) {
1419
- s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
1420
- push @tmp, $_;
1421
- }
1422
- join('/', @tmp);
1423
-}
1424
-
1425
-sub escape_url {
1426
- my ($url) = @_;
1427
- if ($url =~ m#^([^:]+)://([^/]*)(.*)$#) {
1428
- my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only($3));
1429
- $url = "$scheme://$domain$uri";
1430
- }
1431
- $url;
1432
-}
1415
1416
sub cmd_info {
1417
my $path = canonicalize_path(defined($_[0]) ? $_[0] : ".");
@@ -1457,18 +1439,18 @@ sub cmd_info {
1439
my $full_url = $url . ($fullpath eq "" ? "" : "/$fullpath");
1440
1441
if ($_url) {
1460
- print escape_url($full_url), "\n";
1442
+ print canonicalize_url($full_url), "\n";
1443
return;
1444
}
1445
1446
my $result = "Path: $path\n";
1447
$result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
1466
- $result .= "URL: " . escape_url($full_url) . "\n";
1448
+ $result .= "URL: " . canonicalize_url($full_url) . "\n";
1449
1450
eval {
1451
my $repos_root = $gs->repos_root;
1452
Git::SVN::remove_username($repos_root);
1471
- $result .= "Repository Root: " . escape_url($repos_root) . "\n";
1453
+ $result .= "Repository Root: " . canonicalize_url($repos_root) . "\n";
1454
};
1455
if ($@) {
1456
$result .= "Repository Root: (offline)\n";
perl/Git/SVN.pm
+1
-1
@@ -296,7 +296,7 @@ sub find_existing_remote {
296
297
sub init_remote_config {
298
my ($self, $url, $no_write) = @_;
299
- $url =~ s!/+$!!; # strip trailing slash
299
+ $url = canonicalize_url($url);
300
my $r = read_all_remotes();
301
my $existing = find_existing_remote($url, $r);
302
if ($existing) {
perl/Git/SVN/Ra.pm
+5
-22
@@ -66,24 +66,6 @@ sub _auth_providers () {
66
\@rv;
67
}
68
69
-sub escape_uri_only {
70
- my ($uri) = @_;
71
- my @tmp;
72
- foreach (split m{/}, $uri) {
73
- s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
74
- push @tmp, $_;
75
- }
76
- join('/', @tmp);
77
-}
78
-
79
-sub escape_url {
80
- my ($url) = @_;
81
- if ($url =~ m#^(https?)://([^/]+)(.*)$#) {
82
- my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only($3));
83
- $url = "$scheme://$domain$uri";
84
- }
85
- $url;
86
-}
69
70
sub new {
71
my ($class, $url) = @_;
@@ -119,7 +101,7 @@ sub new {
101
$Git::SVN::Prompt::_no_auth_cache = 1;
102
}
103
} # no warnings 'once'
122
- my $self = SVN::Ra->new(url => escape_url($url), auth => $baton,
104
+ my $self = SVN::Ra->new(url => canonicalize_url($url), auth => $baton,
105
config => $config,
106
pool => SVN::Pool->new,
107
auth_provider_callbacks => $callbacks);
@@ -312,7 +294,7 @@ sub gs_do_switch {
294
295
if ($old_url =~ m#^svn(\+ssh)?://# ||
296
($full_url =~ m#^https?://# &&
315
- escape_url($full_url) ne $full_url)) {
297
+ canonicalize_url($full_url) ne $full_url)) {
298
$_[0] = undef;
299
$self = undef;
300
$RA = undef;
@@ -325,7 +307,7 @@ sub gs_do_switch {
307
}
308
309
$ra ||= $self;
328
- $url_b = escape_url($url_b);
310
+ $url_b = canonicalize_url($url_b);
311
my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
312
my @lock = (::compare_svn_version('1.2.0') >= 0) ? (undef) : ();
313
$reporter->set_path('', $rev_a, 0, @lock, $pool);
@@ -580,7 +562,8 @@ sub minimize_url {
562
$ra->get_log("", $latest, 0, 1, 0, 1, sub {});
563
};
564
} while ($@ && ($c = shift @components));
583
- $url;
565
+
566
+ return canonicalize_url($url);
567
}
568
569
sub can_do_switch {