📄 client.pm
字号:
use strict;use warnings;use SVN::Core;use SVN::Wc;package SVN::Client;use SVN::Base(qw(Client svn_client_ checkout update switch add mkdir delete commit status log blame diff merge cleanup relocate revert resolved copy move revprop_set propset proplist revvprop_list export ls cat import propget uuid_from_url uuid_from_path url_from_path revprop_get revprop_list info)); =head1 NAMESVN::Client - Subversion client functions=head1 SYNOPSIS use SVN::Client; my $ctx = new SVN::Client( auth => [SVN::Client::get_simple_provider(), SVN::Client::get_simple_prompt_provider(\&simple_prompt,2), SVN::Client::get_username_provider()] ); $ctx->cat (\*STDOUT, 'http://svn.collab.net/repos/svn/trunk/README', 'HEAD'); sub simple_prompt { my $cred = shift; my $realm = shift; my $default_username = shift; my $may_save = shift; my $pool = shift; print "Enter authentication info for realm: $realm\n"; print "Username: "; my $username = <>; chomp($username); $cred->username($username); print "Password: "; my $password = <>; chomp($password); $cred->password($password); }=head1 DESCRIPTIONSVN::Client wraps the highest level of functions provided bysubversion to accomplish specific tasks in an object oriented API.Methods are similar to the functions provided by the C API andas such the documentation for it may be helpful in understandingthis interface.There are a few notable differences from the C API. Most C functioncalls take a svn_client_ctx_t pointer as the next to last parameter.The Perl method calls take a SVN::Client object as the first parameter.This allows method call invocation of the methods to be possible. Forexample, the following are equivalent: SVN::Client::add($ctx,$path, $recursive, $pool); $ctx->add($path, $recursive, $pool);Many of the C API calls also take a apr_pool_t pointer as their lastargument. The Perl bindings generally deal with this for you andyou do not need to pass a pool parameter. However, you may stillpass a pool parameter as the last parameter to override the automatichandling of this for you.Users of this interface should not directly manipulate the underlying hashvalues but should use the respective attribute methods. Many of theseattribute methods do other things, especially when setting an attribute,besides simply manipulating the value in the hash.=head1 PARAMETER NOTESThe client methods described below take a variety of parameters. Many ofthem are similar. Methods accepting parameters named below will followthe rules below or will be noted otherwise in the method description.=over 4=item $ctxAn SVN::Client object that you get from the constructor.=item $urlThis is a URL to a subversion repository. =item $pathThis is a path to a file or directory on the local file system.=item $pathsThis argument can either be a single path to a file or directory on the localfile system, or it can be a reference to an array of files or directories onthe local file system.=item $targetThis is a path to a file or directory in a working copy or a URL to a file ordirectory in a subversion repository.=item $targetsThis argument can either be a single $target (as defined above) or a referenceto an array of them.=item $revisionThis specifies a revision in the subversion repository. You can specify arevision in several ways. The easiest and most obvious is to directlyprovide the revision number. You may also use the strings (aka revisionkeywords) 'HEAD', 'BASE', 'COMMITTED', and 'PREV' which have the samemeanings as in the command line client. When referencing a working copyyou can use the string 'WORKING" to reference the BASE plus any localmodifications. undef may be used to specify an unspecified revision.Finally you may pass a date by specifying the date inside curly braces'{}'. The date formats accepted are the same as the command line clientaccepts.=item $recursive $nonrecursive.A boolean parameter that specifies if the action should follow directories. Itshould only be 1 or 0. $recursive means, 1 means to descend into directories,0 means not to. $nonrecursive has the inverse meaning.=item $poolPool is always an option parameter. If you wish to pass a pool parameter itshould be a SVN::Pool or an apr_pool_t object.=back=head1 METHODSThe following methods are available:=over 4=item $ctx = SVN::Client-E<gt>new( %options );This class method constructs a new C<SVN::Client> object and returnsa reference to it.Key/value pair arguments may be provided to set up the initial stateof the user agent. The following methods correspond to attributemethods described below: KEY DEFAULT ---------- ---------------------------------------- auth auth_baton initiated with providers that read cached authentication options from the subversion config only. cancel undef config Hash containing the config from the default subversion config file location. log_msg undef notify undef pool A new pool is created for the context.=cutsub new{ my $class = shift; my $self = bless {}, $class; my %args = @_; $self->{'ctx'} = SVN::_Client::svn_client_create_context (); if (defined($args{'auth'})) { $self->auth($args{'auth'}); } else { $self->auth([SVN::Client::get_username_provider(), SVN::Client::get_simple_provider(), SVN::Client::get_ssl_server_trust_file_provider(), SVN::Client::get_ssl_client_cert_file_provider(), SVN::Client::get_ssl_client_cert_pw_file_provider(), ]); } { my $pool_type = ref($args{'pool'}); if ($pool_type eq 'SVN::Pool' || $pool_type eq '_p_apr_pool_t') { $self->{'pool'} = $args{'pool'}; } else { $self->{'pool'} = new SVN::Pool(); } } # If we're passed a config use it, otherwise get the default # config. if (defined($args{'config'})) { if (ref($args{'config'}) eq 'HASH') { $self->config($args{'config'}); } } else { $self->config(SVN::Core::config_get_config(undef)); } if (defined($args{'notify'})) { $self->notify($args{'notify'}); } if (defined($args{'log_msg'})) { $self->log_msg($args{'log_msg'}); } if (defined($args{'cancel'})) { $self->cancel($args{'cancel'}); } return $self;}=item $ctx-E<gt>add($path, $recursive, $pool);Schedule a working copy $path for addition to the repository.$path's parent must be under revision control already, but $path is not.If $recursive is set, then assuming $path is a directory, all of itscontents will be scheduled for addition as well.Calls the notify callback for each added item.Important: this is a B<scheduling> operation. No changes will happento the repository until a commit occurs. This scheduling can beremoved with $ctx-E<gt>revert().No return.=item $ctx-E<gt>blame($target, $start, $end, \&receiver, $pool);Invoke \&receiver subroutine on each line-blame item associated with revision$end of $target, using $start as the default source of all blame.An Error will be raised if either $start or $end is undef.No return.The blame receiver subroutine receives the following arguments:$line_no, $revision, $author, $date, $line, $pool$line_no is the line number of the file (starting with 0).The line was last changed in revision number $revisionby $author on $date and the contents were $line.The blame receiver subroutine can return an svn_error_t objectto return an error. All other returns will be ignored.You can create an svn_error_t object with SVN::Error::create().=item $ctx-E<gt>cat(\*FILEHANDLE, $target, $revision, $pool);Outputs the content of the file identified by $target and $revision to theFILEHANDLE. FILEHANDLE is a reference to a filehandle. If $target is not a local path and if $revision is 'PREV' (or someother kind that requires a local path), then an error will be raised,because the desired revision can not be determined.=item $ctx-E<gt>checkout($url, $path, $revision, $recursive, $pool);Checkout a working copy of $url at $revision using $path as the root directoryof the newly checked out working copy. $revision must be a number, 'HEAD', or a date. If $revision does notmeet these requirements the $SVN::Error::CLIENT_BAD_REVISION is raised.Returns the value of the revision actually checked out of the repository.=item $ctx-E<gt>cleanup($dir, $pool);Recursively cleanup a working copy directory, $dir, finishing any incompleteoperations, removing lockfiles, etc.=item $ctx-E<gt>commit($targets, $nonrecursive, $pool);Commit files or directories referenced by target. Will use the log_msgcallback to obtain the log message for the commit.If $targets contains no paths (zero elements), then does nothing andimmediately returns without error.Calls the notify callback as the commit progresses with any of the followingactions: $SVN::Wc::Notify::Action::commit_modified,$SVN::Wc::Notify::Action::commit_added,$SVN::Wc::Notify::Action::commit_deleted,$SVN::Wc::Notify::Action::commit_replaced,$SVN::Wc::Notify::Action::commit_postfix_txdelta.Use $nonrecursive to indicate that subdirectories of directory targetsshould be ignored.Returns a svn_client_commit_info_t object. If the revision member of thecommit information object is $SVN::Core::INVALID_REVNUM and no error wasraised, then the commit was a no-op; nothing needed to be committed.=item $ctx-E<gt>copy($src_target, $src_revision, $dst_target, $pool);Copies $src_target to $dst_target.$src_target must be a file or directory under version control, or the URLof a versioned item in the repository. If $src_target is a URL,$src_revision is used to choose the revision from which to copy the$src_target. $dst_path must be a file or directory under version control,or a repository URL, existing or not.If $dst_target is a URL, immediately attempt to commit the copy actionto the repository. The log_msg callback will be called to query for a commitlog message. If the commit succeeds, return a svn_client_commit_info_tobject.If $dst_target is not a URL, then this is just a variant of $ctx-E<gt>add(),where the $dst_path items are scheduled for addition as copies. No changeswill happen to the repository until a commit occurs. This scheduling can beremoved with $ctx-E<gt>revert(). undef will be returned in this case.Calls the notify callback for each item added at the new location, passingthe new, relative path of the added item.=item $ctx-E<gt>delete($targets, $force, $pool);Delete items from a repository or working copy.If the paths in $targets are URLs, immediately attempt to commit a deletionof the URLs from the repository. The log_msg callback will be called toquery for a commit log message. If the commit succeeds, return asvn_client_commit_info_t object. Every path must belong to the samerepository.Else, schedule the working copy paths in $targets for removal from therepository. Each path's parent must be under revision control. This isjust a B<scheduling> operation. No changes will happen to the repositoryuntil a commit occurs. This scheduling can be removed with $ctx-E<gt>revert().If a path is a file it is immediately removed from the working copy. Ifthe path is a directory it will remain in the working copy but all the files,and all unversioned items it contains will be removed. If $force is not setthen this operation will fail if any path contains locally modified and/orunversioned items. If $force is set such items will be deleted.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -