use SVN::Core; use SVN::Ra; my $ra = SVN::Ra->new('file:///tmp/svntest'); print $ra->get_latest_revnum;
The following examples will both do the same thing, with all the optional arguments taking their defaults:
my $ra = SVN::Ra->new('file:///tmp/repos'); my $ra = SVN::Ra->new(url => 'file:///tmp/repos');
$ra->change_rev_prop(123, 'svn:log', 'New log message.');
Of course this will only work if there is a "pre-revprop-change" hook available.
The "do_diff2" method was added in Subversion 1.4. It adds the $text_deltas option, which if false disables the generation of text deltas on the editor. With "do_diff" text deltas are always generated.
my $reporter = $ra->do_diff(1, '', 1, 0, $repos_url, MyEditor->new); $reporter->set_path(...); $reporter->finish_report;
To update to the latest revision, pass $SVN::Core::INVALID_REVNUM for the first argument.
$target should be the path to the part of the repository you are interested in. You won't be given information about changes outside this path. If you want everything, pass an empty string.
If $recurse is true and the target is a directory, update recursively; otherwise, update just the target and its immediate entries, but not its child directories (if any).
All paths are relative to the URL used to open $ra.
The caller may not perform any RA operations using $ra before finishing the report, and may not perform any RA operations using $ra from within the editing operations of $editor.
This example shows the simplest update, where the client tells the reporter that it has nothing to start with:
my $reporter = $ra->do_update($revnum, '', 1, MyEditor->new); $reporter->set_path('', 0, 1, undef); $reporter->finish_report;
my $editor = SVN::Delta::Editor->new( $ra->get_commit_editor( "I'm going to commit some changes from within my Perl code.", \&commit_callback, undef, {}, 0));
Now that you've got your editor you can call methods on it to describe changes in the tree you want to make, such as adding directories, changing file contents, etc. See SVN::Delta for documentation of the editor interface.
The $callback function will be called during your call to the "$ed->close_edit()" method, after the commit has succeeded. It will not be called if there were no changes to commit. If you don't need it, pass undef instead of a code ref.
"get_commit_editor2" is identical to "get_commit_editor" except for the information passed to the callback function. The new version, added in Subversion 1.4, will pass the callback a single value (TODO: I can' test this, but it's probably an object or hash ref) which contains all the information. It also includes the error message from the post-commit hook script, which is not available with "get_commit_editor".
The callback for the original version will be passed three arguments:
The undef in the argument list in the example above is the baton which is meant to be passed to the commit callback, but it isn't. This isn't a problem since you can supply a closure as the callback so that it can get to whatever variables you need.
The $logmsg value should be a string which will be stored in the "svn:log" revision property. If undef is passed instead then the new revision won't have a "svn:log" property.
$lock_tokens should be a reference to a hash mapping the paths to lock tokens to use for them. I seems that with Subversion 1.2 this is required, so if you aren't using any locks simply pass "{}". In Subversion 1.3.1 though it seems to be necessary to not pass this argument at all.
If $keep_locks is true then locks on the files committed won't be released by the commit.
The "get_commit_editor()" method itself returns a list of two items, the first of which (a "_p_svn_delta_editor_t" object) is the actual editor. The second is the editor baton. Neither is of any use without wrapping the pair of them in a SVN::Delta::Editor.
A list of three values are returned. The first is a reference to a hash of directory entries. The keys are the names of all the files and directories in $path (not full paths, just the filenames). The values are _p_svn_dirent_t objects, with all their fields filled in. The third parameter to "get_dir2" allows you to select particular fields. TODO: I don't think the constants you'd use to construct the $dirent_fields value are provided in the Perl API.
The second value is a number, which is only valid if $revnum is $SVN::Core::INVALID_REVNUM. If that is the case then the latest revision will be fetched, and the revision number (the HEAD revision) will be returned as the second value. Otherwise the revision number returned will be completely arbitrary.
The third value returned will be a reference to a hash of all properties on the directory. This means all properties: not just ones controlled by the user and stored in the repository fs, but non-tweakable ones generated by the SCM system itself (e.g. 'wcprops', 'entryprops', etc).
my ($dirents, undef, $props) = $ra->get_dir('trunk/dir', 123); my ($dirents, $fetched_revnum, $props) = $ra->get_dir( 'trunk/dir', $SVN::Core::INVALID_REVNUM);
Note that $path cannot end in a slash unless it is just '/'.
A list of two values are returned. The first is a number, which is only valid if $revnum is $SVN::Core::INVALID_REVNUM. If that is the case then the latest revision will be fetched, and the revision number (the HEAD revision) will be returned as the first value. Otherwise the number returned will be completely arbitrary.
The second value returned will be a reference to a hash of all properties on the file. This means all properties: not just ones controlled by the user and stored in the repository fs, but non-tweakable ones generated by the SCM system itself (e.g. 'wcprops', 'entryprops', etc).
my (undef, $props) = $ra->get_file( 'trunk/foo', 123, undef); open my $fh, '>', 'tmp_out' or die "error opening file: $!"; my (undef, $props) = $ra->get_file( 'trunk/foo', 123, $fh); my ($fetched_revnum, $props) = $ra->get_file( 'trunk/foo', $SVN::Core::INVALID_REVNUM, $fh);
The caller may not invoke any RA operations using $ra from within the callback function. They may work in some situations, but it's not guaranteed.
The first argument can be either a single string or a reference to an array of strings. Each of these indicates a path in the repository which you are interested in. Revisions which don't change any of these paths (or files below them) will be ignored. Simply pass '' if you don't want to limit by path.
$start and $end should be revision numbers. If $start has a lower value than $end then the revisions will be produced in ascending order (r1, r2, ...), otherwise in descending order. If $start is $SVN::Core::INVALID_REVNUM then it defaults to the latest revision.
TODO - the previous sentence should also be true of $end, but doing that gets an error message in Subversion 1.3.
$limit is a number indicating the maximum number of times that the receiver "callback()" should be called. If it is 0, there will be no limit.
If $discover_changed_paths is true, then information about which changes were made to which paths is passed to "callback()".
If $strict_node_history is true, copy history will not be traversed (if any exists) when harvesting the revision logs for each path.
The callback function will be given the following arguments:
The hash's keys are the full paths to the files and directories changed. The values are _p_svn_log_changed_path_t objects.
This example prints some of the information received in a simple format, showing which paths were changed in each revision, for all revisions starting from the first:
$ra->get_log('', 1, $ra->get_latest_revnum, 0, 1, 0, \&log_callback); sub log_callback { my ($paths, $revnum, $user, $datetime, $logmsg) = @_; print "$datetime - $user - r$revnum\n"; while (my ($path, $changes) = each %$paths) { print $changes->action, " $path\n"; if ($changes->copyfrom_path) { print " from ", $changes->copyfrom_path, " r", $changes->copyfrom_rev, "\n" } } print "\n"; }
New in Subversion 1.4.
If $send_deltas is true then file contents and property values will be supplied, otherwise just filename changes.
New in Subversion 1.4.
print $ra->rev_prop(123, 'svn:date');
my $props = $ra->rev_proplist(123); print $props->{'svn:log'};
Objects of this class are actually simple wrappers around underlying "svn_ra_reporter2_t" objects and their associated baton.
If $start_empty is true and $path is a directory, the implementor should assume the directory has no entries or properties.
This will override any previous "set_path()" calls made on parent paths. $path is relative to the URL specified in "SVN::Ra->open()" or "SVN::Ra->new()".
If $lock_token is not undef, it is the lock token for $path in the WC.
All temporary allocations are done in $pool.
All temporary allocations are done in $pool.
If $start_empty is true and $path is a directory, the implementor should assume the directory has no entries or props.
If $lock_token is not undef, it is the lock token for $path in the WC.
All temporary allocations are done in $pool.
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.