#!/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;

In reply to Subversion(SVN) pre-commit hook by runrig

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.