基線升級---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文件,供自動腳本使用。

 


 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章