Bytes of Matrix

Simple, Powerful
  • 首页
  • RSS
  • 登入
  • 注册
  • 标签
  • 留言
  • 边栏
  • 链接
  • 星标日志

使用SVN的Hook控制Commit的文件大小、类型及代码修改行数

2008/04/06 1 Comments
在CSDN上看到一个兄弟的提问,想要控制SVN上传(确切的说应该是提交)文件的大小及类型。想起来自己在管理Bug单的时候也有经常类似审计每次提交,单个C文件的代码变更行数的需求。于是写了一个pre-commit的hook,以备忘。

原贴的地址: http://topic.csdn.net/u/20080404/15/acc7c13b-9079-4241-bcc2-fdb7a80be4a8.html?seed=1212379939

#!/bin/sh

# repot && transaction arguments
REPOS="$1"
TXN="$2"

# svnlook command
SVNLOOK=/usr/local/bin/svnlook

# file filter: we only allow commit .c && .h files.
FILTER='\.(c|h)$'

# max file size in bytes after commit.
MAX_SIZE=102400

# max change per one commit
MAX_CHANGE_LINES=50

files=$($SVNLOOK changed -t $TXN $REPOS | awk '{print $2}')

# check 
for f in $files
do
    # check file type
    if echo $f | grep -Eq $FILTER ; then
        # valid file
        :
    else
        echo "File $f is not a .h or .c file" >> /dev/stderr
        exit 1
    fi

    # check file size
    filesize=$($SVNLOOK cat -t $TXN $REPOS $f | wc -c)
    if [ $filesize -gt $MAX_SIZE ] ; then
        echo "File $f is too large (must <= $MAX_SIZE)" >> /dev/stderr
        exit 1
    fi

    # check change lines
    changelines=$($SVNLOOK diff -t $TXN $REPOS $f | grep -E '^(\+|-)' | wc -l)
    if [ $changelines -gt $MAX_CHANGE_LINES ] ; then
        echo "File $f changes too much ($changelines lines, must <= $MAX_CHANGE_LINES)" >> /dev/stderr
        exit 1
    fi
done

exit 0



pre-commit 返回非0,则commit失败。
错误信息为stderr的信息。



发现svnlook 还是很强大的,有空得好好研究研究,还有什么奇妙功能可以深入挖掘之。
我的文档 » 开源工具 svn , subversion , pre-commit , hook
引用功能被关闭了。
Leave a comment
ycj
2009/01/19 13:45
你文档中涉及的脚本是运行在linux系统中吧,
我在window下运行不了

望指教!
分页: 1/1 第一页 1 最后页
昵称 [注册]
网址
打开HTML 打开UBB 打开表情 隐藏 记住我
               
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
关于我
matrix

姓名: Matrix.Ji {嵇斌}
来自: 杭州
MSN: matrix.ji@live.com
MAIL: webmatrix.ji@gmail.com
日历
< 2009 >    < 7 >
己丑年(牛)
日 一 二 三 四 五 六
1234
567891011
12131415161718
19202122232425
262728293031
RSS feed
分类
  • 默认分类 [1] RSS
  • 我的故事 [14] RSS
  • 心情随笔 [4] RSS
  • 流水账 [6] RSS
  • 杂七杂八 [1] RSS
  • 职业生涯 [1] RSS
  • 我的相册 (Picasa)
  • Training In USA
  • 我的文档 [6] RSS
  • Linux [2] RSS
  • 开源工具 [1] RSS
  • Python [1] RSS
  • 软件测试 [2] RSS
统计
访问次数 58137
今日访问 18
日志数量 21
评论数量 10
留言数量 6
在线人数 2
搜索
最新日志
  • Ranorex Studio 测试工...
  • 使用LeakDiag 检测内存泄漏 ...
  • 使用SWIG 扩展Python
  • 入职第二个月小结 vs 工作4年多后...
  • 假如生命只剩下24小时
最新评论
  • 写的很清楚、易懂。
  • 儿童节这个版本没有加壳!可以参考一下源代...
  • 我在2.0的版本上编译了这个工具,所以生...
  • 多谢楼主,真厉害!我在安装2.1版本后,...
  • 能说详细点吗?我的怎么在配置那看不到网卡
链接
  • 默认链接组
  • Bo-Blog
  • 朋友的Blog
  • 双鱼  Pisces {成一星}
  • 灰色地带 {韩飞宇}
  • 三分之二月光下的大柏树 {胡柏}
  • 妖魔小丑 岂堪一击 胜之不武 {杜丙尧}
归档
  • 2009/07
  • 2009/06
  • 2009/05
  • 2009/04
  • 2009/03
  • 2009/02
  • 2009/01
  • 2008/12
  • 2008/11
  • 2008/10
  • 2008/09
  • 2008/08
其他
登入
注册
申请链接
RSS: 日志 | 评论
编码:UTF-8
XHTML 1.0

Top bo-blog
Copyright © Bytes of Matrix. Powered by Bo-Blog 2.1.1 ReleaseCode detection by Bug.Center.Team
浙ICP备06003702号

Theme by mg12&boy110. Valid XHTML 1.1 and CSS 3