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 anauth_batonto the SVN::RA object. defaults to anauth_providerwith ausername_provider. if you wanna know how to create anauth_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 callingSVN::Core::config_get_config(undef).callbackβ thera_callbacknamespace 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$rabefore finishing the report, and may not perform any RA operations using$rafrom 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:daterevision 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:authorrevision 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$pathcannot 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_tobject stuffed with info about the lock at$path, orundefif 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$limitrevisions going from$startto$end, it invokes the receivercallback()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_pathsis true, otherwiseundefis 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
undefif 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$rato point to a different path.$urlmust be in the same repository as the one$rais 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$editorto describe the changes made in the revisions after$low_water_mark, up to revision$revnum. This is like usingdo_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$namefrom revision$revnum. Returnsundefif 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_tobject containing information about the file at$pathin 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$pathas 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$pathas 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)β likeset_path(), but differs in that$pathin the working copy (relative to the root of the report driver) isn't a reflection of$pathin the repository (relative to the URL specified when opening the RA layer), but is instead a reflection of a different repository$urlat$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 intodo_update(). No other reporting functions, includingabort_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>
π COPYRIGHT π
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
- fedora 43: subversion-perl 1.15.0-2.fc43 Β· Apache-2.0
- fedora 43: subversion-perl 1.15.0-2.fc43 Β· Apache-2.0
- fedora 44: subversion-perl 1.15.0-2.fc44 Β· Apache-2.0
- fedora 44: subversion-perl 1.15.0-2.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms