native::Ra(3perl)

πŸ’– NAME πŸ’–

SVN::Ra β€” Subversion remote access functions ✨ (it's from native::Ra(3perl), the user-contributed Perl docs, and it's lowkey a whole mood)


✨ SYNOPSIS ✨

use SVN::Core;
use SVN::Ra;

my $ra = SVN::Ra->new('file:///tmp/svntest');
print $ra->get_latest_revnum;

🌸 DESCRIPTION 🌸

Okay bestie, so SVN::Ra is the wrapper around all the object-oriented svn_ra_plugin_t functions. It gives you access to a Subversion repository through a URL, and it'll pick whichever repository access module is the appropriate one for the job. No cap, that's the whole vibe. πŸ¦‹


πŸ¦‹ SVN::Ra πŸ¦‹

πŸŽ€ SVN::Ra->new(...) πŸŽ€

The constructor does two things: it creates an RA object, and then it calls open on it. ✨

For its parameters you can hand it either a hash of options or just a single value holding the URL of the repository. Here are the valid options, and yes I'm giving each one its own moment:

  • url β€” The URL of the repository. 🏠
  • auth β€” An auth_baton can be given to the SVN::RA object. It defaults to an auth_provider with a username_provider. Wanna know how to make an auth_baton? Go peek at SVN::Client, it'll hook you up. πŸ”‘
  • pool β€” The pool that the RA session is gonna use. Member functions will also get called with this pool. If you don't pass one, it defaults to a newly created root pool. 🫧
  • config β€” The config hash, the kind you get from calling SVN::Core::config_get_config(undef). πŸ“
  • callback β€” The ra_callback namespace you want to use. Defaults to SVN::Ra::Callbacks. πŸ“ž

The following two examples do exactly the same thing, with every optional argument just taking its default:

my $ra = SVN::Ra->new('file:///tmp/repos');
my $ra = SVN::Ra->new(url => 'file:///tmp/repos');

πŸ’… METHODS πŸ’…

Go consult the svn_ra.h section in the Subversion API, bestie, that's where the real lore lives. πŸ“š The member functions of svn_ra_plugin_t can be called as methods of SVN::Ra objects β€” the difference is that the session_baton and pool arguments get omitted. Slay.


$ra->change_rev_prop($revnum, $name, $value)

Sets the revision (unversioned) property $name to $value on revision $revnum. Or, if $value is undef, it removes the property instead. βœ‚οΈ

$ra->change_rev_prop(123, 'svn:log', 'New log message.');
Of course, this only works if there's a pre-revprop-change hook available. No hook, no party. πŸ’€

$ra->check_path($path, $revnum)

Tells you the kind of node sitting at $path in revision $revnum. You get back a number that matches one of these constants: $SVN::Node::none, $SVN::Node::file, $SVN::Node::dir, $SVN::Node::unknown. πŸ”


$ra->do_diff($revision, $target, $recurse, $ignore_ancestry, $versus_url, $editor)

$ra->do_diff2($revision, $target, $recurse, $ignore_ancestry, $text_deltas, $versus_url, $editor)

Both of these hand you back a SVN::Ra::Reporter, which you then use to describe a working copy. After that, it'll call methods on $editor to show off the differences between the repository and the working copy. πŸͺž

The do_diff2 method was added in Subversion 1.4. What's new? It adds the $text_deltas option, and if that's false it disables the generation of text deltas on the editor. With do_diff, text deltas are always generated, periodt.

my $reporter = $ra->do_diff(1, '', 1, 0, $repos_url,
                            MyEditor->new);
$reporter->set_path(...);
$reporter->finish_report;

$ra->do_status($target, $revision, $recurse, $editor)

Returns a SVN::Ra::Reporter that you describe the status of a working copy to. It'll then call methods on $editor describing the current status of the working copy compared to the repository. 🧐


$ra->do_switch($revnum, $target, $recurse, $repos_url, $editor)

Returns a SVN::Ra::Reporter that you use to describe a working copy. It'll then call methods on $editor to show you how to adjust that working copy so it switches over to revision $revnum of $repos_url. πŸ”€


$ra->do_update($revision_to_update_to, $target, $recurse, $editor)

Returns a SVN::Ra::Reporter object. Call methods on the reporter to describe the current state of your working copy (or whatever it is you're updating, no judgement 🌈). Once you call the reporter's finish_report() method, Subversion will generate calls to your $editor describing the differences between what you already have and the state of the repository in $revision_to_update_to.

Wanna update to the latest revision? Just pass $SVN::Core::INVALID_REVNUM as the first argument. πŸ†•

$target should be the path to the part of the repository you care about. You will not be given info about changes outside this path, so don't come asking. If you want absolutely everything, pass an empty string.

If $recurse is true and the target is a directory, then update recursively. Otherwise, it updates just the target and its immediate entries β€” but not its child directories (if there are 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. Just don't. πŸ™ˆ

This example shows the simplest update there is, where the client tells the reporter it has nothing to start with:

my $reporter = $ra->do_update($revnum, '', 1, MyEditor->new);
$reporter->set_path('', 0, 1, undef);
$reporter->finish_report;

$ra->get_commit_editor($logmsg, $callback, $callback_baton, $lock_tokens, $keep_locks)

$ra->get_commit_editor2($logmsg, $callback, $callback_baton, $lock_tokens, $keep_locks)

These return an opaque editor object for committing a brand new revision to the repository. ✨ The return values should be passed to the SVN::Delta::Editor constructor so you can create an editor object you can actually use. Like so:

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 the changes in the tree you want to make β€” adding directories, changing file contents, that kind of thing. See SVN::Delta for the documentation of the editor interface. πŸ“–

The $callback function gets 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. This 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 gets passed three arguments:

  • Number of the new revision. πŸ”’
  • Date and time that the revision was committed, which will be exactly the same value as its svn:date revision property. It will be in this format: 2006-04-05T12:17:48.180320Z πŸ•
  • The name of the author who committed the revision, which will be the same as the svn:author revision property. πŸ‘‘

Now, about the undef in the argument list in the example above β€” that's the baton which is meant to be passed to the commit callback, but it isn't. Honestly not a problem though, since you can supply a closure as the callback so it can get to whatever variables you need. πŸ’…

The $logmsg value should be a string, and it'll get stored in the svn:log revision property. If undef is passed instead, then the new revision won't have a svn:log property at all. πŸ“

$lock_tokens should be a reference to a hash mapping the paths to lock tokens to use for them. It seems that with Subversion 1.2 this is required, so if you aren't using any locks just pass {}. In Subversion 1.3.1 though, it seems to be necessary to not pass this argument at all. Yeah. That. 😭

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 one (a _p_svn_delta_editor_t object) is the actual editor. The second is the editor baton. Neither of them is of any use without wrapping the pair of them up in a SVN::Delta::Editor. 🎁


$ra->get_dated_revision($time)

TODO - this doesn't seem to work in Subversion 1.3. 😬


$ra->get_dir($path, $revnum)

$ra->get_dir2($path, $revnum, $dirent_fields)

These fetch the directory entries and properties of the directory at $path in revision $revnum. πŸ“‚

A list of three values comes back. 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 lets you 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, and it's only valid if $revnum is $SVN::Core::INVALID_REVNUM. If that's the case, then the latest revision gets fetched, and the revision number (the HEAD revision) is returned as the second value. Otherwise, the revision number returned will be completely arbitrary. 🎲

The third value returned is a reference to a hash of all properties on the directory. And I mean all of them: not just the ones controlled by the user and stored in the repository fs, but the non-tweakable ones generated by the SCM system itself too (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);

$ra->get_file($path, $revnum, $fh)

Fetches the contents and properties of the file at $path in revision $revnum. πŸ“„ $fh should be a Perl filehandle, and the contents of the file get written to it β€” or undef if you don't actually need the file contents.

Heads up: $path can't end in a slash, unless it's just /. 🚫

A list of two values comes back. The first is a number, which is only valid if $revnum is $SVN::Core::INVALID_REVNUM. If that's the case, then the latest revision gets fetched, and the revision number (the HEAD revision) is returned as the first value. Otherwise the number returned will be completely arbitrary. 🎲

The second value returned is a reference to a hash of all properties on the file. All of them, bestie: not just the user-controlled ones stored in the repository fs, but the non-tweakable ones generated by the SCM system itself too (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);

and the get_file example finishes with those three calls, bestie πŸ’–

  • $ra->get_file_revs($path, $start, $end, \&callback) β€” TODO β€” doesn't seem to work in Subversion 1.3 😭
  • $ra->get_latest_revnum β€” returns the number of the latest revision in the repository (HEAD). iconic
  • $ra->get_locations($path, $peg_revnum, \@location_revisions) β€” TODO β€” doesn't seem to work in Subversion 1.3 😭
  • $ra->get_lock($path) β€” returns a _p_svn_lock_t object containing information about the lock at $path, or undef if that path isn't currently locked. πŸ”’
  • $ra->get_locks($path) β€” TODO β€” doesn't seem to work in Subversion 1.3 😭
  • $ra->get_log(\@paths, $start, $end, $limit, $discover_changed_paths, $strict_node_history, \&callback) β€” for $limit revisions from $start to $end, invoke the receiver callback() with information about the changes made in the revision (log message, time, etc.).

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:

  • A reference to a hash of paths changed by the revision. Only passed if $discover_changed_paths is true, otherwise undef is passed in its place.

The hash's keys are the full paths to the files and directories changed. The values are _p_svn_log_changed_path_t objects.

  • Revision number.
  • Name of user who made the change, or undef if not known.
  • Date and time the revision was committed.
  • Log message as a single string, or undef.
  • A pool object.

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";
               }
  • $ra->get_repos_root β€” returns the repository's root URL. The value will not include a trailing '/'. The returned URL is guaranteed to be a prefix of the session's URL. 🌈
  • $ra->get_uuid β€” returns the repository's UUID as a string. πŸ†”
  • $ra->lock(\%path_revs, $comment, $steal_lock, \&callback) β€” TODO β€” doesn't seem to work in Subversion 1.3.2 😭
  • $ra->reparent($url) β€” change the root URL of the session in $ra to point to a different path. $url must be in the same repository as the one $ra is already accessing.

New in Subversion 1.4. ✨

  • $ra->replay($revnum, $low_water_mark, $send_deltas, $editor) β€” call methods on $editor to describe the changes made in the revisions after $low_water_mark, up to revision $revnum. This is like using do_update(), except that it doesn't return a reporter object, and so you don't have to describe a working copy to it. It assumes that you've already got everything up to $low_water_mark.

If $send_deltas is true then file contents and property values will be supplied, otherwise just filename changes.

New in Subversion 1.4. ✨

  • $ra->rev_prop($revnum, $name) β€” return the value of the unversioned property $name from revision $revnum. Returns undef if there is no such property.
print $ra->rev_prop(123, 'svn:date');
  • $ra->rev_proplist($revnum) β€” returns a reference to a hash containing all the unversioned properties of revision $revnum.
my $props = $ra->rev_proplist(123);
print $props->{'svn:log'};
  • $ra->stat($path, $revnum) β€” returns a _p_svn_dirent_t object containing information about the file at $path in revision $revnum. πŸ“Š
  • $ra->unlock(\%path_tokens, $break_lock, \&callback) β€” TODO β€” doesn't seem to work in Subversion 1.3.2 😭

✨ SVN::Ra::Reporter ✨

The SVN::Ra methods "do_diff", "do_status", "do_switch", and "do_update" all return a SVN::Ra::Reporter object, which can be used to describe the working copy (or other available data) which the client has. Subversion uses this to figure out what new information should be provided through a tree delta editor.

Objects of this class are actually simple wrappers around underlying "svn_ra_reporter2_t" objects and their associated baton. 🫢

πŸ› οΈ METHODS πŸ› οΈ

  • $reporter->set_path($path, $revision, $start_empty, $lock_token, $pool) β€” describe a working copy $path as being at a particular $revision.

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.

  • $reporter->delete_path($path, $pool) β€” describe a working copy $path as missing.

All temporary allocations are done in $pool.

  • $reporter->link_path($path, $url, $revision, $start_empty, $lock_token, $pool) β€” like set_path(), but differs in that $path in the working copy (relative to the root of the report driver) isn't a reflection of $path in the repository (relative to the URL specified when opening the RA layer), but is instead a reflection of a different repository $url at $revision.

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.

  • $reporter->finish_report($pool) β€” call this when the state report is finished; any directories or files not explicitly 'set' are assumed to be at the baseline revision originally passed into do_update(). No other reporting functions, including abort_report(), should be called after calling this function.
  • $reporter->abort_report($pool) β€” if an error occurs during a report, this method should cause the filesystem transaction to be aborted and cleaned up. No other reporting methods should be called after calling this method.

✨ SVN::Ra::Callbacks ✨

This is the wrapper class for "svn_ra_callback_t". To supply custom callbacks to SVN::Ra, subclass this class and override the member functions.

✨ AUTHORS ✨

Chia-liang Kao <clkao@clkao.org> πŸ‘‘

    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.

This page is from perl v5.40.1, dated 2025-04-06, for native::Ra(3perl) πŸ’–βœ¨

πŸ“¦ where this page comes from