cvs: /CVSROOT commitinfo.pl loginfo.pl

From: Date: Sun, 07 May 2000 18:27:51 +0000
Subject: cvs: /CVSROOT commitinfo.pl loginfo.pl
Groups: php.dev 
Request: Send a blank email to php-dev+get-18503@lists.php.net to get a copy of this message
jimw Sun May 7 11:27:51 2000 EDT Modified files: /CVSROOT commitinfo.pl loginfo.pl Log: update commitinfo/loginfo to be perl -w/use strict clean, only put directories in the subject line, include new files in the email that is sent out, and handle branches (all these changes reflect modifications I made to use this at work, where we use CVS branches extensively) Index: CVSROOT/commitinfo.pl diff -u CVSROOT/commitinfo.pl:1.3 CVSROOT/commitinfo.pl:1.4 --- CVSROOT/commitinfo.pl:1.3 Mon May 1 15:21:25 2000 +++ CVSROOT/commitinfo.pl Sun May 7 11:27:51 2000 @@ -3,15 +3,17 @@ # <module-name> /path/to/commitinfo.pl # # Copyright (c) 1999, 2000 Sascha Schumann <sascha@schumann.cx> +use strict; -$last_file = "/var/cvs/lastdir"; +my $last_file = "/var/cvs/lastdir"; -$id = getpgrp(); +my $id = getpgrp(); -$directory = $ARGV[0]; +my $directory = $ARGV[0]; open(FC, ">$last_file.$id") || die "cannot open last file"; print FC "$directory\n"; close(FC); +# throw away STDIN so parent doesn't get SIGPIPE while(<>) { } Index: CVSROOT/loginfo.pl diff -u CVSROOT/loginfo.pl:1.20 CVSROOT/loginfo.pl:1.21 --- CVSROOT/loginfo.pl:1.20 Sun May 7 10:50:59 2000 +++ CVSROOT/loginfo.pl Sun May 7 11:27:51 2000 @@ -1,68 +1,87 @@ -#!/usr/local/bin/perl +#!/usr/local/bin/perl -w # include this script in your loginfo as: # <modulename> /path/to/loginfo.pl sender@domain recipient@domain %{sVv} # # Copyright (c) 1999, 2000 Sascha Schumann <sascha@schumann.cx> +# This makes some basic assumptions -- you are only checking +# in to a single CVS module, and you are working with a single +# branch (sticky tag). + +# This also doesn't like files or directories with spaces in them. + +use strict; + use Socket; $SIG{PIPE} = 'IGNORE'; -$last_file = "/var/cvs/lastdir"; -$summary = "/var/cvs/summary"; -$smtpserver = "127.0.0.1"; -$smtpport = 25; -$cvs = "/usr/bin/cvs"; -$cvsroot = $ENV{CVSROOT}."/"; - +my $last_file = "/var/cvs/lastdir"; +my $summary = "/var/cvs/summary"; +my $smtpserver = "127.0.0.1"; +my $smtpport = 25; +my $cvs = "/usr/bin/cvs"; +my $cvsroot = $ENV{CVSROOT}."/"; # remove double trailing slash $cvsroot =~ s/\/\/$/\//; - -$id = getpgrp(); +my $cvsusers = "$ENV{CVSROOT}CVSROOT/cvsusers"; -$mailfrom = shift; -$mailto = $mailfrom; +# get the id of this process group for use in figuring out +# whether this is the last directory with checkins or not +my $id = getpgrp(); + +# the command line looks something like this for a normal commit: +# ("user@example.com", "cvsuser", +# "module changedfile,1.1,1.2 addedfile,NONE,1.1 removedfile,1.1,NONE") +my $mailfrom = shift; +my $mailto = $mailfrom; +my $envaddr = $mailto; -$cvsuser = shift; +my $cvsuser = shift; if ($cvsuser eq "changelog") { $envaddr = "php-cvs-daily-private\@lists.php.net"; $mailto = "php-cvs-daily\@lists.php.net"; -} else { - $envaddr = $mailto; } -@args = split(" ", $ARGV[0]); -$directory = $args[0]; -shift @args; +my @args = split(" ", $ARGV[0]); +my $directory = shift @args; -open(FC, "$last_file.$id") || die "last file does not exist"; -chop($last_directory = <FC>); -close(FC); +# extract just the module name from the directory +my $module = $directory; +$module =~ s/\/.+$//; + +# bail when this is a new directory +&bail if $args[0] eq '-' && "$args[1] $args[2]" eq 'New directory'; + +# bail if this is an import +&bail if $args[0] eq '-' && $args[1] eq 'Imported'; + +# find out the last directory being processed +open FC, "$last_file.$id" + or die "last file does not exist"; +my $last_directory = <FC>; +chop $last_directory; +close FC; +# remove the cvsroot from the front +$last_directory =~ s/^$cvsroot//; +# add our changed files to the summary open(FC, ">>$summary.$id") || die "cannot open summary file"; -foreach $arg (@args) { +foreach my $arg (@args) { print FC "$directory/$arg\n"; } close(FC); -$last_directory =~ s/^$cvsroot//; - # is this script already in the last changed directory? - -exit 0 if($last_directory ne $directory); +# exit if this isn't the last directory +&bail if($last_directory ne $directory); +# get the log message and tag -- we throw away everything from STDIN +# before a line that begins with "Log Message" +my ($logmsg,$tag) = &get_log_message(); -while(<STDIN>) { - chop; - if($state eq 5) { - # Uncomment if don't want @ lines - # next if (/^@/); - $logmsg .= $_."\n"; - } - if(/^Log Message/) { $state = 5; } -} - +# now we fork off into the background and generate the email exit 0 if(fork() ne 0); $| = 1; @@ -71,20 +90,20 @@ open(FC, "<$summary.$id"); -while(<FC>) { +my (@added_files, @removed_files, @modified_files, @modified_files_info); +while (<FC>) { chop; - - ($file, $first, $last) = split(","); - if($first eq "NONE") { + my ($file, $old, $new) = split(","); + if($old eq "NONE") { push @added_files, $file; - } elsif($last eq "NONE") { + } elsif($new eq "NONE") { push @removed_files, $file; } else { push @modified_files, $file; - $diff_cmdline .= " $file"; + push @modified_files_info, [ $file, $old, $new ]; } } -close(FC); +close FC; print "Unlinking helper files\n"; @@ -95,126 +114,92 @@ print "Running rdiff\n"; -# build a diff if necessary +# build a diff (and new files) if necessary +my $diffmsg = ''; -if($diff_cmdline ne "") { - open(LOG, "$cvs -Q -n rdiff -t -u $diff_cmdline |") || die; - while(<LOG>) { $diffmsg .= $_; } +foreach my $info (@modified_files_info) { + my ($file, $old, $new) = @$info; + open(LOG, "$cvs -Qn rdiff -r $old -r $new -u $file|") || die; + while(<LOG>) { s/\r\n/\n/; $diffmsg .= $_; } close(LOG); } -print "Building commit email\n"; - -# build our email +# add the added files -sub build_list { - my(@arr) = @_; - my($curdir, $msg); - - $msg = ""; - $curdir = ""; - foreach (@arr) { - /^(.*)\/([^\/]+)$/; - $dir = $1; - $file = $2; - if($dir ne $curdir) { - $curdir = $dir; - $msg .= "\n /$curdir\t"; - $curlen = length($curdir) + 5; - } - if(($curlen + length($file)) > 70) { - $msg .= "\n ".sprintf("%-".length($curdir)."s", "")."\t"; - $curlen = length($curdir) + 5; - } - $msg .= $file." "; - $curlen += length($file) + 1; - } - - $msg .= "\n"; - - return $msg; +foreach my $file (@added_files) { + next if $file =~ /\.(gif|jpe|jpe?g|pdf|png|exe|class|tgz|tar.gz|jar)$/i + or $file !~ /\./; + $diffmsg .= "\nIndex: $file\n+++ $file\n"; + open(LOG, "$cvs -Qn checkout -p -r1.1 $file |") || die; + while(<LOG>) { s/\r\n/\n/; $diffmsg .= $_; } + close(LOG); } -sub myindent { - my($msg,$nr) = @_; - my $s = sprintf("%-$nr"."s", ""); - $msg =~ s/\n/\n$s/g; - $msg = "$s$msg"; - return $msg; -} +print "Building commit email\n"; -$msg = ""; +# build our email +my $msg = ""; if($#added_files ne -1) { $msg .= "\n Added files:"; - $list = build_list(@added_files); - $msg .= $list; - $subj .= $list; + $msg .= &build_list(@added_files); } if($#removed_files ne -1) { $msg .= "\n Removed files:"; - $list = build_list(@removed_files); - $msg .= $list; - $subj .= $list; + $msg .= &build_list(@removed_files); } if($#modified_files ne -1) { $msg .= "\n Modified files:"; - $list = build_list(@modified_files); - $msg .= $list; - $subj .= $list; -} - - -sub trim { - my($x) = @_; - $x =~ s/^\s+//; - $x =~ s/\s+$//; - return $x; + $msg .= &build_list(@modified_files); } - -$msgid = "Message-ID: <cvs$cvsuser".time()."\@cvsserver>\n"; -$cvsusers = "/repository/CVSROOT/cvsusers"; +my $dirs .= join ' ', &get_dirs(@added_files, @removed_files, @modified_files); +# replace all whitespace with real spaces, and collapse consecutive spaces +$dirs =~ s/\s+/ /g; -open(FD, $cvsusers); +my $msgid = "Message-ID: <cvs$cvsuser".time()."\@cvsserver>\n"; -while(<FD>) { - chop; - /^([a-z_]{2,}?)\s(.*)\s+([a-z0-9-\._]+@[a-z0-9-\.]+).*$/i; - $handles{$1} = [trim($2), trim($3)] if($1 ne ""); +my %handles; +if (open FD, $cvsusers) { + while(<FD>) { + chop; + /^([a-z_]{2,}?)\s(.*)\s+([a-z0-9-\._]+@[a-z0-9-\.]+).*$/i; + $handles{$1} = [trim($2), trim($3)] if($1 ne ""); + } + close(FD); } -close(FD); - +my $from; if(defined($handles{$cvsuser})) { $from = "\"".$handles{$cvsuser}[0]."\" <".$handles{$cvsuser}[1].">"; } else { $from = "$cvsuser <$mailfrom>"; } -$subj =~ s/\s/ /g; -1 while $subj =~ s/\s{2,}?/ /g; - # "Reply-to: $mailto\n". # "Date: ".localtime()."\n". -@DAYABBR = qw(Sun Mon Tue Wed Thu Fri Sat); -@MONABBR = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); +my (@DAYABBR) = qw(Sun Mon Tue Wed Thu Fri Sat); +my (@MONABBR) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); -@gmtime = gmtime(); -$rfc822date = sprintf("Date: %s, %02d %s %d %02d:%02d:%02d -0000\n", +my (@gmtime) = gmtime(); +my $rfc822date = sprintf("Date: %s, %02d %s %d %02d:%02d:%02d -0000\n", $DAYABBR[$gmtime[6]], $gmtime[3], $MONABBR[$gmtime[4]], $gmtime[5] + 1900, $gmtime[2], $gmtime[1], $gmtime[0]); + +$tag = $tag ? "($tag)" : ''; -$email = "". +no strict; # quiet warnings after here + +my $email = "". "From: $from\n". "To: $mailto\n". $msgid. $rfc822date. -"Subject: cvs:$subj\n". +"Subject: cvs: $module$tag $dirs\n". "\n". "$cvsuser\t\t".localtime()." EDT\n". "$msg". " Log:\n". -myindent($logmsg,2)."\n". +&indent($logmsg,2)."\n". "$diffmsg\n"; $email =~ s/\r//g; @@ -226,7 +211,7 @@ #print $email; -$paddr = sockaddr_in($smtpport, inet_aton($smtpserver)); +my $paddr = sockaddr_in($smtpport, inet_aton($smtpserver)); socket(SOCK, PF_INET, SOCK_STREAM, 0) || die "socket failed"; connect(SOCK, $paddr) || die "connect $smtpserver:$smtpport failed"; select(SOCK); @@ -244,3 +229,65 @@ close(SOCK); exit 0; + +sub get_log_message { + my ($logmsg, $tag); + while (<STDIN>) { + $logmsg .= $_ if defined $logmsg; + if (/^Log Message/) { $logmsg = ""; } + if (/^\s+Tag:\s+(\w+)/) { $tag = $1; } + } + return ($logmsg, $tag); +} + +sub build_list { + my(@arr) = @_; + my($curdir, $curlen, $msg); + + $msg = ""; + $curdir = ""; + foreach (@arr) { + /^(.*)\/([^\/]+)$/; + my $dir = $1; + my $file = $2; + if($dir ne $curdir) { + $curdir = $dir; + $msg .= "\n /$curdir\t"; + $curlen = length($curdir) + 5; + } + if(($curlen + length($file)) > 70) { + $msg .= "\n ".sprintf("%-".length($curdir)."s", "")."\t"; + $curlen = length($curdir) + 5; + } + $msg .= $file." "; + $curlen += length($file) + 1; + } + + $msg .= "\n"; + + return $msg; +} + +sub get_dirs { + my @files = sort @_; + my %dirs; + foreach my $file (@files) { + (my $dir = $file) =~ s#[^/]+$##; + $dir =~ s/^$module//; + $dirs{$dir} = 1; + } + return sort keys %dirs; +} + +sub indent { + my ($msg,$nr) = @_; + my $s = " " x $nr; + $msg =~ s/\n/\n$s/g; + return $s.$msg; +} + +# eat STDIN (to avoid parent getting SIGPIPE) and exit with supplied exit code +sub bail { + my @toss = <STDIN>; + exit @_; +}

« previous php.dev (#18503) next »