From a02b000d87c44c77f8ff1617c2d654fc8568d17a Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 4 Feb 2007 08:58:28 +0000 Subject: Add rlog-parse git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@254 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- rlog-parse | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100755 rlog-parse diff --git a/rlog-parse b/rlog-parse new file mode 100755 index 0000000..a94cbeb --- /dev/null +++ b/rlog-parse @@ -0,0 +1,103 @@ +#!/usr/bin/perl -wT + +use Rcs; +use strict; +use English; +use Data::Dumper; +use File::Basename; + +$ENV{'PATH'} = '/bin:/usr/bin'; +delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; + +my $STATEFILEPREFIX='/var/spool/rlog-parse/state-'; +my $ENVELOPE_FROM = 'XXXXXXXcommit.noreply.org'; +my $HEADER_FROM = 'XXXXXXXcommit.noreply.org'; +my $BOT_ADDRESS = 'XXXXXXXcommit.noreply.org'; +my $SENDMAIL = '/usr/sbin/sendmail'; +#my $PROJECT = 'oftc'; +#my $PROJECT = 'weasel'; + +sub clean_filename($) { + my ($file) = @_; + + my $b = basename($file); + $b =~ m/^([a-z.,-]+)$/; + my $f = $1; + die ("Evil filename $file") unless $f; + + return $f +}; +sub make_statefile($) { + my ($file) = @_; + + return $STATEFILEPREFIX.clean_filename($file); +}; + +sub read_state($) { + my ($file) = @_; + + my $sf = make_statefile($file); + my $res = open(F, "< $sf"); + if ($res) { + my $rev = ; + close(F); + chomp $rev; + return $rev; + } else { + return undef; + }; +}; + +sub update_state($$) { + my ($file, $rev) = @_; + my $sf = make_statefile($file); + open(F, "> $sf") or die ("Cannot write to $sf: $!\n"); + print F $rev,"\n"; + close(F); +}; + +sub handle_rev($$$$) { + my ($file, $rcs, $comments, $rev) = @_; + update_state($file, $rev); + + my $author = $rcs->author($rev); + my $comment = $comments->{$rev}; + my $base = basename($file); + $base =~ s/,v//; + + #open(MAIL, "|cat") or + open(MAIL, "|$SENDMAIL -t -oi -f $ENVELOPE_FROM") or + die ("Cannot exec sendmail: $!\n"); + print MAIL "From: $HEADER_FROM\n"; + print MAIL "To: $BOT_ADDRESS\n"; + print MAIL "Subject: Announce $PROJECT\n"; + print MAIL "Precedence: junk\n"; + print MAIL "\n"; + print MAIL "$author committed r$rev to $base: $comment\n"; + close(MAIL); +}; + + +die ("Usage: $PROGRAM_NAME \n") unless (scalar @ARGV == 1); +my $file = $ARGV[0]; + +my $rcs = Rcs->new($file); +my %comments = $rcs->comments; +my @revisions = reverse $rcs->revisions; + +my $old_rev = read_state($file); +if (defined $old_rev) { + my $rev; + while (defined($rev = shift @revisions)) { + last if $rev eq $old_rev; + }; + die ("Apparently did not find $old_rev in revisions\n") unless (defined $rev); +} else { + print STDERR "First ivocation. Not sending mails but creating state file\n"; + update_state($file, $revisions[-1]); + exit (0); +}; + +for my $r (@revisions) { + handle_rev($file, $rcs, \%comments, $r); +}; -- cgit v1.2.3