在提交源码前检测调试代码

做 Ajax 开发最大的痛苦就是调试不易,尤其是 PHP 脚本跟远程服务器交互中的调试更是不易,还好有 FirePHP,有热心人做了 FirePHP 的 Moodle 绑定,目前这个补丁还没有提交到 CVS,所以一不小心我就把调式代码放在源码里忘了去掉,然后别的开发者 update 以后就会得到一个未定义函数错误,必须想办法避免这个错误了。

首先在 vim 配置文件中加入

match ErrorMsg /echo_fb/

这将 echo_fb 函数标记为错误,警醒我提交前要去掉。这招显然不够狠,我要是连看都不看就把 vim 关了怎么办?最有效的办法还是在提交前用 grep 搜索文件,所有有了这个 shell 脚本:

ci (){
    if [ $# -eq 0 ]; then
        echo "CVS CHECKIN: No arguments entered.";
        return 1
    else
        echo "Checking in file(s): ${@:2}";
        echo "Working ...";
        if [ "$(grep "echo_fb" ${@:2})" ]; then
            echo 'Remove debug code firstly';
        else
            cvs ci -m "\"$1\"" ${@:2}
        fi

    fi
}

这样基本就没问题了。

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>