Messages in this thread | | | Date | Thu, 3 Mar 2005 11:59:50 +0100 | From | Martin Waitz <> | Subject | script to send changesets per mail |
| |
hoi :)
I just tested my little script that can send changesets per mail. okok, it still had a bug when I first tested it but that should be fixed now.
If anyone is interested (perhaps for Documentation/BK-usage), here it is:
#!/usr/bin/perl -w
# after sending an announcement (created by Documentation/BK-usage/bk-make-sum) # just pipe your mail through this script. # It will create one new mail per Changeset, properly threaded.
# Copyright © 2005 Martin Waitz <tali@admingilde.org>
use strict;
my $from; my $to; my $cc; my $references;
# all local repositories are in ~/src/. # you have to adjust this function if you keep them elsewhere. sub local_repository($) { my $repo; $repo= shift;
$repo =~ s,.*/,"$ENV{HOME}/src/",e; return $repo; }
# this checks if we are allowed to send mails with this sender # please modify the regexp to check for your adress! sub check_from($) { my $from = shift;
exit 1 unless $from =~ /insert-your-email-here/; #FIXME }
# send one changeset. # Parameters: the cset number, description prefix and the actual description. sub send_cset($$$$) { my ($cset, $serial, $desc, $longdesc) = @_;
open (MAIL, "| /usr/sbin/sendmail -t") or die "fork sendmail: $!"; print MAIL "From: $from\n"; print MAIL "To: $to\n"; print MAIL "Cc: $cc\n" if $cc; print MAIL "References: $references\n" if $references; print MAIL "Subject: [PATCH $serial] $desc\n"; print MAIL "\n"; print MAIL "$desc\n"; print MAIL "$longdesc\n"; print MAIL "\n"; print MAIL `bk export -tpatch -du -r $cset`; close (MAIL) or die "could not send mail: error code $?"; }
# Parse header while (<>) { chomp; last if /^$/;
if (/^From:\s+(.+)$/i) { $from = $1; } elsif (/^To:\s+(.+)$/i) { $to = $1; } elsif (/^Cc:\s+(.+)$/i) { $cc = $1; } elsif (/^Message-Id:\s+(.+)$/i) { $references = $1; } }
my @cset; my @desc; my @longdesc;
# Parse body my $cset; while (<>) { chomp; if (/^\s+bk pull (\S+)$/) { chdir local_repository($1) || die "could not find local repository for $1\n"; } elsif (/^<\S+> \(\S+ ([\d.]+)\)$/) { # start of new ChangeSet $cset = $1; } elsif (/^ (.*)$/ && $cset) { # first line of a description unshift @cset, $cset; unshift @desc, $1; unshift @longdesc, ""; $cset = ""; } elsif (/^ (.*)$/) { # next lines of description $longdesc[0] .= "$1\n"; } }
check_from($from);
my $i; my $count; $count = scalar @cset; foreach $i (1 .. $count) { print "$desc[$i-1]\n"; send_cset($cset[$i-1], "$i/$count", $desc[$i-1], $longdesc[$i-1]); # let sendmail process the mail... sleep 3; } exit(0);
-- Martin Waitz [unhandled content-type:application/pgp-signature] | |