Search code examples
mercurialdiffmercurial-extension

Managing a pair of files as one in Mercurial


I'm working with small binary files in Mercurial as posted.

This binary files can be dumped as text to make a diff between versions, but the problem is that the files comes in pairs (eg: Form.scx / Form.sct), and I cannot found a way to tell Mercurial to "make a snapshot" (copy to a temporary location) of the other corresponding file when I do an hg ediff.


Solution

  • As suggested by @Ryan, I ended up with a small batch previous to the diff program:

    @echo off
    set f1=%1
    set f2=%2
    ::Temporary dir created by hg to copy the snapshot file
    set tdir=%~dp1
    ::Original repository dir
    set repo=%~dp2
    ::Filename extension
    set ext=%~x1
    ::The binary files comes in pairs: scx/sct \ vcx/vct ...
    set ex2=%ext:~0,-1%t
    
    ::Check if "dumpable" extension
    echo %ext% | grep -iE "(vcx|vct|scx|sct|pjx|pjt|frx|frt)" > nul && goto DumpFile
    goto diff
    
    :DumpFile
    set f1="%tdir%\_Dump1.prg"
    set f2="%tdir%\_Dump2.prg"
    ::Get the pair file from the repository
    hg cat %repo%\%~n1%ex2% -o "%~dpn1%ex2%" -R %repo%
    
    ::Do the dump, then the diff
    MyDumpProgram.exe %1 %f1%
    MyDumpProgram.exe %2 %f2%
    goto diff
    
    :diff
    ExamDiff.exe %f1% %f2%
    pause
    

    and then config the batch in %UserProfile%\.hgrc

    [extdiff]
    cmd.ediff = d:\Utiles\diff2.bat