2014-09-18:解決Subversion edge 的hook中文亂碼問題
近期檢查SVN時發現備份好的檔案體積異常龐大。才跑2個月備份出來的大小就有4G多。仔細查詢發現很多很多IDE自動生成的二進位制檔案。。。我類個去。好吧,開發不自覺就只有強制限制了。
google的時候發現這篇文章:http://blog.csdn.net/clever101/article/details/8560833
自己動手豐衣足食。指令碼如下:
#!/bin/bash export LANG="zh_CN.UTF-8" #確保中文日誌顯示正常,便於統計日誌 REPOS="$1" TXN="$2" #限制日誌長度 LENGTH=10 SVNLOOK="/usr/local/csvn/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
PS:Subversion edge需要在高階管理中開啟hooks編碼為UTF-8,否則。會導致客戶端無法解析返回的日誌直接報錯。預設為ASCII。