如何将Beyond Compare 3用作svn的diff3-cmd?

10

我看到了这篇帖子,其中解释了如何将BC3用作Subversion的差异工具...但是如何使用Beyond Compare 3来进行三方合并/比较呢?

5个回答

8
为此,创建一个名为(例如)diff3wrap.bat的批处理文件,并在SVN配置中设置您的diff3-cmd指向它。
下面的diff3wrap.bat文件将完成这项工作。它为合并输出创建一个临时文件名,并在将合并内容返回给SVN后删除它。
@ECHO OFF

SET DIFF3="C:\Program Files\BeyondCompare3\BComp.exe"

REM Subversion provides the paths we need as the last three parameters
REM These are parameters 9, 10, and 11.  
REM Suitable titles for these three panes in the merge tool are in parameters 4, 6 and 8 respectively.


REM But we have access to only nine parameters at a time, so we shift our nine-parameter window
REM twice to let us get to what we need, thus changing the effective positions of the various parameters.
REM
SHIFT
SHIFT
SET MYTITLE=%2
SET OLDTITLE=%4
SET YOURTITLE=%6
SET MINE=%7
SET OLDER=%8
SET YOURS=%9
SET OUTPUTFILE=%OLDER%_%RANDOM%.merge

REM Call BeyondCompare to perform the actual merge
REM Note we give it a temporary output file and echo the output back out for SVN to use as the merged file
%DIFF3% /lefttitle=%MYTITLE% /centertitle=%OLDTITLE% /righttitle=%YOURTITLE% /outputtitle="Merge Output" %MINE% %YOURS% %OLDER% %OUTPUTFILE% 

if NOT %errorlevel% == 0 goto :mergenotcomplete

REM Merge complete. Echo the output to stdout for SVN to pick up as the result, then throw away the temporary file

TYPE %OUTPUTFILE%
del /f /q %OUTPUTFILE%
exit 0

:mergenotcomplete
exit 1

根据SVN红皮书上的内容,这看起来是正确的...我会尽快检查并接受答案。 - oz10
我刚刚测试了一下,它可以工作(只要你将set DIFF3行替换为您的计算机正确的安装路径)。 - Patrick Johnmeyer

4
我喜欢liamf的批处理文件,但我认为它需要进行小幅调整:
我已经在命令调用中添加了 automerge 和 reviewconflicts 参数,以便在合并时如果没有冲突,则无需干预即可关闭。只有当需要查看冲突时,用户界面才会弹出。
因此,涉及到的行变成了:
%DIFF3% /automerge /reviewconflicts /lefttitle=%MYTITLE% /centertitle=%OLDTITLE% /righttitle=%YOURTITLE% /outputtitle="Merge Output" %MINE% %YOURS% %OLDER% %OUTPUTFILE% 

很好的改进...我已经将其纳入我的标准BC3合并脚本中。谢谢! - liamf

1

这是一个适用于svn 1.6的liamf脚本的Linux版本。

#!/bin/bash

MYTITLE=$4
OLDTITLE=$6
YOURTITLE=$8
MINE=$9
OLDER=${10}
YOURS=${11}
OUTPUTFILE=${MINE}.merge

/usr/bin/bcompare -solo -automerge -force -reviewconflicts -favorleft -lefttitle=$MYTITLE -centertitle=$OLDTITLE -righttitle=$YOURTITLE -outputtitle=$OUTPUTFILE $MINE $YOURS $OLDER $OUTPUTFILE

RESULT=$?

if [ $RESULT -eq 0 ] ; then
  cat $OUTPUTFILE
  exit 0
else
  exit 1
fi

1
这是一个与Subversion 1.7配合使用的Cygwin bash脚本,可用于diff-cmd和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;

1

我只有使用过BC3和TFS的经验,所以请谨慎对待我的意见。三方合并是我遇到问题的唯一功能。不止一次,我不得不手动复制和粘贴BC3中的更改来完成合并。


1
我在Windows上通过Tortoise使用BC3。我可以说,BC3做出的决策比Tortoise或SVN cli本身更加准确。我还为某些文件类型/模式创建自定义配置文件,以便覆盖默认设置。 - Mike Miller

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接