#! /usr/bin/perl -w # mail-watchers # -- looks up the repo in the database ; # -- determines the repo's watchers ; # # -- calls 'commit-email.pl' if watchers are found ; # -- all the work is done in Repocafe.pm # # -- called from every REPO/hooks/post-commit use strict ; use Repocafe ; my $prog = substr($0,rindex($0,'/')+1) ; my $Usage = < REPO REVISION -s '[repo_name]' mail1 mail2 ... where is an optional config entry ; the default is /usr/bin/perl commit-email.pl - Normally $prog is not used by admins. ---------------------------------------- USAGE sub Usage { die "$_[0]$Usage" ; } sub Error { die "$prog: $_[0]\n" ; } sub Warn { warn "$prog: $_[0]\n" ; } # usage: &GetOptions(ARG,ARG,..) defines $opt_ID as 1 or user spec'ed value # usage: &GetOptions(\%opt,ARG,ARG,..) defines $opt{ID} as 1 or user value # ARG = 'ID' | 'ID=SPC' | 'ID:SPC' for no-arg, required-arg or optional-arg # ID = perl identifier # SPC = i|f|s for integer, fixedpoint real or string argument use Getopt::Long ; Getopt::Long::config('no_ignore_case') ; my %opt = () ; Usage('') unless GetOptions ( \%opt, qw(v q d c help) ) ; if ( $opt{help} ) { print $Usage ; exit 0 ; } Usage("Arg count\n") unless @ARGV == 3 ; my $REPO = shift ; my $REV = shift ; my $RID = shift ; my $Cafe = make_cafe ( c => $opt{c} ) ; my $conf = $Cafe -> conf ; my $serv = $conf -> www_server ; my $from = $conf -> mail_from_noreply ; my $REPO_DIR = $conf -> dir_repos ; my @PROG = split ' ', $conf -> cmd_commit_email ; my @OPTS = ( '--from', $from ) ; # $Cafe -> repos -> dmp ( -incl => [ 'TAB' ] ) if $opt{v} ; my $repo = $Cafe -> repos -> get ( $RID ) ; my $name = $repo -> repo_name ; my @wats = $repo -> watchers ; push @OPTS, '-s', "[$name]" ; my @cmd = ( @PROG, $REPO, $REV, @OPTS, @wats ) ; if ( $opt{v} ) { printf "watchers (%s)\n", join ',', @wats ; printf "(%s)\n", join ') (', @cmd ; } else { exec @cmd if @wats ; }