root@localhost[0]cvsroot00:24:19# ls CVSROOT testproj yfang testrepo
root@localhost[0]CVSROOT00:18:35# ls -a . commitinfo,v editinfo .#loginfo notify,v taginfo,v .. config .#editinfo loginfo,v passwd val-tags checkoutlist .#config editinfo,v modules rcsinfo verifymsg .#checkoutlist config,v Emptydir .#modules .#rcsinfo .#verifymsg checkoutlist,v cvswrappers file.txt,v modules,v rcsinfo,v verifymsg,v commitinfo .#cvswrappers history notify taginfo .#commitinfo cvswrappers,v loginfo .#notify .#taginfo
# 这里有三个和commit行为相关的支持文件,我现在就他们的功能和使用方法简单介绍一下:
#commitinfo
这个文件是用来检查提交文件所在的仓库和文件名列表。如果返回的是非零值,提交将失败。
#例子:
在commitinfo文件添加一行,用来针对testrepo这个项目进行检查,具体检查内容由自定义的脚本实现
^testrepo /path/to/cvs_precommit_logcheck.pl
# 这里脚本后是不需要添加参数的,程序会自动获得参数
# 如果你提交的是testproj仓库中的 file1和file2,
# 那么你自动获得的参数列表就是 /var/cvsroot/testproj file1 file2
# 接下来的事情就是你如何针对这些参数写规则了,什么情况OK,什么情况不行。
# 脚本返回非零值,这次提交就会失败。否则提交成功。
# 说明一下,所有脚本中的输出都会在客户端的console上显示,
# 所以你知道该怎么根据你的脚本类型,pl,py,sh来写警告信息了吧。
#verifymsg
这个用来检验提交时候填写的comment/log内容和格式,
比如你可以检查是否有变更描述或者严格要求comment长度大于10个字等等。
文档上说偶尔与 rcsinfo 文件(用来指定日志模板,受到很多限制,我最后根本就没用它)组合在一起使用。
# 例子:
在verifymsg文件添加一行,用来针对testrepo这个项目进行检查,具体检查内容由自定义的脚本实现
^testrepo /path/to/cvs_precommit_logcheck.pl
# 说明一下:一些文档提到要给/path/to/cvs_precommit_logcheck.pl传参数,
# 实验证明,至少现在的版本肯定是不需要的
# cvs_precommit_logcheck.pl会自动获得一个参数,
# 这个参数是一个存放当前comment/log 信息的临时文件,通常是/tmp/xxxxx
# 所以只要用脚本读取文件内容然后处理就行了。
# 警告信息的写法和commitinfo类似,不赘述。
# 脚本返回非零值,这次提交就会失败。否则提交成功。
#loginfo
在提交之后被调用。它接受日志消息及其他额外信息,并能将日志消息存储到一个文件,或者发邮件给特定的人
# s = file name
# V = old version number (pre-checkin)
# v = new version number (post-checkin)
# t = tag or branch name
#
# For example:
#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
# or
#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog
# or
#DEFAULT (echo ""; id; echo %s; date; cat) | mail -s "commit Log" yangfang@fudan.edu.cnroot@localhost[0]CVSROOT00:47:10# cat verifymsg # The "verifymsg" file is used to allow verification of logging # information. It works best when a template (as specified in the # rcsinfo file) is provided for the logging procedure. Given a # template with locations for, a bug-id number, a list of people who # reviewed the code before it can be checked in, and an external # process to catalog the differences that were code reviewed, the # following test can be applied to the code: # # Making sure that the entered bug-id number is correct. # Validating that the code that was reviewed is indeed the code being # checked in (using the bug-id number or a seperate review # number to identify this particular code set.). # # If any of the above test failed, then the commit would be aborted. # # Actions such as mailing a copy of the report to each reviewer are # better handled by an entry in the loginfo file. # # One thing that should be noted is the the ALL keyword is not # supported. There can be only one entry that matches a given # repository. ^testrepo /path/to/cvs_precommit_logcheck.pl #^.* /path/to/cvs_precommit_logcheck.pl #如果想对所有仓库生效,使用这行
#!/usr/bin/perl
# cvs_precommit_logcheck.pl
# Author: Yang Fang
# Email: yangfang@fudan.edu.cn
# Date: Apr. 15th 2009
# Description: This script will help checking the commit log format.
# Usage: Append a line to $ENV{CVSROOT}/CVSROOT/verifymsg, like
# ^testrepo PATH/TO/cvs_precommit_logcheck.pl
# This sample will affect all commit in 'testrepo'
# ^.* PATH/TO/cvs_precommit_logcheck.pl
# This sample will affect all commit in every repo
sub read_file
{
my ( $f ) = @_;
open F, "< $f" or die "Can't open $f : $!";
my @f = <F>;
close F;
return wantarray ? @f : join('',@f);
}
my $log = read_file($ARGV[0]);
# trim log
$log =~ s/^\s*//;
$log =~ s/\s*$//;
# check log format
$ok = $log =~ /^Bug\s+number\s*:.*\n
Modifier\s*:.*\n
Reviewer\s*:.*\n
Description\s*:.{10,}
/x;
unless($ok) {
$msg = "Invalid Format,comment must in the following format:\n".
"Bug number:\n".
"Modifier:\n".
"Reviewer:\n".
"Description: more than 10 characters are required\n";
die($msg);
}
exit(0);