#!/usr/bin/perl -w # This is the mailing backend to the CVS commit loginfo script # example for CVSNT. Please see mail.pl and the home page for # further information. # The original author of this script is Jouni Heikniemi # Feel free to do whatever you wish with this. # The home page of this script is # . ###################################################################### # CVS loginfo format specifier '%{sVv}' produces items like # 'source.c,1.2,1.3', 'source2.c,NONE,1.1' and 'source3.c,1.5,NONE' # for change, add and remove, respectively. This method parses # those to a hash and returns a ref to it. sub createChangeItem($) { my @arr = split(',', shift); my %change; $change{'filename'} = $arr[0]; $change{'oldrev'} = $arr[1]; $change{'newrev'} = $arr[2]; if ($arr[1] eq 'NONE') { $change{'type'} = 'add'; } elsif ($arr[2] eq 'NONE') { $change{'type'} = 'rm'; } else { $change{'type'} = 'c'; } return \%change; } ## Main code: # Do a small delay so that the main CVS task finishes and # releases locks first. sleep 5; # Find out who did the changes and who shall we mail to. my $user = $ARGV[2] || $ENV{'username'} || $ENV{'USERNAME'}; my $target = $ARGV[3] || 'root@localhost'; # Manipulate the CVS's change info; see docs for further information. my @changes = split(' ', $ARGV[1]); my $changedir = $changes[0]; my @changeItems = map { createChangeItem($_) } @changes[1..$#changes]; open LOGINFO, "<$ARGV[0]"; my @loginfodata = ; close LOGINFO; unlink $ARGV[0]; # Pick up the committer's log message from the loginfo we received my @logmessage; my $islogmessage = 0; foreach $s (@loginfodata) { if ($islogmessage) { @logmessage = (@logmessage, $s); next; } if ($s =~ /^Log Message:/) { $islogmessage = 1; next; } } # Format the output my $msg = "\n\nChanges in directory $changedir:\n\n"; my $diffs; foreach $m (@changeItems) { if ($m->{'type'} eq 'add') { $msg .= "$m->{'filename'} added (r$m->{'newrev'})\n"; } elsif ($m->{'type'} eq 'rm') { $msg .= "$m->{'filename'} (r$m->{'oldrev'}) removed\n"; } else { $msg .= "$m->{'filename'} updated: $m->{'oldrev'} -> $m->{'newrev'}\n"; $diffs .= `cvs -Qf rdiff -u -r $m->{'oldrev'} -r $m->{'newrev'} $changedir/$m->{'filename'}` . "\n\n"; } } $msg .= "\n---\nLog message:\n\n" . join('',@logmessage); $msg .= "\n---\nDiffs of the changes:\n\n" . $diffs; # Send the mail. # Note: this section uses NTSendmail, but feel free to use whatever mail server you like. use NTsendmail; $ENV{'NTsendmail'} = 'your.smtp.server'; $ENV{'NTsendmail_max_tries'} = 5; my $mail = new NTsendmail; $mail->send('cvs@yourdomain.com', $target, "CVS Commits ($changedir, $user)", $msg);