Mercurial

From LabVIEW Wiki
(Redirected from Hg)
Jump to: navigation, search

Introduction

Logo.Mercurial.png

Mercurial is a Source Code Control system by Selenic, it's key feature is the distributed nature of the system. This means that changes (commits) are stored in a local repository, which can be sent (pushed) to a central repository and which can be downloaded (pulled) by others.

Getting started

Joel Spolsky has written a How-To and Why-To page called HG init (hg is the chemical symbol for Mercury).

Configuration

Mercurial stores it's setting in a file called 'hgrc' inside a hidden folder '.hg'

Setting up LVMerge

LVMerge can be used by Mercurial as a Merge tool. Add the following text to the hgrc file:

[merge-tools]
LVMerge.args = $base $other $local $output
LVMerge.executable = C:\Program Files\National Instruments\Shared\LabVIEW Merge\LVMerge.exe
LVMerge.gui = True
LVMerge.binary = True
[merge-patterns]
**.vi = LVMerge
**.ctl = LVMerge
**.lvclass = LVMerge
**.xctl = LVMerge
**.lvlib =LVMerge

You can now use TortoiseHG to perfrom a merge (How-To)


Setting up LVDiff

LVDiff is a software package that uses the built in diff-functionality from LabVIEW to do command line based LVDiffs.

Download

First thing is to download LVDiff, copy the contents of the zip-file to a location where you have writing priviliges (lvdiff uses a local ini file).
Alternative: Installer from NI Community Mercurial User Group

Adjust

Then you need to open up the lvdiff.vi and implement these changes.

Lvdiffcopy.png

This snippet (the actual code inside lvdiff copy is shown) tests if the filenames are the same and if that's the case it calls a VI called lvdiffcopy, which creates a copy of the file2. For LabVIEW 2011 (and up) a patch file is available, use this to replace lvdiff.vi in the lvdiff installer folderFile:Lvdiff 2011 patch.vi.

Configure

To be able to select lvdiff as the diff tool you need to add the following settings to the [merge-tools] section of the hgrc configuration file:

lvdiff.diffargs = $child $parent
lvdiff.executable =C:\Program Files\lvdiff\lvdiff.exe
lvdiff.gui = True
lvdiff.binary = True

If you are using TortoiseHg 1.0 or later, you can add a [diff-patterns] section to your hgrc file, analogous to the merge-patterns section mentioned above. This will enable automatic selection of the visual diff tool (see [1]):

[diff-patterns]
**.vi = lvdiff
**.ctl = lvdiff
**.lvclass = lvdiff
**.xctl = lvdiff
**.lvlib = lvdiff

Start LVDiff

You can start lvdiff in TorsoiseHg in the 'commit' dialog with right-click and 'Visual Diff':

StartVisualDiff.png

In the following dialog, select 'LVDiff' and double click on the VI to diff:

HG LVDIffStart.png

After this LVdiff will launch LabVIEW and both VI (current and committed) will be compared.

Ignoring files

Mercurial stores general ignore patterns in a file called '.hgignore' in the repository root, so you can add the patterns to the repository. I use the following patterns

.ogp$
/built*$
/build*$
.lvlps$
.aliases$

Globally ignoring files

If you're using TortoiseHG you can use a global ignore file, by adding the following in your %profile%\mercurial.ini file:

[ui]
...
ignore = %userprofile%\.hgignore
...

Next to the mercurial.ini file you create the reference .hgignore file with the contents of your choice (source).

Performing a merge

The following conditions needs to be true to be able to perform a merge:

  • All local changes needs to be commited (hg st should only show ?)
  • A changeset is pushed by another user to the central repository
  • The other changeset is not yet pulled

The merge will try to detect the differences and call LVMerge if necesarry, LVmerge will show four VIs:

  • Base, the base VI which was present in the changeset that is the same on both repositories
  • Mine, local commited VI
  • Their, remote VI with edits from the other user

These are not editable.

  • Resulting, this is the VI that will be stored to disc after the merge finalizes. This file can be edited by the user

For each diff LVMerge will give options to use either, 'base', 'mine' or 'their' code.


After the merge the code should be committed and pushed.

Most Mercurial Clients will show a graph with the following layout:

MergeTrackHG.png

Here's the same graph from the 'other' user, which actually performed the merge:

MergeTrackHG Other.png

Here you see the opposite actions, two changesets in the local repo and one in the remote. Only difference is the moment of branching.

Mercurial clients

On WindowsLogo.Windows.png, MacLogo.Mac.png and  Linux Logo.Linux.png, there is a command line client called 'hg'. On windows there is a context menu tool called TortoiseHG based on the popular TortoiseSVN and TortoiseCVS tools

External Links