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.