【转】使用svn pre-commit hook限制提交文件名为中文的文件

我知道标题很令人犯晕, 但是这样说是合理的. 今天无聊着翻了一下svn book, 于是想看一下神奇的svnlook的源码是长怎么样子的. 翻看一看, 发现了新的大陆. 原来svnlook里面定义了一个叫changed的命令, 可以查看被修改的文件的路径 相关的函数如下:
  1. subcommand_changed(apr_getopt_t *os, void *baton, apr_pool_t *pool)
  2. {
  3.   struct svnlook_opt_state *opt_state = baton;
  4.   svnlook_ctxt_t *c;
  5.   SVN_ERR(get_ctxt_baton(&c, opt_state, pool));
  6.   SVN_ERR(do_changed(c, pool));
  7.   return SVN_NO_ERROR;
  8. }
命令的说明如下:
  1. {"changed", subcommand_changed, {0},
  2.    N_("usage: svnlook changed REPOS_PATH\n\n"
  3.       "Print the paths that were changed.\n"),
  4.    {'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会根据返回值决定是否提交该事务.
  1. #!/bin/bash
  2. REPOS="$1"
  3. TXN="$2"
  4. SVNLOOK=/usr/bin/svnlook
  5. $SVNLOOK changed -t "$TXN" "$REPOS" | awk '{print $2}' | grep "[^a-zA-Z0-9._/]" > /dev/null
  6. if [ $? -eq 0 ]; then
  7.         echo "Chinese filename are not allow!" >&2
  8.         exit 1;
  9. fi
posted @ 2012-07-16 18:43  adodo1  Views(805)  Comments(0Edit  收藏  举报