[svn hooks]识别指定目录svn更新钩子
最近项目开发越发膨大,需要提交触发更新的目录越来越多,由于svn的钩子post-commit
是针对只要svn库有提交更新,就会触发执行,
以导致有时候提交svn的时候,要等个几秒钟的卡顿,等待svn的钩子更新,有时候还需要跨服器执行脚本,以上种种情况下来,svn就变得更加的龟速了。
针对这种坑爹事情,想出个方案,在提交的时候,针对性的检查指定目录是否有提交更新,
有调整的话才做进一步svn update
的操作,避免执行的延时
思路很简单...
core code 奉上
## update path list
## 需要挂钩子的目录,把路径写入${SVN_LIST}变量里,以;分割即可
PROJECT_SCRIPTS=/data/workspace/scripts
PROJECT_SERVER_PATH=/data/workspace/server
PROJECT_CLIENT_PATH=/data/workspace/client
PROJECT_TOOLS_DEV_PATH=/data/workspace/tools/dev
## 需要刷新的路径列表
SVN_LIST="${PROJECT_SCRIPTS};${PROJECT_SERVER_PATH};${PROJECT_CLIENT_PATH};${PROJECT_TOOLS_DEV_PATH}"
## svn update handle
UPDATE_LIST=`echo ${SVN_LIST} | sed "s/;/ /g"`
INIT_PATH=$(cd "$(dirname "$0")";pwd)
# 构建versions 目录,没有就新建一个
VERSIONS_PATH=${INIT_PATH}/versions
mkdir -p ${VERSIONS_PATH}
for each in ${UPDATE_LIST}
do
if [ -d ${each} ]; then
get_ver=$(svn log ${each} -r head:1 -l 1 | grep "r" | awk -F ' ' '{print $1}')
cd ${INIT_PATH}
## 用目录生成md5值,当做文件名,保证映射
md5file=`echo -n ${each}|md5sum|cut -d ' ' -f1`
check_file="${VERSIONS_PATH}/${md5file}"
if [ ! -f ${check_file} ]; then
echo "" > ${check_file}
fi
echo "path: ${each}"
echo "get version is ${get_ver}"
check_ver=`cat ${check_file}`
echo "check veriosn is ${check_ver}"
if [ "${get_ver}" != "${check_ver}" ]; then
#echo "${each} 版本好不相等 ==${get_ver}==${check_ver}=="
/usr/bin/svn update --username sysadmin --password `cat /data/save/svn_sysadmin_pwd` ${each}
echo ${get_ver} > ${check_file}
fi
fi
done
end. enjoy it! LOL