烹茶细论

获取svn两个版本之间的差异文件

写脚本之前搜索了一下,刚好有类似脚本,稍微修改
http://xingqiba.sinaapp.com/?p=846
原作者莫怪哈

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#2014-04
#使用方法 ./svn_diff.sh svn老版本 svn新版本 svn路径 如 ./svn_diff.sh 3025 3030 svn://svn/***
#
#home_path 定义checkout svn项目的路径,可以是临时TMP目录
#diff_dir 差异文件存放的目录
#差异文件列表 log
svn_version_old=$1
svn_version_new=$2
svn_url=$3
home_path='/tmp/svn/'
diff_dir='/tmp/svn/difference'
svn_dir_name=`basename ${svn_url}`
svn_path=${home_path}/${svn_dir_name}
log='/tmp/svn/php/svn_diff.log'
Time=`date "+%Y-%m-%d %H:%M:%S"`
echo $Time >> ${log}
echo "差异文件列表" >> ${log}
if [ ! -d "${diff_dir}/${svn_dir_name}" ] ; then
mkdir -p ${diff_dir}/${svn_dir_name}
fi
if [ ! -d "$home_path" ] ; then
mkdir -p $home_path
fi
if [ ! -f "${log}" ] ; then
touch ${log}
fi
cd $home_path
svn co -r $svn_version_new $svn_url
if [ "${svn_version_old}" -ne "${svn_version_new}" ]; then
if test -e "$diff_dir"; then
echo "已经存在差异目录"
rm -rf ${diff_dir}/*
echo "删除差异文件夹内容"
else
echo "创建差异目录"
mkdir -p ${diff_dir}
fi
echo "开始分析差异文件"
cd $home_path
diff_add_num=`svn diff -r ${svn_version_old}:${svn_version_new} $svn_dir_name --summarize --no-diff-deleted | awk '$1~/A/' |wc -l `
if [ ${diff_add_num} -ne 0 ]; then
echo "新增文件数量:$diff_add_num"
diff_add_list=`svn diff -r ${svn_version_old}:${svn_version_new} $svn_dir_name --summarize | awk '$1~/A/ {print $2}'`
for add_file in ${diff_add_list} ; do
echo ${add_file}
FILE_NAME=`basename ${add_file}`
FOLDER_NAME=`dirname ${add_file}`
if test ! -e "${diff_dir}/${FOLDER_NAME}"; then
mkdir -p ${diff_dir}/${FOLDER_NAME}
fi
cp -r ${add_file} ${diff_dir}/${FOLDER_NAME}
echo ${add_file} >> ${log}
done
set_num=1
else
echo "没有新增文件"
fi
cd $home_path
diff_num=`svn diff -r ${svn_version_old}:${svn_version_new} $svn_dir_name --summarize --no-diff-deleted | awk '$1~/M/' |wc -l`
if [ ${diff_num} -ne 0 ]; then
echo "修改文件数量:$diff_num"
diff_list=`svn diff -r ${svn_version_old}:${svn_version_new} $svn_dir_name --summarize | awk '$1~/M/ {print $2}'`
for file in ${diff_list} ; do
echo ${file}
FILE_NAME=`basename ${file}`
FOLDER_NAME=`dirname ${file}`
if test ! -e "${diff_dir}/${FOLDER_NAME}"; then
mkdir -p ${diff_dir}/${FOLDER_NAME}
fi
cp -r ${file} ${diff_dir}/${FOLDER_NAME}
echo ${file} >> ${log}
done
set_num=1
echo "结束" >> ${log}
else
echo "无文件修改"
fi
else
echo "版本号输入有误"
fi