summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrlog-parse103
1 files changed, 103 insertions, 0 deletions
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 = <F>;
+ 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 <rcsfile>\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);
+};