以 FreeBSD 6.2 为例。注意,此 mailer.conf 是 svn 自己的。而 FreeBSD 也有个 mailer.conf,参见 man mailer.conf。
Quick Install
(1) 安装 swig (ports/devel/swig13)
(2) 安装 svn,在 configure 时,会自动找系统是否安装了 swig,因此 swig 要放在前面
cd ports/devel/subversion
make install
(3) 安装 swig-py,请阅读 ports/devel/subversion/work/subversion-1.6.2/subversion/bindings/swig/INSTALL
cd ports/devel/subversion/work/subversion-1.6.2
gmake swig-py
gmake check-swig-py
gmake install-swig-py DESTDIR=/usr/local/svn-python
echo /usr/local/svn-python > /usr/local/lib/python2.5/site-packages/subversion.pth
(4) 假设建立好的仓库在 /home/svnrepos
cd /home/svnrepos/hooks
cp post-commit.tmpl post-commit
chmod +x post-commit
修改 post-commit 中最下面的几行命令为:
PATH=/usr/bin:/usr/local/bin; export PATH
/usr/local/share/subversion/hook-scripts/mailer/mailer.py commit "$REPOS" "$REV"
cp /usr/local/share/subversion/hook-scripts/mailer/mailer.conf /home/svnrepos/conf/
修改 /home/svnrepos/conf/mailer.conf:
Uncomment the line
#mail_command = /usr/sbin/sendmail
and change the line
to_addr =
[email protected]
to
to_addr = <your e-mail address> <hobbes' e-mail address> <susie's e-mail address>
配置 mailer.conf
假设svn目录结构为:
REPOS/
program/client/ 客户端代码
program/server/ 服务端代码
design/ 策划文档
那么我们可以配置:
[server]
for_paths = /program/server
to_addr = server programmers' email
commit_subject_prefix = [server]
[client]
for_paths = /program/client
to_addr = client programmers' email
commit_subject_prefix = [client]
[design]
for_paths = /design
to_addr = designers' email
commit_subject_prefix = [design]
FAQ
<1> Warning: 'post-commit' hook failed with error output:
Traceback (most recent call last):
File "/usr/share/subversion/hook-scripts/mailer/mailer.py", line 1307, in ?
sys.argv[3:3+expected_args])
File "/var/lib/python-support/python2.4/svn/core.py", line 217, in run_app
return apply(func, (_core.application_pool,) + args, kw)
File "/usr/share/subversion/hook-scripts/mailer/mailer.py", line 77, in main
messenger.generate()
File "/usr/share/subversion/hook-scripts/mailer/mailer.py", line 369, in generate
self.output.finish()
File "/usr/share/subversion/hook-scripts/mailer/mailer.py", line 275, in finish
self.pipe.tochild.close()
IOError: [Errno 32] Broken pipe
这个错误 ... 因为你没装 sendmail,嘿嘿。
<2> 都设置好了,还是没收到信。测试下:
------------------------------
imp ort subprocess, sys
cmd = ['/usr/sbin/sendmail', '-f', '
[email protected]', 'your_email']
pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, close_fds = True)
pipe.stdin.write(r'Subject: abc\n\ngood')
pipe.stdin.close()
pipe.wait()
------------------------------
看看是否正常工作了。还有留意发件人地址,有些邮件服务器会检查发件人是否合法的,sendmail
正常工作,但邮件服务器把你发出去的邮件丢弃了。
<3> 中文显示问题
mailer.py 中,邮件的编码,默认用了 utf-8,svn log 也用了 utf-8 编码,而假设我们项目代码的注释用了 gbk。则需要修改下 mailer.py 文件。比如统一转换为 gbk 编码:
# 修改邮件头
hdrs = 'From: %s\n' \
...
'Content-Type: text/plain; charset=gbk\n' \
...
# 修改log编码
mylog = repos.get_rev_prop(svn.core.SVN_PROP_REVISION_LOG) or '',
log = (mylog[0].decode('utf-8').encode('gbk'), )
da ta = _da ta(
log=log,
...
)