#!/usr/bin/perl
require SVN::Core;
require SVN::Repos;
require SVN::Fs;
require SVN::Delta;
package ChangeReceiver;
my $file_re = qr/\.txt/;
my $bad_re = qr/foo/;
our @ISA = qw(SVN::Delta::Editor);
sub add_file {
return [0, $_[1]];
}
sub open_file {
return [0, $_[1]];
}
sub apply_textdelta {
$_[1]->[0] = 1;
return;
}
sub close_file {
my ($self, $file_baton) = @_;
my ($changed, $path) = @$file_baton;
return unless $changed;
return unless $path =~ /$file_re/;
my $pool = SVN::Pool->new_default_sub;
my $stream = SVN::Fs::file_contents( $self->{txn_root}, $path, $pool
+ );
my $bytes;
my $byte_cnt = 0;
my $exit_code = 0;
my $buffer = '';
while ( $bytes = $stream->read( $buffer, $SVN::Core::STREAM_CHUNK_SI
+ZE, 0 ) ) {
if ( $buffer =~ /$bad_re/ ) {
$exit_code=1;
last;
}
$byte_cnt += $bytes;
$buffer = '';
}
$stream->close;
if ($exit_code) {
warn "Bad file: $path\n";
exit $exit_code;
}
return;
}
package main;
my ($rep, $txn) = @ARGV;
my $rep = SVN::Repos::open($rep);
my $fs = $rep->fs;
my $txn_ptr = $fs->open_txn($txn);
my $txn_root = SVN::Fs::txn_root($txn_ptr);
my $base_root = $fs->revision_root($fs_ptr, SVN::Fs::txn_base_revision
+($txn_ptr));
my $editor = ChangeReceiver->new;
$editor->{txn_root} = $txn_root; # Bad OO I know
SVN::Repos::dir_delta($base_root, '', '', $txn_root, '', $editor, sub{
+1}, 1, 1, 0, 0);
exit 0;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.