在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 还是很强大的,有空得好好研究研究,还有什么奇妙功能可以深入挖掘之。
by matrix | 多云 2008/04/06 22:07 | 分类: 我的文档 » 开源工具 | 评论(0) | 引用(0) | 阅读(423)
前两天研究TP(一个基于vxWorks的IPS),搞得郁闷了,却激起了对实时系统的兴趣,想研究把RTLinux。  什么是RTLinux,参见Waht is RTLinux (http://blog.jibin.net/read.php?7)  先把安装过程写下来的说。RTLinux是以Linux Kernel Patch的方式发布的,他通过巧妙的技术实现了不重写Linux内核而使得Linux支持实时的特性。根据网上的测试数据来看,在多任务的情况,RTLinux的进程切换时间要明显优于通常的Linux。  废话不多说了,讲一下安装过程:   下载rtlinux,去ftp://ftp.rtlinux-gpl.org/pub/rtlinux/下载。下载一个最近的版本,这里是 rtlinux-3.2-rc1.tar.bz2。支持内核 2.4.19 to 2.4.29。接着下载Linux Kernel,去kernel.org 找个速度快点的镜像推荐一个国内的镜像(http://www.cn.kernel.org/pub/linux/kernel/v2.4/)。   我用的是Slackware Linux 10.2,将Kernel源码和rtlinux的源码拷贝到/usr/src下解压。
tar xjvf rtlinux-3.2-rc1.tar.bz2 tar xjvf linux-kernel-2.4.28.tar.bz2
 
进入rtlinux的源码目录,创建一个指向kernel source的连接
cd rtlinux-3.2-rc1 ln -s /usr/src/linux-2.4.28/ ./linux

应用RTLinux的Patch
cd ./linux patch &ndash;p1 &lt; /usr/src/linux-2.4.28/patches/kernel_patch-2.4.28-rtl3.2-rc1

开始编译内核 (这里不详细说了)
make menuconfig   // 选择自己需要的驱动、模块等 make dep make bzImages make modules make modules_install

安装新内核
Tags: ,
by matrix | 晴 2006/07/09 13:54 | 分类: 我的文档 » Linux | 评论(1) | 引用(0) | 阅读(1590)
What is RTLinux?
Rtlinux is an operating system that allows real-time control of machinery and data from a Linux environment. RTLinux is a hard real time operating system with guaranteed response times (up to hardware limits). Many "real-time" operating systems offer " typical" response times instead. RTLinux was originally developed at the New Mexico Institute of Technology.
Response times are close to hardware limits. On a modest, reasonably configured, x86 PC a RTLinux interrupt handler will run under 10 microseconds from the moment the interrupt was asserted and a RTLinux periodic task will run worst case within 30 microseconds of its scheduled time. On better hardware, these times shrink. Of course, if you insist on bad hardware, you can make things run worse.
Programs are developed in a standard Linux environment with additional capability of connecting to real-time tasks. For example, it is easy to write a Perl script that displays data in Xwindows, responds to commands delivered over a network, and collects data from a real-time task.
RTlinux is currently used for telecommunications, robotics, video editing, and data acquisition and other applications in the field and in R&D labs.
License is an open-source license with no royalties or fees. RTLinux is an open-source kernel, released under the LGPL. The source is freely distributed.
Tags: ,
by matrix | 阴 2006/07/08 13:53 | 分类: 我的文档 » Linux | 评论(0) | 引用(0) | 阅读(1049)
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]