Documentation

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

Set Up SVN Source Control

Set Up SVN Integration Provided with Simulink Project

Simulink® Project provides Built-In SVN Integration for use with Subversion® (SVN) sandboxes and repositories at version 1.8. You do not need to install SVN to use this integration because it includes an implementation of SVN.

Note

This integration ignores any existing SVN installation.

The Built-In SVN Integration supports secure logins.

To use the version of SVN provided with Simulink Project, when you add a project to source control or retrieve from source control, select Built-In SVN Integration in the Source control integration list. For instructions, see

Caution

Place your project sandbox folder on a local hard disc. Using a network folder with SVN is slow and unreliable. If you use a Windows® network drive, SVN move operations can result in incorrect "not existing" status for files visible in file browsers.

When you create a new sandbox using the Simulink Project Built-In SVN Integration, the new sandbox uses the latest version of SVN provided by Simulink Project.

When your project is under source control, you can use these project features:

You can check out from a branch, but the project Built-In SVN Integration does not support branch merging. Use an external tool such as TortoiseSVN to perform branch merging. You can use the project tools for comparing and merging by configuring TortoiseSVN to generate an XML comparison report when you perform a diff on model files. See Merge Simulink Models from the Comparison Report.

Set Up SVN Integration for SVN Version Already Installed

If you want to use Simulink Project with an earlier SVN version you already have installed, create a new project in a folder already under SVN source control. The project detects SVN.

For example:

  1. Create the sandbox using TortoiseSVN from Windows Explorer.

  2. Use Simulink Project to create a new project in that folder. The project detects the existing source control. If the sandbox is version 1.6, for example, it remains a version 1.6 sandbox.

Note

Before using source control, you must register model files with the tools. See Register Model Files with Subversion.

Set Up SVN Integration for SVN Version Not Yet Provided with Simulink Project

If you need to use a later version of SVN than 1.8, you can use Command-Line SVN Integration (compatibility mode), but you must also install a command-line SVN client.

Note

Select Command-Line SVN Integration (compatibility mode) only if you need to use a later version of SVN than 1.8. Otherwise, use Built-In SVN Integration instead, for more features, improved performance, and no need to install an additional command-line SVN client.

Command-line SVN integration communicates with any Subversion (SVN) client that supports the command-line interface.

  1. Install an SVN client that supports the command-line interface.

    Note

    TortoiseSVN does not support the command-line interface unless you choose the option to install command-line tools. Alternatively, you can continue to use TortoiseSVN from Windows Explorer after installing another SVN client that supports the command-line interface. Ensure that the major version numbers match, for example, both clients are SVN 1.7.

    You can find Subversion clients on this Web page:

  2. In Simulink Project, select Command-Line SVN Integration (compatibility mode).

With Command-Line SVN Integration (compatibility mode), if you try to rename a file in a project and the folder name contains an @ character, an error appears because command-line SVN treats all characters after the @ symbol as a peg revision value.

Tip

You can check for updated source control integration downloads on the Simulink Projects Web page: https://www.mathworks.com/discovery/simulink-projects.html

Register Model Files with Subversion

You must register model files if you use SVN, including the Built-In SVN Integration provided by Simulink Project.

If you do not register your model file extension as binary, SVN might add annotations to conflicted Simulink files and attempt automerge. This corrupts model files so you cannot load the models in Simulink.

To avoid this problem when using SVN, register file extensions.

  1. Locate your SVN config file. Look for the file in these locations:

    • C:\Users\myusername\AppData\Roaming\Subversion\config or C:\Documents and Settings\myusername\Application Data\Subversion\config on Windows

    • In ~/.subversion on Linux® or Mac OS X

  2. If you do not find a config file, create a new one. See Create SVN Config File.

  3. If you find an existing config file, you have previously installed SVN. Edit the config file. See Update Existing SVN Config File.

Create SVN Config File

  1. If you do not find an SVN config file, create a text file containing these lines:

    [miscellany]
    enable-auto-props = yes
    [auto-props]
    *.mdl = svn:mime-type=application/octet-stream
    *.mat = svn:mime-type=application/octet-stream 
    *.slx = svn:mime-type= application/octet-stream
    *.mlx = svn:mime-type=application/octet-stream
  2. Check for other file types you use in your projects that you also need to register as binary to avoid corruption at check-in. Check for files such as .mat, .mdlp, .slxp, .p, MEX-files (.mexa64, .mexmaci64, , .mexw64), .xlsx, .jpg, .pdf, .docx, etc. Add a line to the attributes file for each file type you need. Examples:

    *.mdlp  = svn:mime-type=application/octet-stream
    *.slxp  = svn:mime-type=application/octet-stream
    *.sldd  = svn:mime-type=application/octet-stream
    *.p  = svn:mime-type=application/octet-stream
    *.mexa64  = svn:mime-type=application/octet-stream
    *.mexw64  = svn:mime-type=application/octet-stream
    *.mexmaci64  = svn:mime-type=application/octet-stream
    *.xlsx  = svn:mime-type=application/octet-stream
    *.docx  = svn:mime-type=application/octet-stream
    *.pdf  = svn:mime-type=application/octet-stream
    *.jpg  = svn:mime-type=application/octet-stream
    *.png  = svn:mime-type=application/octet-stream
  3. Name the file config and save it in the appropriate location:

    • C:\Users\myusername\AppData\Roaming\Subversion\config or C:\Documents and Settings\myusername\Application Data\Subversion\config on Windows

    • ~/.subversion on Linux or Mac OS X

After you create the SVN config file, SVN treats new model files as binary.

If you already have models in repositories, see Register Models Already in Repositories.

Update Existing SVN Config File

If you find an existing config file, you have previously installed SVN. Edit the config file to register files as binary.

  1. Edit the config file in a text editor.

  2. Locate the [miscellany] section, and verify the following line enables auto-props with yes:

    enable-auto-props = yes 
    Ensure that this line is not commented (that is, that it does not start with a #). Config files can contain example lines that are commented out. If there is a # character at the beginning of the line, delete it.

  3. Locate the [auto-props] section. Ensure that [auto-props] is not commented. If there is a # character at the beginning, delete it.

  4. Add the following lines at the end of the [auto-props] section:

    *.mdl = svn:mime-type= application/octet-stream
    *.mat = svn:mime-type=application/octet-stream 
    *.slx = svn:mime-type= application/octet-stream
    *.mlx = svn:mime-type=application/octet-stream
    These lines prevent SVN from adding annotations to MATLAB® and Simulink files on conflict and from automerging.

  5. Check for other file types you use in your projects that you also need to register as binary to avoid corruption at check-in. Check for files such as .mat, .mdlp, .slxp, .p, MEX-files (.mexa64, .mexmaci64, .mexw64), .xlsx, .jpg, .pdf, .docx, etc. Add a line to the config file for each file type you need.

    Examples:

    *.mdlp  = svn:mime-type=application/octet-stream
    *.slxp  = svn:mime-type=application/octet-stream
    *.sldd  = svn:mime-type=application/octet-stream
    *.p  = svn:mime-type=application/octet-stream
    *.mexa64  = svn:mime-type=application/octet-stream
    *.mexw64  = svn:mime-type=application/octet-stream
    *.mexmaci64  = svn:mime-type=application/octet-stream
    *.xlsx  = svn:mime-type=application/octet-stream
    *.docx  = svn:mime-type=application/octet-stream
    *.pdf  = svn:mime-type=application/octet-stream
    *.jpg  = svn:mime-type=application/octet-stream
    *.png  = svn:mime-type=application/octet-stream
  6. Save the config file.

After you create or update the SVN config file, SVN treats new model files as binary.

If you already have models in repositories, register them as described next.

Register Models Already in Repositories

Caution

Changing your SVN config file does not affect model files already committed to an SVN repository. If a model is not registered as binary, use svn propset to manually register models as binary.

To manually register a file in a repository as binary, use the following command with command-line SVN:

svn propset svn:mime-type application/octet-stream modelfilename
If you need to install a command-line SVN client, see Set Up SVN Integration for SVN Version Not Yet Provided with Simulink Project.

Enforce SVN Locking Model Files Before Editing

To ensure users remember to get a lock on model files before editing, you can configure SVN to make specified file extensions read only. To locate your SVN config file, see Register Model Files with Subversion.

After this setup, SVN sets model files to read only when you open the project, so you need to select Source Control > Get File Lock before you can edit them. Doing so helps prevent editing of models without getting the file lock. When the file has a lock, other users know the file is being edited, and you can avoid merge issues.

  1. To make SLX files read only, add a property to your SVN config file. Find this line in the [auto-props] section that registers slx files as binary:

    *.slx = svn:mime-type= application/octet-stream
    

  2. Add the needs-lock property to the end of the existing slx line, separated by a semicolon, so the line looks like this:

    *.slx = svn:mime-type=application/octet-stream;svn:needs-lock=yes 
    You can combine properties in any order, but multiple entries (e.g., for slx) must be on a single line separated by semicolons.

  3. Recreate the sandbox for the config to take effect.

  4. You need to select Get File Lock before you can edit model files. See Get SVN File Locks.

If you need to resolve merge issues, see Resolve Conflicts.

Share a Subversion Repository

You can specify a repository location using the file:// protocol. However, Subversion documentation strongly recommends only single users access a repository directly via file:// URLs. See the Web page:

Caution

Do not allow multiple users to access a repository directly via file:// URLs or you risk corrupting the repository. Use file:// URLs only for single-user repositories.

Be aware of this caution with these workflows:

  • If you specify a repository with a file:// URL, or

  • If you use Simulink Projects to create a repository, this uses the file:// protocol. Creating new repositories is provided for local single-user access only, for testing and debugging.

Also, accessing a repository via file:// URLs is slower than using a server.

When you want to share a repository, you need to set up a server. You can use svnserve or the Apache™ SVN module. See the Web page references:

Standard Repository Structure

Create your repository with the standard tags, trunk, and branches folders, and check out files from trunk. The Subversion project recommends this structure. See the Web page:

If you use Simulink Project to create an SVN repository, it creates the standard repository structure. To enable tagging, the repository must have trunk/ and tags/ folders.

After you create a repository with this structure, to add tags to all your project files, on the Simulink Project tab, in the Source Control section, click Tag. See Tag and Retrieve Versions of Project Files.

Manage SVN Externals

To get files into your project from another repository or from a different part of the same repository, use SVN externals.

  1. In Simulink Project, right-click a project folder and select Source Control > Manage Externals.

  2. In the Manage Externals dialog box, click Add entry. You can browse to and validate a repository location, specify the relative reference format, specify the subfolder, choose the revision, e.g., the HEAD node, etc.

  3. After specifying the externals, click OK. The project displays the externals definition in the Manage Externals dialog box.

    Alternatively, enter or paste an svn:external definition in the Manage Externals dialog box. The project applies an SVN version 1.6 compliant externals definition.

  4. Click Set to validate and apply your changes.

  5. To retrieve the external files, click Update to update the sandbox.

If two users modify the svn:external for a folder, you can get a conflict. To resolve the conflict, in the All Files View, locate the .prej file and examine the conflict details. Open the Manage Externals dialog box and specify the desired svn:external, mark the folder conflict resolved, and then commit the changes.

Related Examples

More About

Was this topic helpful?