#!/bin/bash export LANG="zh_CN.UTF-8" #确保中文日志显示正常,便于统计日志 REPOS="$1" TXN="$2" #限制日志长度 LENGTH=10 SVNLOOK="/usr/bin/svnlook" BLACKLIST="target build classes bin/target .* *.iml *.ipr *.iws *.class " function error_exit(){ echo -e "1.Not allowed empty log " >&2 echo -e "2.Logs must be greater than ${LENGTH} characters or chinese" >&2 exit 1 } function blacklist_exit(){ if [ ! -z "${INBLACKLIST}" ] ;then echo -e "some files in the blacklist , please cheack again !" >&2 echo -e "blacklist:\n ${BLACKLIST}" >&2 exit 1 fi } # 获取字符数量(包括换行符) TEMP_LENGTH=`${SVNLOOK} log -t "${TXN}" "${REPOS}"|sed 's/\s*$//g'|sed 's/^\s*//g'| wc --chars` # 统计换行符 TEMP_LINE=`${SVNLOOK} log -t "${TXN}" "${REPOS}"| wc --lines` # 真实字符数量 LOGMSG_LENGTH=`expr ${TEMP_LENGTH} - ${TEMP_LINE}` # 文件黑名单过滤 # 过滤文件夹 INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/target/"`" #文件夹前后必须有/,否则匹配会有误伤 blacklist_exit INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/build/"`" blacklist_exit INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/classes/"`" blacklist_exit INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/bin/target/"`" blacklist_exit # 过滤所有已点开头的文件和文件夹 INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "/\."`" blacklist_exit # 过滤文件尾缀 INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "\.iml$"`" blacklist_exit INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "\.ipr$"`" blacklist_exit INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "\.iws$"`" blacklist_exit INBLACKLIST="`${SVNLOOK} changed -t "${TXN}" "${REPOS}" | grep "\.class$"`" blacklist_exit # 判断日志长度是否满足要求 if [ "${LOGMSG_LENGTH}" -lt ${LENGTH} ];then error_exit fi exit 0