1 package Git::SVN::Utils;
18 Git::SVN::Utils - utility functions used across Git::SVN
22 use Git::SVN::Utils qw(functions to import);
26 This module contains functions which are useful across many different
27 parts of Git::SVN. Mostly it's a place to put utility functions
28 rather than duplicate the code or have classes grabbing at other
33 All functions can be imported only on request.
39 Display a message and exit with a fatal error code.
43 # Note: not certain why this is in use instead of die. Probably because
44 # the exit code of die is 255? Doesn't appear to be used consistently.
45 sub fatal (@) { print STDERR "@_\n"; exit 1 }
50 my $can_compress = can_compress;
52 Returns true if Compress::Zlib is available, false otherwise.
58 return $can_compress if defined $can_compress;
60 return $can_compress = eval { require Compress::Zlib; };
64 =head3 canonicalize_path
66 my $canoncalized_path = canonicalize_path($path);
68 Converts $path into a canonical form which is safe to pass to the SVN
73 sub canonicalize_path {
75 my $dot_slash_added = 0;
76 if (substr($path, 0, 1) ne "/") {
80 # File::Spec->canonpath doesn't collapse x/../y into y (for a
81 # good reason), so let's do this manually.
83 $path =~ s#/\.(?:/|$)#/#g;
84 $path =~ s#/[^/]+/\.\.##g;
86 $path =~ s#^\./## if $dot_slash_added;
93 =head3 canonicalize_url
95 my $canonicalized_url = canonicalize_url($url);
97 Converts $url into a canonical form which is safe to pass to the SVN
102 sub canonicalize_url {
104 $url =~ s#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e;