From 6a8d999ed4a0030ab7902382ed3b122ce448e581 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Fri, 27 Jul 2012 13:00:51 -0700 Subject: use Git::SVN->path accessor globally No functional change. [ew: commit title] Signed-off-by: Eric Wong --- git-svn.perl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index 5711c5719f..039623e5c5 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1195,7 +1195,7 @@ sub cmd_show_ignore { my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); $gs ||= Git::SVN->new; my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum); - $gs->prop_walk($gs->{path}, $r, sub { + $gs->prop_walk($gs->path, $r, sub { my ($gs, $path, $props) = @_; print STDOUT "\n# $path\n"; my $s = $props->{'svn:ignore'} or return; @@ -1211,7 +1211,7 @@ sub cmd_show_externals { my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); $gs ||= Git::SVN->new; my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum); - $gs->prop_walk($gs->{path}, $r, sub { + $gs->prop_walk($gs->path, $r, sub { my ($gs, $path, $props) = @_; print STDOUT "\n# $path\n"; my $s = $props->{'svn:externals'} or return; @@ -1226,7 +1226,7 @@ sub cmd_create_ignore { my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); $gs ||= Git::SVN->new; my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum); - $gs->prop_walk($gs->{path}, $r, sub { + $gs->prop_walk($gs->path, $r, sub { my ($gs, $path, $props) = @_; # $path is of the form /path/to/dir/ $path = '.' . $path; @@ -1396,7 +1396,7 @@ sub cmd_commit_diff { "the command-line\n", $usage); } $url = $gs->{url}; - $svn_path = $gs->{path}; + $svn_path = $gs->path; } unless (defined $_revision) { fatal("-r|--revision is a required argument\n", $usage); @@ -1634,6 +1634,8 @@ sub post_fetch_checkout { sub complete_svn_url { my ($url, $path) = @_; $path =~ s#/+$##; + + # If the path is not a URL... if ($path !~ m#^[a-z\+]+://#) { if (!defined $url || $url !~ m#^[a-z\+]+://#) { fatal("E: '$path' is not a complete URL ", @@ -1670,7 +1672,7 @@ sub complete_url_ls_init { "wanted to set to: $gs->{url}\n"; } command_oneline('config', $k, $gs->{url}) unless $orig_url; - my $remote_path = "$gs->{path}/$repo_path"; + my $remote_path = $gs->path . "/$repo_path"; $remote_path =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg; $remote_path =~ s#/+#/#g; $remote_path =~ s#^/##g; -- cgit v1.2.3 From b1ea6c3829109aff412095b889432bf496f46a90 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Fri, 27 Jul 2012 13:00:52 -0700 Subject: use Git::SVN{,::RA}->url accessor globally Note: The structure returned from Git::SVN->read_all_remotes() does not appear to contain objects, so I'm leaving them alone. That's everything converted over to the url and path accessors. No functional change. [ew: commit title] Signed-off-by: Eric Wong --- git-svn.perl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index 039623e5c5..de1ddd1051 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1395,7 +1395,7 @@ sub cmd_commit_diff { fatal("Needed URL or usable git-svn --id in ", "the command-line\n", $usage); } - $url = $gs->{url}; + $url = $gs->url; $svn_path = $gs->path; } unless (defined $_revision) { @@ -1663,15 +1663,16 @@ sub complete_url_ls_init { "and a separate URL is not specified"); } } - my $url = $ra->{url}; + my $url = $ra->url; my $gs = Git::SVN->init($url, undef, undef, undef, 1); my $k = "svn-remote.$gs->{repo_id}.url"; my $orig_url = eval { command_oneline(qw/config --get/, $k) }; - if ($orig_url && ($orig_url ne $gs->{url})) { + if ($orig_url && ($orig_url ne $gs->url)) { die "$k already set: $orig_url\n", - "wanted to set to: $gs->{url}\n"; + "wanted to set to: $gs->url\n"; } - command_oneline('config', $k, $gs->{url}) unless $orig_url; + command_oneline('config', $k, $gs->url) unless $orig_url; + my $remote_path = $gs->path . "/$repo_path"; $remote_path =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg; $remote_path =~ s#/+#/#g; -- cgit v1.2.3 From 91e6e0c56cc83e5f53d93e90726380a2d392f5f1 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Sat, 28 Jul 2012 02:38:26 -0700 Subject: git-svn: move canonicalization to Git::SVN::Utils So they can be used by others. I'd like to test them, but they're going to become SVN API wrappers shortly and those aren't predictable. No functional change. [ew: commit title] Signed-off-by: Eric Wong --- git-svn.perl | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index de1ddd1051..a857484c58 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -29,7 +29,13 @@ use Git::SVN::Prompt; use Git::SVN::Log; use Git::SVN::Migration; -use Git::SVN::Utils qw(fatal can_compress); +use Git::SVN::Utils qw( + fatal + can_compress + canonicalize_path + canonicalize_url +); + use Git qw( git_cmd_try command @@ -1256,31 +1262,6 @@ sub cmd_mkdirs { $gs->mkemptydirs($_revision); } -sub canonicalize_path { - my ($path) = @_; - my $dot_slash_added = 0; - if (substr($path, 0, 1) ne "/") { - $path = "./" . $path; - $dot_slash_added = 1; - } - # File::Spec->canonpath doesn't collapse x/../y into y (for a - # good reason), so let's do this manually. - $path =~ s#/+#/#g; - $path =~ s#/\.(?:/|$)#/#g; - $path =~ s#/[^/]+/\.\.##g; - $path =~ s#/$##g; - $path =~ s#^\./## if $dot_slash_added; - $path =~ s#^/##; - $path =~ s#^\.$##; - return $path; -} - -sub canonicalize_url { - my ($url) = @_; - $url =~ s#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e; - return $url; -} - # get_svnprops(PATH) # ------------------ # Helper for cmd_propget and cmd_proplist below. -- cgit v1.2.3 From ca475a61f8c07d475c505bf64d219f7e9d61e728 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Sat, 28 Jul 2012 02:38:29 -0700 Subject: 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 --- git-svn.perl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index a857484c58..6e3e240473 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -34,6 +34,7 @@ use Git::SVN::Utils qw( can_compress canonicalize_path canonicalize_url + join_paths ); use Git qw( @@ -1275,7 +1276,7 @@ sub get_svnprops { $path = $cmd_dir_prefix . $path; fatal("No such file or directory: $path") unless -e $path; my $is_dir = -d $path ? 1 : 0; - $path = $gs->{path} . '/' . $path; + $path = join_paths($gs->{path}, $path); # canonicalize the path (otherwise libsvn will abort or fail to # find the file) -- cgit v1.2.3 From 9c27a57b2da502b7dd3736013b7a185fb6e5064e Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Sat, 28 Jul 2012 02:47:48 -0700 Subject: 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 --- git-svn.perl | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index 6e3e240473..6e975457f9 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1412,24 +1412,6 @@ sub cmd_commit_diff { } } -sub escape_uri_only { - my ($uri) = @_; - my @tmp; - foreach (split m{/}, $uri) { - s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg; - push @tmp, $_; - } - join('/', @tmp); -} - -sub escape_url { - my ($url) = @_; - if ($url =~ m#^([^:]+)://([^/]*)(.*)$#) { - my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only($3)); - $url = "$scheme://$domain$uri"; - } - $url; -} sub cmd_info { my $path = canonicalize_path(defined($_[0]) ? $_[0] : "."); @@ -1457,18 +1439,18 @@ sub cmd_info { my $full_url = $url . ($fullpath eq "" ? "" : "/$fullpath"); if ($_url) { - print escape_url($full_url), "\n"; + print canonicalize_url($full_url), "\n"; return; } my $result = "Path: $path\n"; $result .= "Name: " . basename($path) . "\n" if $file_type ne "dir"; - $result .= "URL: " . escape_url($full_url) . "\n"; + $result .= "URL: " . canonicalize_url($full_url) . "\n"; eval { my $repos_root = $gs->repos_root; Git::SVN::remove_username($repos_root); - $result .= "Repository Root: " . escape_url($repos_root) . "\n"; + $result .= "Repository Root: " . canonicalize_url($repos_root) . "\n"; }; if ($@) { $result .= "Repository Root: (offline)\n"; -- cgit v1.2.3 From 8266fc8be19ef1405d4ef175bb0e75ebc2730f5d Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Sat, 28 Jul 2012 02:47:49 -0700 Subject: git-svn: canonicalize earlier Just a few things I noticed. Its good to canonicalize as early as possible. [ew: commit title] Signed-off-by: Eric Wong --- git-svn.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index 6e975457f9..6b9076599b 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -1436,16 +1436,16 @@ sub cmd_info { # canonicalize_path() will return "" to make libsvn 1.5.x happy, $path = "." if $path eq ""; - my $full_url = $url . ($fullpath eq "" ? "" : "/$fullpath"); + my $full_url = canonicalize_url( $url . ($fullpath eq "" ? "" : "/$fullpath") ); if ($_url) { - print canonicalize_url($full_url), "\n"; + print "$full_url\n"; return; } my $result = "Path: $path\n"; $result .= "Name: " . basename($path) . "\n" if $file_type ne "dir"; - $result .= "URL: " . canonicalize_url($full_url) . "\n"; + $result .= "URL: $full_url\n"; eval { my $repos_root = $gs->repos_root; -- cgit v1.2.3 From d2fd119c4fcaea266a894354b506959376140c37 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Sat, 28 Jul 2012 02:47:50 -0700 Subject: git-svn: introduce add_path_to_url function Remove the ad-hoc versions. This is mostly to normalize the process and ensure the URLs produced don't have double slashes or anything. Also provides a place to fix the corner case where a file path contains a percent sign. [ew: commit title] Signed-off-by: Eric Wong --- git-svn.perl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index 6b9076599b..3d120d5bc4 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -35,6 +35,7 @@ use Git::SVN::Utils qw( canonicalize_path canonicalize_url join_paths + add_path_to_url ); use Git qw( @@ -1436,7 +1437,7 @@ sub cmd_info { # canonicalize_path() will return "" to make libsvn 1.5.x happy, $path = "." if $path eq ""; - my $full_url = canonicalize_url( $url . ($fullpath eq "" ? "" : "/$fullpath") ); + my $full_url = canonicalize_url( add_path_to_url( $url, $fullpath ) ); if ($_url) { print "$full_url\n"; -- cgit v1.2.3 From 5eaa1fd086e826b1ac8d9346a740527edbdb3c34 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Sat, 28 Jul 2012 02:47:52 -0700 Subject: git-svn: remove ad-hoc canonicalizations [ew: commit title] Signed-off-by: Eric Wong --- git-svn.perl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'git-svn.perl') diff --git a/git-svn.perl b/git-svn.perl index 3d120d5bc4..56d1ba712a 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -36,6 +36,7 @@ use Git::SVN::Utils qw( canonicalize_url join_paths add_path_to_url + join_paths ); use Git qw( @@ -1598,7 +1599,7 @@ sub post_fetch_checkout { sub complete_svn_url { my ($url, $path) = @_; - $path =~ s#/+$##; + $path = canonicalize_path($path); # If the path is not a URL... if ($path !~ m#^[a-z\+]+://#) { @@ -1617,7 +1618,7 @@ sub complete_url_ls_init { print STDERR "W: $switch not specified\n"; return; } - $repo_path =~ s#/+$##; + $repo_path = canonicalize_path($repo_path); if ($repo_path =~ m#^[a-z\+]+://#) { $ra = Git::SVN::Ra->new($repo_path); $repo_path = ''; @@ -1638,9 +1639,8 @@ sub complete_url_ls_init { } command_oneline('config', $k, $gs->url) unless $orig_url; - my $remote_path = $gs->path . "/$repo_path"; + my $remote_path = join_paths( $gs->path, $repo_path ); $remote_path =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg; - $remote_path =~ s#/+#/#g; $remote_path =~ s#^/##g; $remote_path .= "/*" if $remote_path !~ /\*/; my ($n) = ($switch =~ /^--(\w+)/); -- cgit v1.2.3