native::Ra(3)

πŸ’– NAME πŸ’–

SVN::Ra β€” Subversion remote access functions πŸ¦‹

okay so real quick before we get into it: this page is native::Ra(3), part of the User Contributed Perl Documentation, and it's all about letting your Perl code reach out and touch a Subversion repo over a URL. and yes bestie it's giving main character energy, let's go πŸ’…


✨ SYNOPSIS ✨

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

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

like. that's it. that's the whole vibe check 🫢


🌸 DESCRIPTION 🌸

SVN::Ra wraps all those object-oriented svn_ra_plugin_t functions for you, so you get access to a Subversion repository through a URL πŸ’« and it picks whichever repository access module is appropriate for the job. no cap, it just handles it. lowkey iconic.


πŸ‘‘ SVN::Ra πŸ‘‘

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

the constructor does two things: it makes an RA object, then it calls open on it. periodt.

its parameters are either a hash of options or a single value holding the URL of the repository. the valid options are, and I'm listing all of them because we don't skip:

  • url β€” the URL of the repository. that's it, that's the whole thing πŸ“
  • auth β€” you could hand an auth_baton to the SVN::RA object. defaults to an auth_provider with a username_provider. if you wanna know how to create an auth_baton, go check SVN::Client, bestie has the receipts πŸ“œ
  • pool β€” the pool the RA session is gonna use. member functions will also get called with this pool. defaults to a freshly created root pool ✨
  • config β€” the config hash, which you can get by calling SVN::Core::config_get_config(undef).
  • callback β€” the ra_callback namespace to use. defaults to SVN::Ra::Callbacks.

and look, these two examples do exactly the same thing, every optional argument just chilling at its default πŸ’œ:

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

πŸ”₯ METHODS πŸ”₯

go read the svn_ra.h section in the Subversion API, that's the homework πŸ“š the thing is: member functions of svn_ra_plugin_t can just be called as methods of SVN::Ra objects, with the session_baton and pool arguments omitted. you don't pass those. the object already knows. 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. two jobs, one method, we love efficiency πŸ’–

$ra->change_rev_prop(123, 'svn:log', 'New log message.');
⚠️ of course this will only work if there's a pre-revprop-change hook available. no hook, no dice, sorry bestie 😭

πŸ’… $ra->check_path($path, $revnum)

tells you what kind of node lives 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. mystery solved πŸ”

πŸ’… $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, and with it you describe a working copy. then it goes and calls methods on $editor to indicate the differences between the repository and that working copy πŸ¦‹

do_diff2 is the newer girl β€” added in Subversion 1.4 ✨ β€” and she adds the $text_deltas option, which if false disables the generation of text deltas on the editor. with plain old do_diff, text deltas are always generated. no opt-out, that's just how she is πŸ’€

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 for you to describe the status of a working copy to. then it'll call methods on $editor to describe the current status of the working copy compared to the repository. status update, but make it Subversion 🌈

πŸ’… $ra->do_switch($revnum, $target, $recurse, $repos_url, $editor)

returns a SVN::Ra::Reporter you describe a working copy to, and then it calls methods on $editor telling you how to adjust that working copy to switch it over to revision $revnum of $repos_url. glow-up, but for a working copy πŸ’«

πŸ’… $ra->do_update($revision_to_update_to, $target, $recurse, $editor)

returns a SVN::Ra::Reporter object. you call methods on the reporter to describe the current state of your working copy (or whatever it is you're updating, no judgement 🫢). after 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. chef's kiss πŸ‘‘

to update to the latest revision, pass $SVN::Core::INVALID_REVNUM as the first argument. yes literally that constant, that's the move.

$target should be the path to the part of the repository you care about. you won't be handed info about changes outside that path β€” none of that FOMO content, bestie. if you want everything, pass an empty string.

if $recurse is true and the target is a directory, it updates recursively. otherwise, it updates just the target and its immediate entries, but not its child directories (if any). know the difference, it matters πŸ’…

all paths are relative to the URL used to open $ra.

⚠️ okay this one's important: 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. that's the rule. don't test it. πŸ’€

this example shows the simplest update, 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 new revision to the repository πŸŽ€ the return values should get passed to the SVN::Delta::Editor constructor to make 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 wanna make β€” adding directories, changing file contents, whatever. 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. no pressure 🌸

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 ✨, passes the callback a single value (the docs literally say "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:

  • the number of the new revision πŸ”’
  • the date and time that the revision was committed, which will be exactly the same value as its svn:date revision property. it'll 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

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 πŸ™ˆ not a problem though, since you can supply a closure as the callback so it can get to whatever variables you need. workaround queen πŸ’…

the $logmsg value should be a string which gets stored in the svn:log revision property. if undef is passed instead, then the new revision won't have a svn:log property. gone. not there.

$lock_tokens should be a reference to a hash mapping the paths to lock tokens to use for them. seems like with Subversion 1.2 this is required, so if you aren't using any locks just pass {}. but in Subversion 1.3.1 though, it seems necessary to not pass this argument at all 😭 the lore is inconsistent, we report it as we find it.

if $keep_locks is true, then locks on the files committed won't be released by the commit. they stay. periodt πŸ”’

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, and the second is the editor baton. neither is of any use without wrapping the pair of them in a SVN::Delta::Editor. they come as a set, bestie 🫢

πŸ’… $ra->get_dated_revision($time)

TODO β€” this doesn't seem to work in Subversion 1.3. πŸ’€ that's all we've got. she's not cooperating.

πŸ’… $ra->get_dir($path, $revnum)

πŸ’… $ra->get_dir2($path, $revnum, $dirent_fields)

fetches the directory entries and properties of the directory at $path in revision $revnum. let's talk about what comes back, because it's three whole values 🎁

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." so, you know. noted πŸ“

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. don't trust it. it's not lying to you, it's just not telling you anything πŸ’€

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 (e.g. 'wcprops', 'entryprops', etc). full transparency, no secrets πŸ‘‘

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 pass undef if you don't need the file contents. your choice, no judgement πŸ“

⚠️ note that $path cannot end in a slash unless it is just '/'. that trailing slash is not it, bestie.

a list of two values comes back. the first 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 first value. otherwise, the number returned will be completely arbitrary. same energy as get_dir, same warning 😭

the second value returned is a reference to a hash of all properties on the file. again, 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 (e.g. 'wcprops', 'entryprops', etc). 🌈


✨ and that's part 1, bestie β€” more is coming, don't go anywhere ✨

               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);
  • $ra->get_file_revs($path, $start, $end, \&callback) β€” TODO - doesn't seem to work in Subversion 1.3 😭 (yes bestie, it's giving broken, that's literally what it says)
  • $ra->get_latest_revnum β€” hands you the number of the latest revision in the repository (HEAD). that's the freshest one πŸ’…
  • $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 stuffed with info about the lock at $path, or undef if that path isn't currently locked. no lock, no tea πŸ«–
  • $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 going from $start to $end, it invokes the receiver callback() with all the info about the changes made in that revision (log message, time, etc.). the whole receipts, basically ✨
⚠️ real talk: the caller may not invoke any RA operations using $ra from inside the callback function. They may work in some situations, but it's not guaranteed. don't risk it bestie.

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. (path filter off, we're seeing everything 🌈)

$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. πŸ˜” so close

$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. (zero = unlimited, iconic behaviour ngl πŸ‘‘)

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 / (so don't go adding one, she's already perfect πŸ’…). 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. her social security number but make it ✨unique✨
  • $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. no jumping repos, she's monogamous 🫢

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. (deltas on = full tea, deltas off = just the headlines πŸ“°)

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. the whole vibe, itemised πŸŽ€
               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. like a lil character sheet for one file 🧚
  • $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. so like, she's the messenger telling svn what you already have so it only sends the new stuff πŸ¦‹

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. (empty. nothing. zero. ghost town πŸ‘»)

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. it's not here bestie, she's gone πŸ’¨

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. it's giving borrowed from another house 🏠

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. that's it, we're done, curtain call 🎭
  • $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. no take-backs, no follow-ups 🚫

πŸ¦‹ 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. DIY energy, go off πŸ’–

✨ 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.

and that's the whole page bestie, we ate and left no crumbs πŸ“ this was native::Ra(3) from perl v5.42.3, dated 2026-10-16 β€” screenshot it, bookmark it, tattoo it, whatever, just know your RA layer now. mwah πŸ’‹πŸ’œ

πŸ“¦ where this page comes from