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 <normalperson@yhbt.net>
This commit is contained in:

committed by
Eric Wong

parent
b1ea6c3829
commit
91e6e0c56c
33
git-svn.perl
33
git-svn.perl
@ -29,7 +29,13 @@ use Git::SVN::Prompt;
|
|||||||
use Git::SVN::Log;
|
use Git::SVN::Log;
|
||||||
use Git::SVN::Migration;
|
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(
|
use Git qw(
|
||||||
git_cmd_try
|
git_cmd_try
|
||||||
command
|
command
|
||||||
@ -1256,31 +1262,6 @@ sub cmd_mkdirs {
|
|||||||
$gs->mkemptydirs($_revision);
|
$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)
|
# get_svnprops(PATH)
|
||||||
# ------------------
|
# ------------------
|
||||||
# Helper for cmd_propget and cmd_proplist below.
|
# Helper for cmd_propget and cmd_proplist below.
|
||||||
|
@ -5,7 +5,12 @@ use warnings;
|
|||||||
|
|
||||||
use base qw(Exporter);
|
use base qw(Exporter);
|
||||||
|
|
||||||
our @EXPORT_OK = qw(fatal can_compress);
|
our @EXPORT_OK = qw(
|
||||||
|
fatal
|
||||||
|
can_compress
|
||||||
|
canonicalize_path
|
||||||
|
canonicalize_url
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
@ -56,4 +61,49 @@ sub can_compress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
=head3 canonicalize_path
|
||||||
|
|
||||||
|
my $canoncalized_path = canonicalize_path($path);
|
||||||
|
|
||||||
|
Converts $path into a canonical form which is safe to pass to the SVN
|
||||||
|
API as a file path.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
=head3 canonicalize_url
|
||||||
|
|
||||||
|
my $canonicalized_url = canonicalize_url($url);
|
||||||
|
|
||||||
|
Converts $url into a canonical form which is safe to pass to the SVN
|
||||||
|
API as a URL.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub canonicalize_url {
|
||||||
|
my ($url) = @_;
|
||||||
|
$url =~ s#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e;
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Reference in New Issue
Block a user