參考上一篇文章,"基線升級---merge方法分析「
1. 準備
bs_x --- 初始基線
bs_y --- 新基線
md_x --- 當前版本(帶svn信息)
2. 得到集合A
#!/bin/sh
# getA
# A = md_x - bs_x
diff -r md_x/ bs_x/ --exclude .svn --brief > .temp
grep "^Only in" .temp | sed -e 's/: /\//' > A
grep -v "^Only in" .temp | sed -e 's/ and .*$//' >> A
3. 得到集合B
#!/bin/sh
# getB
# B = bs_y - bs_x
diff -r bs_y/ bs_x/ --exclude .svn --brief > .temp
grep "^Only in" .temp | sed -e 's/: /\//' > B
grep -v "^Only in" .temp | sed -e 's/ and .*$//' >> B
4. 得到集合A-B和AB
#!/bin/bash
# here we generate shell to modify bs_y to get the merge version
echo > AB
echo > A_B
while read line #read file A
do
item=${line#*/}
#find the item in file B
temp=$(grep "${item}$" B)
# in File A not in File B
if [ -z "${temp}" ]; then
echo "################ SECTION #############################" >> A_B
echo "#${line}" >> A_B
index=${line:0:5}
if [ "$index" = "Only " ]; then
base=${line:8:4}
if [ "$base" = "bs_x" ]; then #we also need delete it
echo rm -rf \$BASEY/${item} >> A_B
elif [ "$base" = "md_x" ]; then #we also need copy it to new baseline
svn log "md_x/${item}" >> A_B
echo cp -r md_x/$item \$BASEY/$(dirname "${item}") >> A_B
else
echo "Error: uncorrect base line index"
fi
elif [ "$index" = "Files" ]; then
svn log "md_x/${item}" >> A_B
echo cp -r md_x/$item \$BASEY/$(dirname "${item}") >> A_B
else
echo "Error: uncorrect index in A-B"
fi
# Both in File A and B
else
echo "################ SECTION #############################" >> AB
echo "#${line}" >> AB
svn log "md_x/${item}" >> AB
echo vimdiff "md_x/${item}" "bs_y/${item}" >> AB
fi
done < "A"
而後逐行分析和修改AB和A-B獲得merge的腳本
對於須要手動merge的,能夠用kdiff3,而後生成overlay文件,供自動腳本使用。
shell