How can I use Beyond Compare 3 as the diff3-cmd for svn?

前端 未结 5 1365
南笙
南笙 2021-02-14 14:24

I saw this posting which explained how to get BC3 working as the diff tool for Subversion... but what about using Beyond Compare 3 to do 3-way merge/compares?

5条回答
  •  死守一世寂寞
    2021-02-14 14:57

    Here's a Cygwin bash script that works with Subversion 1.7 for both diff-cmd and diff3-cmd

    #!/bin/bash
    # Set path to BeyondCompare
    bcomp=~/bin/bcomp;
    
    function bcerrlvl () {
        echo -en "$1\t";
    
        case $1 in
              0) echo "Success";;
              1) echo "Binary same";;
              2) echo "Rules-based same";;
             11) echo "Binary differences";;
             12) echo "Similar";;
             13) echo "Rules-based differences";;
             14) echo "Conflicts detected";;
            100) echo "Error";;
            101) echo "Conflicts detected, merge output not saved";;
              *) echo "Error";;
        esac;
    
        return $1;
    }
    
    if [ "$1" = "-u" ];
    then
        # paths
        left=$(cygpath --dos "$6");
        right=$(cygpath --dos "$7");
    
        # titles
        titleleft="$3";
        titleright="$5";
    
        # compare command
        $bcomp -title1="$titleleft" -title2="$titleright" "$left" "$right";
    
        if [ $? -gt 0 ];
        then
            bcerrlvl $?;
            exit $?;
        else
            exit 0;
        fi;
    elif [ "$1" = "-E" ];
    then
        # Get to the tenth and eleventh arguments
        shift; shift;
    
        # paths
        centre=$(cygpath --dos "$7");
        left=$(cygpath --dos "$8");
        right=$(cygpath --dos "$9");
        outext="_$(date +%s)-$RANDOM.merge";
        output="$(cygpath --dos "$8")_$outext";
    
        # titles
        titlecentre=$2;
        titleleft=$4;
        titleright=$6;
        titleoutput="Merge Output";
    
        # compare command
        $bcomp -title1="$titleleft" -title2="$titleright" -title3="$titlecentre" \
            -outputtitle="$titleoutput" -automerge -reviewconflicts \
            "$left" "$right" "$centre" "$output";
    
        if [ $? -eq 0 ];
        then
            outfile=$(cygpath --unix "$output");
            cat $outfile
            rm -f $outfile
            exit 0;
        else
            bcerrlvl $?;
            exit $?;
        fi;
    fi;
    

提交回复
热议问题