1 package Git
::SVN
::Utils
;
20 Git::SVN::Utils - utility functions used across Git::SVN
24 use Git::SVN::Utils qw(functions to import);
28 This module contains functions which are useful across many different
29 parts of Git::SVN. Mostly it's a place to put utility functions
30 rather than duplicate the code or have classes grabbing at other
35 All functions can be imported only on request.
41 Display a message and exit with a fatal error code.
45 # Note: not certain why this is in use instead of die. Probably because
46 # the exit code of die is 255? Doesn't appear to be used consistently.
47 sub fatal
(@
) { print STDERR
"@_\n"; exit 1 }
52 my $can_compress = can_compress;
54 Returns true if Compress::Zlib is available, false otherwise.
60 return $can_compress if defined $can_compress;
62 return $can_compress = eval { require Compress
::Zlib
; };
66 =head3 canonicalize_path
68 my $canoncalized_path = canonicalize_path($path);
70 Converts $path into a canonical form which is safe to pass to the SVN
75 sub canonicalize_path
{
77 my $dot_slash_added = 0;
78 if (substr($path, 0, 1) ne "/") {
82 # File::Spec->canonpath doesn't collapse x/../y into y (for a
83 # good reason), so let's do this manually.
85 $path =~ s
#/\.(?:/|$)#/#g;
86 $path =~ s
#/[^/]+/\.\.##g;
88 $path =~ s
#^\./## if $dot_slash_added;
95 =head3 canonicalize_url
97 my $canonicalized_url = canonicalize_url($url);
99 Converts $url into a canonical form which is safe to pass to the SVN
104 sub canonicalize_url
{
107 # The 1.7 way to do it
108 if ( defined &SVN
::_Core
::svn_uri_canonicalize
) {
109 return SVN
::_Core
::svn_uri_canonicalize
($url);
111 # There wasn't a 1.6 way to do it, so we do it ourself.
113 return _canonicalize_url_ourselves
($url);
118 sub _canonicalize_url_ourselves
{
120 $url =~ s
#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e;