Source Code Control Using Mercurial in LabVIEW
Source code control is the major task in programming environment. Managing large of files with multiple developers is difficult because when people overwrite/modify the files in multi-user environment, it becomes difficult to track the changes. Here comes the use of configuration management. It can also be useful for small projects to get the previous versions. Various opensource and commercial source code control tools are available from various vendors in the market.
Here I made an attempt to use Mercurial for version management in LabVIEW, which is free and easy to use software. Version of mercurial for windows is TortoiseHg. It provides both command line and graphical user interfaces.
Tools used: LabVIEW, Windows and TortoiseHg
Click here to download TortoiseHg and install. Once installed, TortoiseHg will be visible under the right click menu in windows. The following are the steps to save versions. I will show how to work with it from command line as well as graphical user interface. Any method can be followed.
Conventions followed here:
- Project directory is referred to a directory, in which you are working[Ex:CLD6 in my case]
- Commit means saving the versions [Versions].
- Repository is the .hg directory inside working directory [.hg inside CLD6]. Repository contains the history of the project.
- First and foremost, you need to create a configuration file and set your username. This has to be done since user name will be used to commit (to know which user has created the version). To create configuration file and set the username in the home directory of windows.
- Open command prompt and find the home directory by typing echo %USERPROFILE% [C:\Users\Aarthi]
- In home directory, create a file using any of your favorite editor. Write the below content into it and save it as .hgrc
#This is the mercurial configuration file
username = aarthi s <email@example.com>
- Open command prompt and change the current working directory to Project directory6[F:\CLD].
- Create a repository there, by using hg init command. This will create .hg folder inside the project directory.
- Add files to repository by using hg add command.
This adds all files from the directory. After adding all files, folder will look like [with a blue plus mark]. To add specific files instead of all, mention the names of the files in the command. e.g.: hg add “File1” “File2”. Now the icon on the files which are added to repository will be changed with plus mark.
- Save the repository by commit command. Commit can be done by giving hg commit command. Editor will be opened to which you have to enter some commit message and save the file. Or else the commit message can be given directly in the command as hg commit –m ‘message’ [hg commit –m ‘Ver1’] and now the project directory will look like [green tick mark]. Give appropriate message for commit such that it’s understandable when it is seen in web server. Icon changes to green tick mark only for the files which are committed. If entire project directory files are committed then the folder [CLD6] changes its icon with green tick mark.
- Mercurial web server can be enabled by hg serve command. Server will run in port number 8000. Through this all files can be accessed/downloaded and users can see the versions [the messages what we have saved before]. Web server will be visible to all computers which are in network. Access the web server by typing ipaddress:8000 in the browser.
All files can be downloaded by selecting browse ->select file ->then select raw and save it.
If any other version files are needed [Ver2] Select Ver2 -> browse -> select file [lists only updated files] ->then select raw and save it.
- Repository history can be seen by using hg history command, which will list all the versions.
Graphical user interface:
- All steps are same as command line, only change is graphical interface.
- First step is to set the user name, it can be set by right clicking project directory -> select TortoiseHg -> Global Settings -> select commit and enter username if not available. It will be saved as mercurial.ini in windows home directory.
- If username is displayed, it means that it is already available in .hgrc file [home directory], or else in mercurial.ini file.
- Initialize repository by right clicking the project directory and select TortoiseHg ->Create repository here. Mercurial files will be created as .hg folder and .hgignore inside the project directory.
- Add files by right clicking the folder and select TortoiseHg ->Add Files. It prompts to select the files to add and click Add.
- Right click and select Hg Commit which prompts the dialog to select the files to commit and for commit message.
NOTE: When user name is not set, commit will not be done which gives the error. And prompts the dialog to enter user name and then saves the revision.
When OK is clicked, it prompts to enter user name.
- Mercurial web server can be enabled by right clicking the project directory and select TortoiseHg ->Web Server.[Refer Fig 2]
Also copies of repositories can be done by hg clone command; Specific revision can alone be copied to another by using pull, push commands. Log can be seen by hg log.
Mercurial basics– All commands are listed in this link.