- 2006-02-25 みんなのプロフィール
cvsのコミット時に担当者へメールを送信できれば便利ですね。
ということで、「バージョン管理システム(CVS)の導入と活用」を参考に設定してみました。
この本でのサンプルは"mailto-committers.pl"です。
なお、jcode.pl(http://mikeneko.creator.club.ne.jp/~lab/kcode/jcode.html)が必要なので、合わせてダウンロードします。
現在うちのサーバーでバージョンの異なるcvsを使っています。
1台目は「1.11.22」、2台目は「1.12.13」です。
前者では特にファイルの変更もなく使えていますが、後者で使う場合、パラメータの渡し方から違っているようです。
#あくまでも実機確認です。
手順としては以下の通りです。
あ、ちなみに、各サーバー共にSMTPサーバーとしてqmailが動いています。
1. $CVSROOT/CVSROOTをチェックアウトします。
cvs co CVSROOT
2. CVSROOTにダウンロードしたmailto-commiters.plとjcode.plを格納しました。
3. checkoutlistに以下を追加します。
===== checkoutlist ↓から =====
mailto-committers.pl unable to check out / update mailto-commiters.pl
jcode.pl unable to check out / update jcode.pl
===== checkoutlist ↑まで =====
※1カラム目は動作させるコマンドで、2カラム目以降は、1カラム目のコマンドが失敗した時のメッセージです。
jcode.plは入らないと思いますけどね。
4. loginfoに以下を追加します。
===== loginfo ↓から =====
DEFAULT perl -I$CVSROOT/CVSROOT $CVSROOT/CVSROOT/mailto-commiters.pl %{sVv} $USER aaa@bbb.ne.jp
===== loginfo ↑まで =====
1カラム目は対象のリポジトリですが、「実際のリポジトリ名」「DEFAULT」「ALL」が指定できる。
とりあえず、上記だととりあえず全リポジトリとなる。
ちなみに、%{sVv}は値に置換される。%{s}:対象ファイル %{V}:直前のリビジョン %{v}:更新後のリビジョン
5. mailto-committers.plおよびjcode.plは追加しておきます。
&nsbp;cvs add mailto-committers.pl jcode.pl
6. コミットします。
これでloginfo、checklist、mailto-committers.pl、jcode.plがコミットされます。
とバージョン「1.11.22」は問題ないですね。
しかし、バージョン「1.12.13」はいろいろと変更があって、このままではいかないんですね。
7. configに以下を追加する。
===== config ↓から =====
UseNewInfoFmtStrings=yes
===== config ↑まで =====
これが必要なのは単純に、コミットしたときにエラーが出たのでその通りにしたというだけですね。
8. loginfoを以下のように修正する。
===== loginfo ↓から =====
DEFAULT perl -I$CVSROOT/CVSROOT $CVSROOT/CVSROOT/mailto-commiters.pl "%{sVv}" $USER aaa@bbb.ne.jp
===== loginfo ↑まで =====
どこが違うかというと、%{sVv}をダブルクォートで括っているんですね。
以前のバージョンまではこの箇所はカンマ区切りで1つのパラメータとして認識していたみたいですが、このバージョンではどうもスペース区切りとなっているので、実質3つのパラメータとして渡されているようです。ですので明示的に括ってみました。
9. mailto-committers.plに細工をする。
上記の関係でカンマ区切りで取得する箇所があるのでそこを重点的に修正しました。なんだか力技ですね(^^♪
説明は後にして(書くのか?)diffを貼っつけます(syslogやbasenameは利便性のために使ってます(^^♪)。
※実際の送信者アドレスの箇所は実際の送信者アドレスに変える。
3c3
< # $Id: mailto-committers.pl.txt,v 1.1 2001/05/09 00:42:27 nishi Exp $
---
> # $Id: mailto-committers.pl,v 1.16 2010/05/17 10:36:51 ladm Exp $
8a9,10
> use Sys::Syslog;
> use File::Basename;
11,12c13,14
< $cvs = "/usr/bin/cvs";
< $rcsdiff = "/usr/bin/rcsdiff";
---
> $cvs = "/usr/local/bin/cvs";
> $rcsdiff = "/usr/local/bin/rcsdiff";
23,29c25,49
< $ARGV[0] =~ s/ - New directory//go;
< ($repository, @tmp) = split(/ /, $ARGV[0]);
< foreach $tmp (@tmp) {
< my($file, $old, $new) = split(/,/, $tmp);
< push(@files, $file);
< $old{$file} = $old;
< $new{$file} = $new;
---
> my $index = 1;
> syslog("info",sprintf("ARGV[%d]:[$_]",$index++)) for @ARGV;
> $ARGV[0] =~ s/- New directory NONE NONE//go;
> $ARGV[0] =~ s/- Imported sources NONE NONE//go;
> # とりあえず今のバージョンに合わせています。
> @tmp = split m/\s+/,$ARGV[0];
> my $index = 0;
> my $file = "";
> foreach $tmp (@tmp)
> {
> if($index eq 0)
> {
> $file = $tmp;
> push @files,$file;
> }
> elsif($index eq 1)
> {
> $old{$file} = $tmp;
> }
> elsif($index eq 2)
> {
> $new{$file} = $tmp;
> $index = -1;
> }
> $index++;
32c52
<
---
> syslog("info","ファイル数:[$files]");
50,51c70,72
<
< $header = "To: $mailaddr\n";
---
> # メール送信者を追加
> $header = "From: 実際の送信者アドレス\n";
> $header .= "To: $mailaddr\n";
76,77c97,98
< local($tmp) = @_;
< local($tt) = hex(substr($tmp, 1, 8));
---
> local($tmp2) = @_;
> local($tt) = hex(substr($tmp2, 1, 8));
102c123
< $fullname = $CVSROOT .'/'. $repository .'/'. $file;
---
> $fullname = $CVSROOT .'/'. (split /\|/,$history{$file})[3] .'/'. $file;
106a128
> syslog("info","FULLNAME:[$fullname]");
127a150,151
> openlog(basename(__FILE__),"cons,pid","user");
> syslog("info","処理を開始します。");
128a153,154
> syslog("info","処理を終了します。");
> closelog();
■コンテキストdiff形式
*** mailto-committers.pl_orig 2010-05-14 21:16:54.152420000 +0900
--- mailto-committers.pl 2010-05-18 09:12:38.881550000 +0900
***************
*** 1,15 ****
#!/usr/bin/perl
#
! # $Id: mailto-committers.pl.txt,v 1.1 2001/05/09 00:42:27 nishi Exp $
# Copyright (C) 1998 Hajime BABA. All rights reserved.
#$debug = 0;
require 'jcode.pl';
! $cvs = "/usr/bin/cvs";
! $rcsdiff = "/usr/bin/rcsdiff";
$sendmail = "/usr/sbin/sendmail";
$tail = "/usr/bin/tail";--- 1,17 ----
#!/usr/bin/perl
#
! # $Id: mailto-committers.pl,v 1.16 2010/05/17 10:36:51 ladm Exp $
# Copyright (C) 1998 Hajime BABA. All rights reserved.
#$debug = 0;
+ use Sys::Syslog;
+ use File::Basename;
require 'jcode.pl';! $cvs = "/usr/local/bin/cvs";
! $rcsdiff = "/usr/local/bin/rcsdiff";
$sendmail = "/usr/sbin/sendmail";
$tail = "/usr/bin/tail";***************
*** 20,35 ****
$CVSROOT = $ENV{'CVSROOT'};print $ARGV[0], "\n" if $debug;
! $ARGV[0] =~ s/ - New directory//go;
! ($repository, @tmp) = split(/ /, $ARGV[0]);
! foreach $tmp (@tmp) {
! my($file, $old, $new) = split(/,/, $tmp);
! push(@files, $file);
! $old{$file} = $old;
! $new{$file} = $new;
}
$files = scalar(@files);
!
shift @ARGV;
print $ARGV[0], "\n" if $debug;
$user = $ARGV[0]; # NG $user = $ENV{'USER'};
--- 22,55 ----
$CVSROOT = $ENV{'CVSROOT'};print $ARGV[0], "\n" if $debug;
! my $index = 1;
! syslog("info",sprintf("ARGV[%d]:[$_]",$index++)) for @ARGV;
! $ARGV[0] =~ s/- New directory NONE NONE//go;
! $ARGV[0] =~ s/- Imported sources NONE NONE//go;
! # とりあえず今のバージョンに合わせています。
! @tmp = split m/\s+/,$ARGV[0];
! my $index = 0;
! my $file = "";
! foreach $tmp (@tmp)
! {
! if($index eq 0)
! {
! $file = $tmp;
! push @files,$file;
! }
! elsif($index eq 1)
! {
! $old{$file} = $tmp;
! }
! elsif($index eq 2)
! {
! $new{$file} = $tmp;
! $index = -1;
! }
! $index++;
}
$files = scalar(@files);
! syslog("info","ファイル数:[$files]");
shift @ARGV;
print $ARGV[0], "\n" if $debug;
$user = $ARGV[0]; # NG $user = $ENV{'USER'};
***************
*** 47,54 ****
my($xheader_r) = "";
my($xheader_m) = "";
my(@h, $file, @tmp, $date);
!
! $header = "To: $mailaddr\n";
open(HISTORY, "$tail -$files $CVSROOT/CVSROOT/history |") || die;
@h =;
close(HISTORY);
--- 67,75 ----
my($xheader_r) = "";
my($xheader_m) = "";
my(@h, $file, @tmp, $date);
! # メール送信者を追加
! $header = "From: 実際の送信者アドレス\n";
! $header .= "To: $mailaddr\n";
open(HISTORY, "$tail -$files $CVSROOT/CVSROOT/history |") || die;
@h =;
close(HISTORY);
***************
*** 73,80 ****
}sub todate {
! local($tmp) = @_;
! local($tt) = hex(substr($tmp, 1, 8));
local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tt);
$year += 1900;
$date = sprintf("%4d/%02d/%02d %02d:%02d:%02d",
--- 94,101 ----
}sub todate {
! local($tmp2) = @_;
! local($tt) = hex(substr($tmp2, 1, 8));
local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tt);
$year += 1900;
$date = sprintf("%4d/%02d/%02d %02d:%02d:%02d",
***************
*** 99,109 ****
print(MAIL "\n");foreach $file (@files) {
! $fullname = $CVSROOT .'/'. $repository .'/'. $file;
$old = $old{$file};
$new = $new{$file};next if ($new eq 'NONE' || $old eq 'NONE');
# open(RCSDIFF, "$rcsdiff -u -kk -r$old -r$new $fullname,v 2>&1 |") || next;
# open(RCSDIFF, "$cvs -nQ rdiff -u -kk -r$old -r$new $repository/$file 2>&1 |") || next;
open(RCSDIFF, "$cvs -nQ diff -u -kk -r$old -r$new $file 2>&1 |") || next;
--- 120,131 ----
print(MAIL "\n");foreach $file (@files) {
! $fullname = $CVSROOT .'/'. (split /\|/,$history{$file})[3] .'/'. $file;
$old = $old{$file};
$new = $new{$file};next if ($new eq 'NONE' || $old eq 'NONE');
+ syslog("info","FULLNAME:[$fullname]");
# open(RCSDIFF, "$rcsdiff -u -kk -r$old -r$new $fullname,v 2>&1 |") || next;
# open(RCSDIFF, "$cvs -nQ rdiff -u -kk -r$old -r$new $repository/$file 2>&1 |") || next;
open(RCSDIFF, "$cvs -nQ diff -u -kk -r$old -r$new $file 2>&1 |") || next;
***************
*** 125,131 ****
--- 147,157 ----
}# go!
+ openlog(basename(__FILE__),"cons,pid","user");
+ syslog("info","処理を開始します。");
&main();
+ syslog("info","処理を終了します。");
+ closelog();## EOF