Skip to content

Commit 3a81a00

Browse files
committed
Move the canonicalization functions 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.
1 parent b5095f7 commit 3a81a00

File tree

2 files changed

+58
-27
lines changed

2 files changed

+58
-27
lines changed

git-svn.perl

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@
2929
use Git::SVN::Log;
3030
use Git::SVN::Migration;
3131

32-
use Git::SVN::Utils qw(fatal can_compress);
32+
use Git::SVN::Utils qw(
33+
fatal
34+
can_compress
35+
canonicalize_path
36+
canonicalize_url
37+
);
38+
3339
use Git qw(
3440
git_cmd_try
3541
command
@@ -1256,31 +1262,6 @@ sub cmd_mkdirs {
12561262
$gs->mkemptydirs($_revision);
12571263
}
12581264

1259-
sub canonicalize_path {
1260-
my ($path) = @_;
1261-
my $dot_slash_added = 0;
1262-
if (substr($path, 0, 1) ne "/") {
1263-
$path = "./" . $path;
1264-
$dot_slash_added = 1;
1265-
}
1266-
# File::Spec->canonpath doesn't collapse x/../y into y (for a
1267-
# good reason), so let's do this manually.
1268-
$path =~ s#/+#/#g;
1269-
$path =~ s#/\.(?:/|$)#/#g;
1270-
$path =~ s#/[^/]+/\.\.##g;
1271-
$path =~ s#/$##g;
1272-
$path =~ s#^\./## if $dot_slash_added;
1273-
$path =~ s#^/##;
1274-
$path =~ s#^\.$##;
1275-
return $path;
1276-
}
1277-
1278-
sub canonicalize_url {
1279-
my ($url) = @_;
1280-
$url =~ s#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e;
1281-
return $url;
1282-
}
1283-
12841265
# get_svnprops(PATH)
12851266
# ------------------
12861267
# Helper for cmd_propget and cmd_proplist below.

perl/Git/SVN/Utils.pm

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ use warnings;
55

66
use base qw(Exporter);
77

8-
our @EXPORT_OK = qw(fatal can_compress);
8+
our @EXPORT_OK = qw(
9+
fatal
10+
can_compress
11+
canonicalize_path
12+
canonicalize_url
13+
);
914

1015

1116
=head1 NAME
@@ -56,4 +61,49 @@ sub can_compress {
5661
}
5762

5863

64+
=head3 canonicalize_path
65+
66+
my $canoncalized_path = canonicalize_path($path);
67+
68+
Converts $path into a canonical form which is safe to pass to the SVN
69+
API as a file path.
70+
71+
=cut
72+
73+
sub canonicalize_path {
74+
my ($path) = @_;
75+
my $dot_slash_added = 0;
76+
if (substr($path, 0, 1) ne "/") {
77+
$path = "./" . $path;
78+
$dot_slash_added = 1;
79+
}
80+
# File::Spec->canonpath doesn't collapse x/../y into y (for a
81+
# good reason), so let's do this manually.
82+
$path =~ s#/+#/#g;
83+
$path =~ s#/\.(?:/|$)#/#g;
84+
$path =~ s#/[^/]+/\.\.##g;
85+
$path =~ s#/$##g;
86+
$path =~ s#^\./## if $dot_slash_added;
87+
$path =~ s#^/##;
88+
$path =~ s#^\.$##;
89+
return $path;
90+
}
91+
92+
93+
=head3 canonicalize_url
94+
95+
my $canonicalized_url = canonicalize_url(http://github.com/$url);
96+
97+
Converts $url into a canonical form which is safe to pass to the SVN
98+
API as a URL.
99+
100+
=cut
101+
102+
sub canonicalize_url {
103+
my ($url) = @_;
104+
$url =~ s#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e;
105+
return $url;
106+
}
107+
108+
59109
1;

0 commit comments

Comments
 (0)