[Bioperl-l] cvs commit info msgs
Lars G. T. Jorgensen
larsj@diku.dk
07 Oct 2002 16:08:02 +0200
--=-=-=
This script is used by Copenhagen Perl Mongers (and does just that).
--=-=-=
Content-Disposition: attachment; filename=log.pl
#!/usr/bin/perl
#-----------------------------------------------------------------------------#
# log.pl - Tool for sending mail whenever something is committed
# $Id: log.pl,v 1.1 2001/11/27 16:29:15 mil Exp $
#-----------------------------------------------------------------------------#
#
# Usage: log.pl email_from email_to info
#
#-----------------------------------------------------------------------------#
# ENABLE_USERNAME_HACK: Enable this hack if the cvs-users are mapped to
# a common unix-user on the cvs server. If all cvs-users are also unix-users
# this hack is not needed.
$ENABLE_USERNAME_HACK = 0;
#-----------------------------------------------------------------------------#
exit 0 unless @ARGV == 3;
$email_from = shift @ARGV;
$email_to = shift @ARGV;
$info = shift @ARGV;
@changes = split / /, $info;
$module = shift @changes;
@log_lines = ();
while (<STDIN>) {
next if (1 .. /^$/); # Skip header
chomp;
push @log_lines, $_;
if (/^Log Message:$/) {
$log_start_here = @log_lines;
}
}
$msg = $log_lines[$log_start_here];
# If log-msg is '.' don't send mail. This is to enable
# developers to commit trivial stuff without mail getting
# sent. This may be an unwise thing (anything is trivial
# if you look at it a long time).
exit 0 if ($msg eq '.');
# At this point we are ready to send mail. We fork a child
# to continue with this task, so that the parent can exit
# and cvs get a chance to clear up its locks
# Also, the child takes a nap for 2 seconds to ensure cvs
# doesn't start waiting for locks and such.
exit 0 if(fork() ne 0);
sleep 2;
@changed_files=();
for $change (@changes) {
($file,$v1,$v2) = split /,/, $change;
$one_of_the_files=$file;
push @changed_files,$module."/".$file unless ($v2 eq 'NONE');
}
# Getting Author-name: The nice way only works if users are real users on
# the system. See below for an ugly hack solving this (sort of).
if (!$ENABLE_USERNAME_HACK) {
$login = (getpwuid($<))[0];
}
else {
# Now, don't look at this, kids. It's ugly as hell, but
# unless we patch CVS there is no other (easy) way to get
# the real Author of this commit
$cvsroot=$ENV{'CVSROOT'};
($serial,$user,$type,$mod,$rev,$file) =
split (/\|/, `tail -n 50 $cvsroot/CVSROOT/history | grep "$one_of_the_files\$" | tail -n 1`);
$login = $user;
# Ok, you can look again. It's over.
}
$subject = "$module ($one_of_the_files".(@changed_files>1?',...':'')."): $msg";
$debug = 1 if $msg =~ m/^-DEBUG/;
$nodiff = 1 if $msg =~ m/^-NODIFF/;
open (F, "| /usr/sbin/sendmail -oi -od -t");
print F <<STOP
From: CVS-$login <$email_from>
Reply-To: $email_from
To: $email_to
Subject: $subject
STOP
;
print F "DEBUG: $info\n" if $debug;
print F "-----------------\n";
print F "-- Log --\n";
print F "-----------------\n\n";
print F join("\n",@log_lines)."\n\n";
if (@changed_files > 0 and not $nodiff) {
print F "-----------------\n";
print F "-- Changes --\n";
print F "-----------------\n\n";
for $change (@changes) {
($file,$v1,$v2) = split /,/, $change;
print F "DEBUG: $file $v1 $v2\n" if $debug;
next if $v2 eq 'NONE'; # Skip file kills
$v1 = '0' if $v1 eq 'NONE'; # Show new files
$diffcmd = "cvs -q rdiff -u -r$v1 -r$v2 $module/$file";
print F "DEBUG: Diffing: $diffcmd\n" if $debug;
open( DIFF, "$diffcmd |");
while(<DIFF>) { print F $_; }
close DIFF ;
}
}
close F;
exit 0
--=-=-=
Aaron J Mackey <ajm6q@virginia.edu> writes:
> Can I place a vote to have the diff output *after* the normal log message,
> rather than before it?
>
> -Aaron
>
> On Sun, 6 Oct 2002, Jason Stajich wrote:
>
> > I've fixed the CVS mail messages so that they get proper To headers now
> > with the new dev.open-bio.org machine. We lost a few mails back there in
> > the switchover due to some small nuances of switching to solaris from
> > linux, but all should be behaving now.
> >
> > Additionally, I've also written a little script that is executing during
> > cvs commits so that messages to bioperl-guts will include a diff log for
> > the changes (as suggested by Tim Bunce). Let's give it a try for a month
> > or so and see if people find it helpful.
> >
> > Enjoy,
> > -jason
> >
--
Mvh|Regards, Lars
System administrator | Student
Bioinformatics Centre | Department of Computer Science
University of Copenhagen | University of Copenhagen
http://www.binf.ku.dk | http://www.diku.dk
When's the last time you used duct tape on a duct? -- Larry Wall
--=-=-=--