Monday, January 30, 2006

Distributed Version Control with SVK

Imagine a situation where some software development company has it's offices located in different part of the world. This company also has central server where the version control software is running. The connection to this server is not always good. In such situation, if each office has its own server having version control system which is a mirror of the central system, the problem due to bad connection can be reduced. For this kind of situation, SVK is the tool everybody should use. SVK allows mirroring of existing remote repositories, creating local branches, working on these branches, and when everything is ready, merging them back into mirrored trunk, which updates the remote repository automatically. I've done some research on SVK for the real world situation mentioned above. The company I am currently working has it's offices in US, India and Nepal. The central server is located in US. But sometimes, due to the problem of connection or by other factors, the main repository is not available. To overcome this problem, we looked for the alternative of making mirror of central repository in both Nepal and India. By having the repository in both locations, access to the repository is local. No more slow connection or time out problem. Since our version control is Subversion, our task was to find the tool(s) which is best suitable for this system. Also, most of the development work is done in Microsoft Windows Platform, we use TortoiseSVN to update from and commit to the repository. It was an advantage to us that SVK works on subversion file system.

Plan of implementation
In order to make SVK work, the plan is to mirror the central repository in the local machine. Then the local branch is created. Instead of using the mirrored trunk, user will be accessing this branch. At the end of the day, when everybody is done with their work, the local branch is merged into mirrored trunk. At the same time, the central repository is automatically updated.

Installing SVK
SVK is written completely in Perl and kind of pain to install. Luckily, in my Fedora Core 4 system, Subversion was already installed with perl binding, all I needed to fire the command;

perl -MCPAN -e 'install SVK'
This command install SVK and all of it's many dependencies.

Setting up local 'depotmap'
To set up local repository, the following command does the trick;

svk depotmap --init
This will create a default depotmap. Alternatively, if you want to make a depotmap to the desire location, just issue the command
svk depotmap
This will open a default text editor and let you edit the depotmap name and the location.

Mirroring the central repository

svk mirror svn:// //localrepo/trunk
To ensure that mirror has been setup, svk mirror --list command can be used. Now that the mirror has been set up, the local copy is sync with mirror using
svk sync //localrepo/trunk
Creating a local branch
The first thing need to be done before start working is to create a local branch. Doing this is same as in Subversion.
svk cp -m "local branch" //localrepo/trunk /localrepo/localbranch
You can check the branch by issuing the following command;
svk ls //localrepo/localbranch
Now user is able to work with the local branch using TortoiseSVN or anyother Subversion client tool.

Merging from local branch to the mirror
At the end of the day, after everybody is done with the work, local branch must be merged to the mirror. This can be done with the command svk smerge command.

svk smerge -C //localrepo/localbranch //localrepo/trunk
The C option checks for the conflict that may have. Now, if there is no conflict, the actual merger can be done using following command;
svk smerge -l //localrepo/localbranch //localrepo/trunk
This command also updates the repository automatically that the mirror points to.

1 comment:

Anonymous said...

Good posting