基线升级---merge方法实现

参考上一篇文章,"基线升级---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

相关文章
相关标签/搜索