Saturday, July 21, 2007

Using SVK for offline access to subversion

SVK is a distributed version control system. Since I've been working through a dial up connection to the internet, I was looking for a way to have offline access to source control. That way I will be able to view logs, diffs and even commit changes while offline. I've only used SVK for a small time, but it looks ideal for this task.

SVK commands mirror subversion commands so it's very easy to use if you are familiar with subversion. It has better support for branching and merging and doesn't keep any extra files inside your working copy (like CVS or .svn directories). SVK is built on top of the subversion and is written in Perl.

I particularly like being able to filter logs and edit the files being checked in while editing the log message: svk log --filter 'HEAD 15 | grep employer'

The easiest way to install SVK is to use your distribution's package manager. In Fedora, I could just use yum install perl-SVK (you need to have the Fedora extra repositories configured). This downloaded about 3MB of rpms so was quite ok on a dialup connection. For alternative methods look in the SVK book or Installing SVK

Once you have SVK installed, initialize your local repository (depot) with

svk depotmap --init

Initialise and sync a mirror for the remote repository with:

svk mirror https://orangehrm.svn.sourceforge.net/svnroot/orangehrm/trunk //orangehrm/trunk
svk sync //orangehrm/trunk

The sync command can take a while to complete, but you can interrupt in the middle and the next time you run it, it will start from where you stopped earlier.

Here //orangehrm/trunk is the mirror of the remote repository. While we can checkout //orangehrm/trunk and work on it, any commit will propagate to the remote server. That will not do if we are offline.

So we create a local branch.

svk copy //orangehrm/trunk //local/orangehrm

Now we can checkout the branch.

svk co //local/orangehrm

This will create a orangehrm directory and you can do all your work here. Check-ins go to the local branch so you don't need network access.

When you are online again, sync the mirror again, merge the changes to the local branch and update your working copy.

svk sync //orangehrm/trunk
svk smerge -Il //orangehrm/trunk //local/orangehrm
svk update (from your working copy)

You can also use svk pull instead of the last 3 commands. I prefer doing it this way because I can use the -Il options which apply each change from the remote server individually and uses the original log messages as commit messages.

Now if you have any changes in your working copy, check them in to the local branch.

Push the local changes to the remote server (first doing a dry run to check for conflicts):

svk smerge -C //local/orangehrm //oranghrm/trunk
svk smerge -Il //local/orangehrm //orangehrm/trunk

Again I prefer using -Il to get one commit to the remote server per one local commit but you can also have one single commit containing all the local changes. Using a single commit is faster and you may prefer it if using a slow connection to the internet. You might prefer the svk push command, which does the above two steps in one go.

SVK also supports mirroring CVS, Perforce and some other repositories.
I recommend you go through these tutorials and glance through the SVK book before using it.

No comments: