DiffMerge integration with Surround SCM

Support for our DiffMerge utility.

Moderator: SourceGear


Posts: 2
Joined: Tue Jun 08, 2010 1:56 pm
PostPosted: Tue Jun 08, 2010 2:07 pm
Hello:

I've recently been using DiffMerge as my diff and merge tool of choice. I use Surround SCM as my SCM tool, and I've been able to integrate DiffMerge using the following command line:

"C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe" -m --title1="source branch" --title2="merged version" --title3="local version" "%1" "%3" "%2" /result="%2"

I need to write the result back to the local branch file because that is what SCM expects when it goes to check the file back in. For example, if I use the following command line:

"C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe" --title1="source branch" --title2="merged version" --title3="local version" %1 %3 %2

Then the local file is left as it was when it was entered into DiffMerge. This results in me checking changes back into SCM that don't take into account any changes from the source branch since I started working on the file.

Now, this seems all well and good. I found a solution that actually works to integrate SCM and DiffMerge, but the problem is that when I save the merged file, it gives me the following two warnings that I must click through before it saves the file:

<filename/path>

This window was given /result: <pathname> on the command line. Saving this window will write to the above pathname instead of the file loaded. This feature is used by Vault/Fortress to locate the merge result. This file is currently open in another window. Are you sure you want to continue? (Options are Yes/No)

After choosing 'Yes', I am presented with:

The following file(s) have been changed by another application: <filename/path> Would you like to reload? (Options are Yes/No).

Is it possible to suppress these warning dialogs? I would like to use Surround SCM with DiffMerge, but these warning dialogs are fairly irritating. And, if I use a different command line, it doesn't actually write to the correct file after merging. Instead, the temp file is written to, which SCM doesn't look for when checking in the results.

Thoughts on how to overcome this situation?

Thanks!

-jwir3

Posts: 534
Joined: Tue Jun 05, 2007 11:37 am
Location: SourceGear
PostPosted: Tue Jun 08, 2010 6:19 pm
How odd. Sometimes it seems like there are just too many
different ways to combine/permute the various inputs and
result file.

From what you describe, the best option might be to write a
little bat/cmd file that takes the 3 input files from Surround SCM,
launches diffmerge.exe with the results routed to a TEMP
file, and then if diffmerge exited with 0 replace your local
version with the TEMP file. And be sure to exit from the
script with the proper exit status (so that Surround SCM
will see that you resolved or aborted the merge).

Then tell Surround SCM to use the bat file rather than
diffmerge.exe.

This is a bit of a pain, but should fix the problem.

Let me know if you have any other questions or problems
getting it to work.
j

Posts: 2
Joined: Tue Jun 08, 2010 1:56 pm
PostPosted: Fri Jun 18, 2010 9:54 am
Thanks. I'm posting the script, in case others could use it.

Code: Select all
@echo off
rem ####################################################################
rem # diffmerge-surround.bat
rem # Author: Scott Johnson <scott.johnson@gd-ais.com>
rem # Last Update: 06-16-2010
rem #
rem # This is a helper script to coordinate communication
rem # between the Sourcegear DiffMerge utility and Surround
rem # SCM.
rem #
rem # Usage: diffmerge-surround.bat source ancestor local
rem #        source: The source file from Surround
rem #        ancestor: The common ancestor of the two files
rem #        local: The local version of the file
rem ####################################################################

rem ####################################################################
rem # DiffMerge Path - You will want to change this to the location of
rem #                DiffMerge on your machine
rem ####################################################################
SET DIFFMERGE="C:\Program Files\SourceGear\DiffMerge\DiffMerge.exe"

SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS

SET PROGNAME=%0
SET source=%1
SET ancestor=%2
SET local=%3

SET argc=1
call :GetArgc %*

call :VerifyCommandLineArgs
call :SetArguments
call :GenerateTemp
call :RunThreeWayMerge
call :CheckErrors

IF DEFINED ERRORS (
   call :ReportError
   goto :eof
)

call :CopyFileBack
call :DeleteTempFile
goto :eof

endlocal

:GetArgc
   SET yca=%1
   if defined yca set /a argc+=1 & shift & goto GetArgc
   goto :eof
   
:VerifyCommandLineArgs
   IF NOT %argc% == 4 goto :DisplayUsage
   goto :eof

:SetArguments
   SET ARGVS="--title1=^"source branch^" --title2=^"merged version^" --title3=^"local version^" %1 %2 %3"
   goto :eof

:GenerateTemp
   rem Create a unique temporary file
   SET TempFile=~~%Time%
   SET TempFile=%TempFile::=%
   SET TempFile=%TempFile:.=%
   SET TempFile=%TempFile:,=%

   FOR /L %%A IN (0,1,9) DO SET TempFile=!TempFile!!Random!
   SET TempFile=%TempFile%.tmp
   IF EXIST "%TEMP%.\%TempFile%" (
      GOTO GenerateTemp
   ) ELSE (
      TYPE NUL > "%Temp%.\%TempFile%"
   )

   goto :eof

:RunThreeWayMerge
   %DIFFMERGE% -m --title1="source version" --title2="merged version" --title3="local version" "%source%" "%ancestor%" "%local%" /result="%TEMP%./%TEMPFILE%"
   goto :eof

rem if diffmerge exited with return value != 0
:CheckErrors
   IF ERRORLEVEL 1 (
      SET ERRORS=1
      Call :ReportError
   )
   
   goto :eof

:CopyFileBack
   rem copy the temp file to the original local file path
   COPY %TEMP%.\%TempFile% %local%
   Goto :eof
   
:ReportError
   echo MsgBox "DiffMerge encountered an error.  Please retry your merging of files.", 0, "DiffMerge Error" > %TEMP%\usermessage.vbs
   wscript.exe %TEMP%\usermessage.vbs
   del %TEMP%\usermessage.vbs
   goto :eof

:DisplayUsage
   echo Usage: diffmerge-surround.bat [source] [ancestor] [local]
   echo        source: The source file from Surround
   echo        ancestor: The common ancestor of the two files
   echo        local: The local version of the file
   goto :eof
   
:DeleteTempFile
   del %TEMP%.\%TempFile%
   goto :eof

Return to Support (DiffMerge)

Who is online

Users browsing this forum: No registered users and 1 guest

cron