5 use SVN
::Base
qw(Core svn_ VERSION);
6 # Some build tool hates VERSION assign across two lines.
7 $SVN::Core
::VERSION
= "$SVN::Core::VER_MAJOR.$SVN::Core::VER_MINOR.$SVN::Core::VER_MICRO";
11 SVN::Core - Core module of the subversion perl bindings
15 use SVN::Core; # does apr_initialize and cleanup for you
17 # create a root pool and set it as default pool for later use
18 my $pool = SVN::Pool->new_default;
21 # create a subpool of the current default pool
22 my $pool = SVN::Pool->new_default_sub;
23 # some svn operations...
25 # $pool gets destroyed and the previous default pool
26 # is restored when $pool's lexical scope ends
29 # svn_stream_t as native perl io handle
30 my $stream = $txn->root->apply_text('trunk/filea', undef);
34 # native perl io handle as svn_stream_t
35 SVN::Repos::dump_fs($repos, \*STDOUT, \*STDERR,
36 0, $repos->fs->youngest_rev, 0);
40 SVN::Core implements higher level functions of fundamental subversion
50 SVN
::_Core
::apr_initialize
();
53 my $gpool = SVN
::Pool
->new_default;
54 sub gpool
{ $gpool } # holding the reference to gpool
55 SVN
::Core
::utf_initialize
($gpool);
58 SVN
::_Core
::apr_terminate
();
61 =item SVN::Core::auth_open([auth provider array]);
63 Takes a reference to an array of authentication providers
64 and returns an auth_baton. If you use prompt providers
65 you can not use this function, but need to use the
68 =item SVN::Core::auth_open_helper([auth provider array);
70 Prompt providers return two values instead of one. The
71 2nd parameter is a reference to whatever was passed into
72 them as the callback. auth_open_helper splits up these
73 arguments, passing the provider objects into auth_open
74 which gives it an auth_baton and putting the other
75 ones in an array. The first return value of this
76 function is the auth_baton, the second is a reference
77 to an array containing the references to the callbacks.
79 These callback arrays should be stored in the object
80 the auth_baton is attached to.
86 sub auth_open_helper
{
88 my (@auth_providers,@auth_callbacks);
90 foreach my $arg (@
{$args}) {
91 if (ref($arg) eq '_p_svn_auth_provider_object_t') {
92 push @auth_providers, $arg;
94 push @auth_callbacks, $arg;
97 my $auth_baton = SVN
::Core
::auth_open
(\
@auth_providers);
98 return ($auth_baton,\
@auth_callbacks);
101 # import the INVALID and IGNORED constants
102 our $INVALID_REVNUM = $SVN::_Core
::SWIG_SVN_INVALID_REVNUM
;
103 our $IGNORED_REVNUM = $SVN::_Core
::SWIG_SVN_IGNORED_REVNUM
;
105 package _p_svn_stream_t
;
106 use SVN
::Base
qw(Core svn_stream_);
110 our @ISA = qw(IO::Handle);
114 =head2 svn_stream_t - SVN::Stream
116 You can use native perl io handles (including io globs) as
117 svn_stream_t in subversion functions. Returned svn_stream_t are also
118 translated into perl io handles, so you could access them with regular
121 Note that some functions take a stream to read from or write to, but do not
122 close the stream while still holding the reference to the io handle.
123 In this case the handle won't be destroyed properly.
124 You should always set up the correct default pool before calling
134 my $self = bless Symbol
::gensym
(), ref($class) || $class;
136 *$self->{svn_stream
} = shift;
142 *$self->{svn_stream
};
147 return $_[0] if ref($_[0]);
149 my $self = bless Symbol
::gensym
(), $class;
150 *$self->{svn_stream
} = shift;
157 *$self->{svn_stream
}->close
158 if *$self->{svn_stream
};
159 undef *$self->{svn_stream
};
166 return $buf if $self->read($buf, 1);
173 $self->WRITE ($_[0], length ($_[0]));
181 $self->print(join($,, @_).$\
);
183 $self->print(join("",@_).$\
);
187 $self->print(join($,, @_));
189 $self->print(join("",@_));
198 $self->print(sprintf($fmt, @_));
204 *$self->{pool
} ||= SVN
::Core
::pool_create
(undef);
205 my ($buf, $eof) = *$self->{svn_stream
}->readline ($/, *$self->{pool
});
206 return undef if $eof && !length($buf);
207 return $eof ?
$buf : $buf.$/;
212 die "getlines() called in scalar context\n" unless wantarray;
215 push @lines, $line while defined($line = $self->getline);
222 unless (defined $/) {
224 while (length( my $chunk = *$self->{svn_stream
}->read
225 ($SVN::Core
::STREAM_CHUNK_SIZE
)) ) {
231 my $buf = *$self->{svn_stream
}->read (${$/});
232 return length($buf) ?
$buf : undef;
234 return wantarray ?
$self->getlines : $self->getline;
240 if (@_ > 2) { # read offset
241 substr($_[0],$_[2]) = *$self->{svn_stream
}->read ($len);
243 $_[0] = *$self->{svn_stream
}->read ($len);
250 my $slen = length($_[0]);
255 $len = $_[1] if $_[1] < $len;
258 die "Offset outside string" if $off > $slen;
261 die "Offset outside string" if $off < 0;
263 my $rem = $slen - $off;
264 $len = $rem if $rem < $len;
266 *$self->{svn_stream
}->write (substr ($_[0], $off, $len));
274 return undef; # XXX perlfunc says this means the file is closed
282 package _p_apr_pool_t
;
288 my $pobj = SVN
::Pool
->_wrap ($$pool);
289 $WRAPPED{$pool} = $pobj;
295 delete $WRAPPED{$pool};
299 use SVN
::Base
qw(Core svn_pool_);
301 =head2 svn_pool_t - SVN::Pool
303 The perl bindings significantly simplify the usage of pools, while
304 still being manually adjustable.
306 For functions requiring a pool as the last argument (which are, almost all
307 of the subversion functions), the pool argument is optional. The default pool
308 is used if it is omitted. When C<SVN::Core> is loaded, it creates a
309 new default pool, which is also available from C<SVN::Core-E<gt>gpool>.
311 For callback functions providing a pool to your subroutine, you could
312 also use $pool-E<gt>default to make it the default pool in the scope.
318 =item new ([$parent])
320 Create a new pool. The pool is a root pool if $parent is not supplied.
322 =item new_default ([$parent])
324 Create a new pool. The pool is a root pool if $parent is not supplied.
325 Set the new pool as default pool.
327 =item new_default_sub
329 Create a new subpool of the current default pool, and set the
330 resulting pool as new default pool.
338 Destroy the pool. If the pool was the default pool, restore the
339 previous default pool. This is normally called
340 automatically when the SVN::Pool object is no longer used and
341 destroyed by the perl garbage collector.
348 # block is here to restrict no strict refs to this block
350 *{"apr_pool_$_"} = *{"SVN::_Core::apr_pool_$_"}
351 for qw
/clear destroy/;
357 my ($class, $parent) = @_;
358 $parent = $$parent if ref ($parent) eq 'SVN::Pool';
359 my $self = bless \create
($parent), $class;
363 sub new_default_sub
{
364 my $parent = ref ($_[0]) ?
${+shift} : $SVN::_Core
::current_pool
;
365 my $self = SVN
::Pool
->new_default ($parent);
377 push @POOLSTACK, $SVN::_Core
::current_pool
378 unless $$SVN::_Core
::current_pool
== 0;
379 $SVN::_Core
::current_pool
= $$self;
384 apr_pool_clear
($$self);
395 # Create a cloned _p_apr_pool_t pointing to the same apr_pool_t
396 # but on different address. this allows pools that are from C
397 # to have proper lifetime.
399 my ($class, $rawpool) = @_;
400 my $pool = \
$rawpool;
401 bless $pool, '_p_apr_pool_t';
403 bless $npool, $class;
404 $WRAPPOOL{$npool} = 1;
408 use Scalar
::Util
'reftype';
411 return if $globaldestroy;
413 # for some reason, REF becomes SCALAR in perl -c or after apr_terminate
414 return if reftype
($self) eq 'SCALAR';
415 if ($$self eq $SVN::_Core
::current_pool
) {
416 $SVN::_Core
::current_pool
= pop @POOLSTACK;
418 if (exists $WRAPPOOL{$self}) {
419 delete $WRAPPOOL{$self};
422 apr_pool_destroy
($$self)
426 package _p_svn_error_t
;
427 use SVN
::Base
qw(Core svn_error_t_);
430 return SVN
::Error
::strerror
($_[$[]->apr_err());
434 return SVN
::Error
::handle_error
(@_);
437 sub expanded_message
{
438 return SVN
::Error
::expanded_message
(@_);
442 # need to swap parameter order.
443 return SVN
::Error
::handle_warning
($_[$[+1],$_[$[]);
446 foreach my $function (qw(compose clear quick_wrap)) {
448 my $real_function = \
&{"SVN::_Core::svn_error_$function"};
449 *{"_p_svn_error_t::$function"} = sub {
450 return $real_function->(@_);
455 use SVN
::Base
qw(Core svn_error_);
456 use SVN
::Base
qw(Core SVN_ERR_);
458 our @CARP_NOT = qw(SVN::Base SVN::Client SVN::Core SVN::Delta
459 SVN::Delta::Editor SVN::Error SVN::Fs SVN::Node
460 SVN::Pool SVN::Ra SVN::Ra::Callbacks SVN::Ra::Reporter
461 SVN::Repos SVN::Stream SVN::TxDelta SVN::Wc);
463 =head2 svn_error_t - SVN::Error
465 By default the perl bindings handle exceptions for you. The default handler
466 automatically croaks with an appropriate error message. This is likely
467 sufficient for simple scripts, but more complex usage may demand handling of
470 You can override the default exception handler by changing the
471 $SVN::Error::handler variable. This variable holds a reference to a perl sub
472 that should be called whenever an error is returned by a svn function. This
473 sub will be passed a svn_error_t object. Its return value is ignored.
475 If you set the $SVN::Error::handler to undef then each call will return an
476 svn_error_t object as its first return in the case of an error, followed by the
477 normal return values. If there is no error then a svn_error_t will not be
478 returned and only the normal return values will be returned. When using this
479 mode you should be careful only to call functions in array context. For
480 example: my ($ci) = $ctx-E<gt>mkdir('http://svn/foo'); In this case $ci will
481 be an svn_error_t object if an error occurs and a svn_client_commit_info object
482 otherwise. If you leave the parenthesis off around $ci (scalar context) it
483 will be the commit_info object, which in the case of an error will be undef.
485 If you plan on using explicit exception handling, understanding the exception
486 handling system the C API uses is helpful. You can find information on it in
487 the HACKING file and the API documentation. Looking at the implementation of
488 SVN::Error::croak_on_error and SVN::Error::expanded_message may be helpful as
493 =item $svn_error_t-E<gt>apr_err()
495 APR error value, possibly SVN_ custom error.
497 =item $svn_error_t-E<gt>message()
499 Details from producer of error.
501 =item $svn_error_t-E<gt>child()
503 svn_error_t object of the error that's wrapped.
505 =item $svn_error_t-E<gt>pool()
507 The pool holding this error and any child errors it wraps.
509 =item $svn_error_t-E<gt>file()
511 Source file where the error originated.
513 =item $svn_error_t-E<gt>line()
515 Source line where the error originated.
517 =item SVN::Error::strerror($apr_status_t)
519 Returns the english description of the status code.
521 =item $svn_error_t-E<gt>strerror()
523 Returns the english description of the apr_err status code set on the
524 $svn_error_t. This is short for:
525 SVN::Error::strerror($svn_error_t-E<gt>apr_err());
527 =item SVN::Error::create($apr_err, $child, $message);
529 Returns a new svn_error_t object with the error status specified in $apr_err,
530 the child as $child, and error message of $message.
532 =item SVN::Error::quick_wrap($child, $new_msg); or $child-E<gt>quick_wrap($new_msg);
534 A quick n' easy way to create a wrappered exception with your own message
535 before throwing it up the stack.
537 $child is the svn_error_t object you want to wrap and $new_msg is the new error
538 string you want to set.
540 =item SVN::Error::compose($chain, $new_error); or $chain-E<gt>compose($new_error);
542 Add new_err to the end of $chain's chain of errors.
544 The $new_err chain will be copied into $chain's pool and destroyed, so $new_err
545 itself becomes invalid after this function.
547 =item SVN::Error::clear($svn_error_t); or $svn_error_t-E<gt>clear();
549 Free the memory used by $svn_error_t, as well as all ancestors and descendants
552 You must call this on every svn_error_t object you get or you will leak memory.
556 # Permit users to determine if they want automatic croaking or not.
557 our $handler = \
&croak_on_error
;
559 # Import functions that don't follow the normal naming scheme.
560 foreach my $function (qw(handle_error handle_warning strerror)) {
562 my $real_function = \
&{"SVN::_Core::svn_$function"};
563 *{"SVN::Error::$function"} = sub {
564 return $real_function->(@_);
568 =item SVN::Error::expanded_message($svn_error_t) or $svn_error_t-E<gt>expanded_message()
570 Returns the error message by tracing through the svn_error_t object and its
571 children and concatenating the error messages. This is how the internal
572 exception handlers get their error messages.
576 sub expanded_message
{
577 my $svn_error = shift;
578 unless (is_error
($svn_error)) {
582 my $error_message = $svn_error->strerror();
584 $error_message .= ': ' . $svn_error->message();
585 $svn_error = $svn_error->child();
587 return $error_message;
591 =item SVN::Error::is_error($value)
593 Returns true if value is of type svn_error. Returns false if value is
594 anything else or undefined. This is useful for seeing if a call has returned
600 return (ref($_[$[]) eq '_p_svn_error_t');
603 =item SVN::Error::croak_on_error
605 Default error handler. It takes an svn_error_t and extracts the error messages
606 from it and croaks with those messages.
608 It can be used in two ways. The first is detailed above as setting it as the
609 automatic exception handler via setting $SVN::Error::handler.
611 The second is if you have $SVN::Error::handler set to undef as a wrapper for
612 calls you want to croak on when there is an error, but you don't want to write
613 an explicit error handler. For example:
615 my $result_rev=SVN::Error::croak_on_error($ctx-E<gt>checkout($url,$path,'HEAD',1));
617 If there is no error then croak_on_error will return the arguments passed to it
623 unless (is_error
($_[$[])) {
626 my $svn_error = shift;
628 my $error_message = $svn_error->expanded_message();
632 croak
($error_message);
635 =item SVN::Error::confess_on_error
637 The same as croak_on_error except it will give a more detailed stack backtrace,
638 including internal calls within the implementation of the perl bindings.
639 This is useful when you are doing development work on the bindings themselves.
643 sub confess_on_error
{
644 unless (is_error
($_[$[])) {
647 my $svn_error = shift;
649 my $error_message = $svn_error->expanded_message();
653 confess
($error_message);
656 =item SVN::Error::ignore_error
658 This is useful for wrapping around calls which you wish to ignore any potential
659 error. It checks to see if the first parameter is an error and if it is it
660 clears it. It then returns all the other parameters.
667 if (is_error
($_[$[])) {
668 my $svn_error = shift;
675 package _p_svn_log_changed_path_t
;
676 use SVN
::Base
qw(Core svn_log_changed_path_t_);
678 =head2 svn_log_changed_path_t
682 =item $lcp-E<gt>action()
684 'A'dd, 'D'elete, 'R'eplace, 'M'odify
686 =item $lcp-E<gt>copyfrom_path()
688 Source path of copy, or C<undef> if there isn't any previous revision
691 =item $lcp-E<gt>copyfrom_rev()
693 Source revision of copy, or C<$SVN::Core::INVALID_REVNUM> if there is
701 use SVN
::Base
qw(Core svn_node_);
703 =head2 svn_node_kind_t - SVN::Node
705 An enum of the following constants:
707 $SVN::Node::none, $SVN::Node::file,
708 $SVN::Node::dir, $SVN::Node::unknown.
712 package _p_svn_opt_revision_t
;
713 use SVN
::Base
qw(Core svn_opt_revision_t_);
715 =head2 svn_opt_revision_t
719 package _p_svn_opt_revision_t_value
;
720 use SVN
::Base
qw(Core svn_opt_revision_t_value_);
722 package _p_svn_config_t
;
723 use SVN
::Base
qw(Core svn_config_);
727 Opaque object describing a set of configuration options.
731 package _p_svn_dirent_t
;
732 use SVN
::Base
qw(Core svn_dirent_t_);
738 =item $dirent-E<gt>kind()
740 Node kind. A number which matches one of these constants:
741 $SVN::Node::none, $SVN::Node::file,
742 $SVN::Node::dir, $SVN::Node::unknown.
744 =item $dirent-E<gt>size()
746 Length of file text, or 0 for directories.
748 =item $dirent-E<gt>has_props()
750 Does the node have properties?
752 =item $dirent-E<gt>created_rev()
754 Last revision in which this node changed.
756 =item $dirent-E<gt>time()
758 Time of created_rev (mod-time).
760 =item $dirent-E<gt>last_author()
762 Author of created rev.
768 package _p_svn_auth_cred_simple_t
;
769 use SVN
::Base
qw(Core svn_auth_cred_simple_t_);
771 =head2 svn_auth_cred_simple_t
775 =item $simple-E<gt>username()
779 =item $simple-E<gt>password()
783 =item $simple-E<gt>may_save()
785 Indicates if the credentials may be saved (to disk).
791 package _p_svn_auth_cred_username_t
;
792 use SVN
::Base
qw(Core svn_auth_cred_username_t_);
794 =head2 svn_auth_cred_username_t
798 =item $username-E<gt>username()
802 =item $username-E<gt>may_save()
804 Indicates if the credentials may be saved (to disk).
810 package _p_svn_auth_cred_ssl_server_trust_t
;
811 use SVN
::Base
qw(Core svn_auth_cred_ssl_server_trust_t_);
813 =head2 svn_auth_cred_ssl_server_trust_t
817 =item $strust-E<gt>may_save()
819 Indicates if the credentials may be saved (to disk).
821 =item $strust-E<gt>accepted_failures()
823 Bit mask of the accepted failures.
829 package _p_svn_auth_ssl_server_cert_info_t
;
830 use SVN
::Base
qw(Core svn_auth_ssl_server_cert_info_t_);
832 =head2 svn_auth_ssl_server_cert_info_t
836 =item $scert-E<gt>hostname()
840 =item $scert-E<gt>fingerprint()
844 =item $scert-E<gt>valid_from()
846 ASCII date from which the certificate is valid.
848 =item $scert-E<gt>valid_until()
850 ASCII date until which the certificate is valid.
852 =item $scert-E<gt>issuer_dname()
854 DN of the certificate issuer.
856 =item $scert-E<gt>ascii_cert()
858 Base-64 encoded DER certificate representation.
864 package _p_svn_auth_cred_ssl_client_cert_t
;
865 use SVN
::Base
qw(Core svn_auth_cred_ssl_client_cert_t_);
867 =head2 svn_auth_cred_ssl_client_cert_t
871 =item $ccert-E<gt>cert_file()
873 Full paths to the certificate file.
875 =item $ccert-E<gt>may_save()
877 Indicates if the credentials may be saved (to disk).
883 package _p_svn_auth_cred_ssl_client_cert_pw_t
;
884 use SVN
::Base
qw(Core svn_auth_cred_ssl_client_cert_pw_t_);
886 =head2 svn_auth_cred_ssl_client_cert_pw_t
890 =item $ccertpw-E<gt>password()
892 Certificate password.
894 =item $ccertpw-E<gt>may_save()
896 Indicates if the credentials may be saved (to disk).
904 =head2 SVN::Auth::SSL
908 =item $SVN::Auth::SSL::NOTYETVALID
910 Certificate is not yet valid.
912 =item $SVN::Auth::SSL::EXPIRED
914 Certificate has expired.
916 =item $SVN::Auth::SSL::CNMISMATCH
918 Certificate's CN (hostname) does not match the remote hostname.
920 =item $SVN::Auth::SSL::UNKNOWNCA
922 Certificate authority is unknown (i.e. not trusted).
924 =item $SVN::Auth::SSL::OTHER
926 Other failure. This can happen if neon has introduced a new failure bit that we
933 package SVN
::Auth
::SSL
;
934 use SVN
::Base
qw(Core SVN_AUTH_SSL_);
936 package _p_svn_lock_t
;
937 use SVN
::Base
qw(Core svn_lock_t_);
941 Objects of this class contain information about locks placed on files
942 in a repository. It has the following accessor methods:
948 The full path to the file which is locked, starting with a forward slash (C</>).
952 A string containing the lock token, which is a unique URI.
956 The username of whoever owns the lock.
960 A comment associated with the lock, or undef if there isn't one.
964 True if the comment was made by a generic DAV client.
968 Time at which the lock was created, as the number of microseconds since
969 00:00:00 S<January 1>, 1970 UTC. Divide it by 1_000_000 to get a Unix
972 =item expiration_date
974 When the lock will expire. Has the value '0' if the lock will never expire.
982 '""' => sub { SVN
::Core
::md5_digest_to_cstring
(${$_[0]})};
985 my ($class, $digest) = @_;
986 bless \
$digest, $class;
991 Chia-liang Kao E<lt>clkao@clkao.orgE<gt>
995 Copyright (c) 2003 CollabNet. All rights reserved.
997 This software is licensed as described in the file COPYING, which you
998 should have received as part of this distribution. The terms are also
999 available at http://subversion.tigris.org/license-1.html. If newer
1000 versions of this license are posted there, you may use a newer version
1001 instead, at your option.
1003 This software consists of voluntary contributions made by many
1004 individuals. For exact contribution history, see the revision history
1005 and logs, available at http://subversion.tigris.org/.