#!/bin/bash
export LANG="en_US.UTF-8" #确保中文日志显示正常,便于统计日志
REPOS="$1"
TXN="$2"
#限制日志长度
LENGTH=20
#exit 0
SVNLOOK="/usr/bin/svnlook"
BLACKLIST=".* *.o *.chw *.pck ~\$*"
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}`
################################## 检查变更文件 ##################################
changed_files=$(${SVNLOOK} changed -t "${TXN}" "${REPOS}")
# 文件黑名单过滤
# 过滤文件夹
#INBLACKLIST=$(echo ${changed_files} | grep "/target/"`" #文件夹前后必须有/,否则匹配会有误伤
#blacklist_exit
################################## 过滤prefix ##################################
# 过滤所有以点开头的文件和文件夹
INBLACKLIST=$(echo ${changed_files} | grep "/\.")
blacklist_exit
# 过滤所有office的临时文件
INBLACKLIST=$(echo ${changed_files} | grep "~\\$")
blacklist_exit
################################## 过滤suffix ##################################
# 过滤文件尾缀,.chw, .o, .pck
INBLACKLIST=$(echo ${changed_files} | grep "\.chw$")
blacklist_exit
INBLACKLIST=$(echo ${changed_files} | grep "\.o$")
blacklist_exit
INBLACKLIST=$(echo ${changed_files} | grep "\.pck$")
blacklist_exit
# 判断日志长度是否满足要求
if [ "${LOGMSG_LENGTH}" -lt ${LENGTH} ];then
error_exit
fi
exit 0
文章来源地址https://www.toymoban.com/news/detail-501751.html
文章来源:https://www.toymoban.com/news/detail-501751.html
到了这里,关于Linux SVN提交日志校验的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!