‹ Version Control Setup

Integrating Simulink and Stateflow with Mercurial using SimDiff

Mercurial launches SimDiff for a model diff through extdiff, and for a file-level merge conflict through a merge tool.

To configure SimDiff for Mercurial, edit the Mercurial configuration file. On Windows the file is %USERPROFILE%/Mercurial.ini. On Linux it is $HOME/.hgrc.

Use SimDiff as an external diff tool

The extdiff extension that ships with Mercurial is the way to use an external diff tool.

SimDiff expects the left and right model paths to be prefixed with -leftModel (or -l) and -rightModel (or -r). The extdiff extension has two options. cmd.xxx names the program that will run. opts.xxx is the set of command-line options inserted between the program name and the files to diff.

  1. Create a batch file in a location you can write to, such as
"C:\Users\<username>\hg-simdiff.bat"
  1. Add this single line to the batch file. It assumes SimDiff is installed in the default location.
"C:\Program Files\EnSoft\SimDiff\simdiff4.exe" -l "%1" -r "%2"
  1. Point the simdiff command in mercurial.ini at the batch file.
[extdiff] 
cmd.simdiff = C:\Users\<username>\hg-simdiff.bat 
opts.simdiff =

The command works like hg diff:

> hg simdiff model.mdl

The custom command compares revisions of a single model file. It fails if you give it a directory.

Use SimDiff as a merge tool for Simulink model files

Change two sections: [merge-patterns] and [merge-tools].

[merge-patterns]
**.mdl = simdiff

[merge-tools]
simdiff.executable = C:\Program Files\EnSoft\SimDiff\simdiff4.exe
simdiff.args = -b $base -l $local -r $other -o $output
simdiff.binary = true
simdiff.gui = true

SimDiff then merges files with the .mdl extension, and only when there is a conflict at the file level. When a model file changed on only one branch, SimDiff does not launch.

Reference documentation

Additional instructions for TortoiseHg

By default, TortoiseHg uses the first external diff tool in the config file for Visual Diff. SimDiff diffs Simulink model files, not text files. For text files, configure another external diff tool above SimDiff, or set a different tool in the TortoiseHg global settings:

  1. Right-click an empty space in a Windows Explorer window and select TortoiseHg, then Global Settings.
  2. Select the TortoiseHg preference group on the left.
  3. For the Visual Diff Tool drop-down, choose a tool other than SimDiff, such as kdiff3.

TortoiseHg still uses SimDiff as the merge tool when the configuration file says so, because external merge tools are organized by file extension.

A terminal running hg log --graph, with five changesets including a merge of my-hello-new-output.mpl

Using another client? See Version Control Setup.