Migrating from Subversion to Bazaar (Including special guide for Sourceforge projects)

It's about the sixth years since my first commit using Subversion, Moving from CVS to Subversion was really amazing, Subversion was superior in many ways and it served me well. But the age of centralized version control systems is over, we need much more powerful VCSs to deal with huge projects. Now days we should to be able to work with anyone, on anything, anywhere , at anytime, and also keep track of all this activities.
As part of my research project (Comparing Popular Version Control Systems) i decided to start with Bazaar and migrate one of my Subversion Sourceforge projects to this new VCS in order to have a better understanding of how it actually works. And also test the migration utilities because if you can't migrate your code's history then that would be a huge problem.
Before we begin note that Bazaar currently does not support all of subversion's features, so please make sure that your project does not depend on those features. Also you need to at least know what Bazaar is! and why you want to try it. if you don't then please spend some time and read the Bazaar's user guide documentation or perhaps my notes on (Comparing Popular Version Control Systems) before continuing.
Another thing is if you're not using Subversion's recommended branch scheme, (trunk, branches, tags), i suggest you to rename them to the recommended scheme if possible ,before continuing. If you can't it's possible to tweak the import utility to understand your custom scheme, but that requires modifying its code which it is not covered in this article.
Bazaar offers several ways for migrating SVN repositories , each one has its own limitations but the one i'm going to use in this article is bzr-svn. This solution works on Linux , Windows and also for non Sourceforge Subversoin repositories. For more information about other solutions visit BzrMigration - Bazaar Version Control
Note : Replace USERNAME and PROJECTNAME texts with your desire username and project name.
Migration
Step1 : Obtaining shell access to Sourceforge
# Skip this step if you're not using Sourceforge
For dumping the Subversion repository we need to have direct access to the repository. Soruceforge offers shell access for project's owners by default which is very useful for managing projects. For activating the shell access we first need to create a shell session (Skip this if already have an active session) :
ssh USERNAME,PROJECTNAME@shell.sourceforge.net create
Then for loggin into your shell :
ssh USERNAME,PROJECTNAME@shell.sourceforge.net
Note : The password is the same as your Sourceforge's account password
More information about sourceforge shell access Shell service – sourceforge
Step2 : Working copy?!
One of the problems with centralized version control systems is lack of local history, therefore there is usually some non commited changes on working copy. There are several ways to migrate this changes :
- Commit all changes before migration!
- Export the working copy , migrate repository , checkout Bazaar repository , delete all files/folders (except Bazaar's specially folder) and then copy the exported working copy over (You'll lose rename,move history unless you use auto-mv plugin, however Bazaar can detect missing files).
- Commit all changes to a different temporary branch and then merge it with the mainline branch after the migration
- Create a patch and apply it to Bazaar working copy after migration
Step3 : Exporting Subversion repository
# Ignore this step if you're not using Sourceforge
Subversion repositories are not accessible by default, for obtaining access to your project's Subversion repository there is a utility called adminrepo. We're not going to change anything on the Subversion repository however. In Sourceforge each project can use several VCSs at the same time. cool!.
Lets checkout Subversion repository to an accessible folder :
adminrepo --checkout svn
After the execution you should see an address like this /svnroot/PROJECTNAME which is the location of the checked out repository
Step4 : Dumping and Backing up the Subversion repository
For preserving files history it's important to dump the whole Subversion repository which also acts as a backup. We're not going to change anything on Subversion repository however. but for any reason you need to, you can have a look at adminrepo command's help
So now
it's time to dump the repository and then compress it (PLEASE replace &
gt
; with >
) :
svnadmin dump /svnroot/PROJECTNAME/ > svn.dump zip -r svn.dump.zip svn.dump
Step5 : Downloading the dump
# Ignore this step if you're not using Sourceforge
Move the zip file to your user's web folder :
mv svn.dump.zip ~/userweb/htdocs/
Now you can download the zip file using this link :http://USERNAME.users.sourceforge.net/svn.dump.zip
Note : There are other ways of course, like using scp for downloading it directly via shell, but it doesn't work on Windows out of the box.
Step6 : Enabling Bazaar for your project
# Ignore this step if you're not using Sourceforge
Login to Sourceforge and then open your Develop page, go to "Project Admin" -> "Feature Settings".
From the Feature Settings page, click on "Available Features", then check the box next to "Bazaar". This will enable Bazaar for your project.
Step7 : Preparing Remote Bazaar repository
# Ignore this step if you're not using Sourceforge
To simplify things, in this article we will use a familiar work-flow to Subversion users (Centralized) , you can easily make it decentralized without much changes once you understood Bazaar's work-flow properly (Bazaar supports mulitply work-flows).
In Sourcforge, Unlike Subversion/CVS for Bazaar we have direct access to repository so lets create our Bazaar repository :
mkdir -p /home/scm_bzr/p/pr/PROJECTNAME/ cd /home/scm_bzr/p/pr/PROJECTNAME/ bzr init-repo --no-trees . bzr upgrade --rich-root-pack .
Note : The two folder behind PROJECTNAME folder (p/pr) are named after the [first] and then [first+second] character of project's name
Note : The last command "bzr upgrade --rich-root-pack" is very important, without it you can't import Subversion dump into this Bazaar repository.
Note : Sourceforge's Bazaar is at version 2.0.3 (At the time of writing this article), but you can install the latest version of Bazaar on your client system because bazaar is highly backward compatible. In Bazaar each important version uses a different tree format.
Step8 : Installing Bazaar on local machine
Windows :
http://wiki.bazaar.canonical.com/WindowsDownloads
Linux (Redhat based) :
sudo yum install bzr bzr-svn
Linux (Debian based) :
sudo apt-get install bzr bzr-svn
For other Linux distributions visit : DistroDownloads - Bazaar Version Control
Step9 : Preparing Bazaar local repository
You might ask why i didn't import it on the online server?! It's due to the limitation on Sourceforge, importing Subversion dump requires an special Bazaar utility which we can't install on Sourceforge.net
mkdir -p vcs/bazaar/PROJECTNAME bzr init-repo vcs/bazaar/PROJECTNAME #(prepare local repository)
Step10 : Importing Subversion Dump
Both repositories should be "rich root" so you can upgrade you Sourceforge using bzr upgrade --rich-root-pack
unzip svn.dump.zip #Importing each subversion folder branch as a bazaar branch bzr svn-import --layout=trunk svn.dump vcs/bazaar/PROJECTNAME
Note : svn-import sub-command offers several useful switches , have a look
Note : While i was trying to migrate one of my project from svn to bzr, i came into some very nasty issue due to the difference between server and local bzr version. bazaar supports various different tree formats which can causes lots of headaches. This command helped : bzr upgrade --rich-root-pack
Step11 : Uploading(Pushing) the imported branches
# Ignore this step if you're not using Sourceforge
Unlike Subversion Bazaar branches are flat and do not support branch hierarchy. Therefore we have to push them
one by one.
cd vcs/bazaar/PROJECTNAME cd trunk bzr push bzr+ssh://USERNAME,PROJECTNAME@PROJECTNAME.bzr.sourceforge.net/bzrroot/PROJECTNAME/trunk cd .. cd branches/v1.0 bzr push --create-prefix bzr+ssh://USERNAME,PROJECTNAME@PROJECTNAME.bzr.sourceforge.net/bzrroot/PROJECTNAME/branches/v1.0
Step12 : Checking out working copy
Now that we're done, lets start working by checking-out from the local or remote repository :)
Sourceforge repository
mkdir -p ~/vcs/bazaar/working_copy cd ~/vcs/bazaar/working_copy bzr checkout bzr+ssh://USERNAME@PROJECTNAME.bzr.sourceforge.net/bzrroot/PROJECTNAME/trunk
Local repository
mkdir -p ~/vcs/bazaar/working_copy cd ~/vcs/bazaar/working_copy bzr checkout ~/vcs/bazaar/PROJECTNAME/trunk
I hope you find this article useful :) , don't hesitate to ask me if you had any question.
Resources
- Shell service – sourceforge
- #3691 (I would switch my project X3 CMS from svn to bazaar) – sourceforge
- #517 (Problem converting svn to bzr repository.) – sourceforge
- Bazaar – sourceforge
- DistroDownloads - Bazaar Version Control
- BzrMigration - Bazaar Version Control
- Question #61528 : Questions : Bazaar Subversion Plugin
- svn2bzr - Bazaar Version Control
- ...