Wednesday, August 09, 2006

Restructuring SVN repository

Sometime you may need to restructure your SVN repository. I was in the same kind of situation. We rely on SVN and we really trust this software. But the person who created repository made a mistake. He created 3 folders, 'trunk', 'tags' and 'branches' in the hard drive and then created repo in the 'trunk' folder. We didn't notice this until we need to branch our project. After going through some websites and forums, I found the simple method to restructure the repository.
1. First, dump the repository to some file
svnadmin dump /path/to/repo > dumpfile.txt
2. Move your repository folder to somewhere else in order to backup, just in case
mv /path/to/repo /path/to/repo_backup
3. Now, manually change the "Node-path:" and "Copy-to-path:" headers to insert "trunk/" into them
sed -e 's/^\(Node-path: \)\(.*\)/\1trunk\/\2/;s/^\(Copy-from-path:\)\(.*\)/\1trunk\/\2/' dumpfile > dumpfile.new 
If you find above command too hard, just open the dumpfile in any text editor and do find and replace. :-) You should be replacing "Node-path:" with "Node-path:trunk/" and "Copy-to-path:" with "Copy-to-path:trunk/". Simple huh! 4. Create new repository
svnadmin create /path/to/repo
5. Load modified dump file into newly created repository
svnadmin load newdumpfile.txt path/to/repo
6. Finally, import 'tags' and 'branches' folder in the repository. Now, you will see your repository with proper structure in which you can make branches and tags of your project.

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://mydomain.com/myproject/trunk //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.