我知道标题很令人犯晕, 但是这样说是合理的. 今天无聊着翻了一下svn book, 于是想看一下神奇的svnlook的源码是长怎么样子的. 翻看一看, 发现了新的大陆.
原来svnlook里面定义了一个叫changed的命令, 可以查看被修改的文件的路径
相关的函数如下:
- subcommand_changed(apr_getopt_t *os, void *baton, apr_pool_t *pool)
- {
- struct svnlook_opt_state *opt_state = baton;
- svnlook_ctxt_t *c;
- SVN_ERR(get_ctxt_baton(&c, opt_state, pool));
- SVN_ERR(do_changed(c, pool));
- return SVN_NO_ERROR;
- }
命令的说明如下:
- {"changed", subcommand_changed, {0},
- N_("usage: svnlook changed REPOS_PATH\n\n"
- "Print the paths that were changed.\n"),
- {'r', 't', svnlook__copy_info} },
看一下svn的帮助, 果然有这个命令, 以前我是忽略了, 呵呵.
#svnlook changed -h
changed: usage: svnlook changed REPOS_PATH
Print the paths that were changed.
Valid options:
-r [--revision] arg : specify revision number ARG
-t [--transaction] arg : specify transaction name ARG
这个时候pre-commit的就好写好多了, 可以用任何语言都可以, 说明一下其中变量REPOS是项目仓库的路径, TXN则是这次提交的事务号名称. pre-commit返回非零表示失败, svnserve会根据返回值决定是否提交该事务.
- #!/bin/bash
- REPOS="$1"
- TXN="$2"
- SVNLOOK=/usr/bin/svnlook
- $SVNLOOK changed -t "$TXN" "$REPOS" | awk '{print $2}' | grep "[^a-zA-Z0-9._/]" > /dev/null
- if [ $? -eq 0 ]; then
- echo "Chinese filename are not allow!" >&2
- exit 1;
- fi