I recently wanted to clean up a subversion repository of mine and move some of the larger folders/projects into their own repository. There’s not much documentation on how to do this in Windows (what I primarily use) which is the main reason why I wanted to share this info.
Now, in the past, I’d moved whole repos using the svnadmin dump command, but now I had to make sure that I only got revisions related to a specific folder. Fortunately, there’s this handy little program that comes with subversion called svndumpfilter. This little tool lets you filter out revisions from an svn dump based on a path in the repo. It will even renumber the revisions for you so that when you load the new dump file into it’s own repo, the revisions will all be in order starting from revision 1.
Ok, let’s get to it!
Here’s my basic test case setup:
- I’ve backed everything up before messing around with it.
- I’m logged into the box where my SVN server resides.
- The SVN Repo with the folders to move is here: C:\repos\MyHugeRepo
- The repo’s root directory looks like this (no files):
- I want to move GinormousProject into its own repository at c:\repos\GinormousProject.
- I have a C:\temp folder to use for the repo dump files.
1. Dumping MyHugeRepo
The first thing you’ll want to do is dump your huge repository into it’s own dump file. You could pipe the dump command into
svndumpfilter but if you have more than one folder to move to new repos, it’ll be faster to have the dump as a file to reuse. We’re going to dump all the revision data from MyHugeRepo into the file C:\temp\MyHugeRepo.dump.
Note: Obviously, this is all done in the command prompt.
svnadmin dump C:\repos\MyHugeRepo > C:\temp\MyHugeRepo.dump
This will dump your whole repository at C:\repos\MyHugeRepo into the file C:\temp\MyHugeRepo.dump. You should see an indication of what revision it’s currently on in the command prompt window.
Note that if you were to leave off the > C:\temp\MyHugeRepo.dump, it would dump the repository right to the command prompt window. Not very helpful. The > redirects the output of the command (in this case svnadmin dump C:\repos\MyHugeRepo) to the file specified after it.
2. Filtering GinormousProject
The next step is to create a new dump file with only the revisions relating to the GinormousProject. This is where we use svndumpfilter. We’re also going to use the Windows < input redirect to take the contents of the file we made in step 1 and send them to svndumpfilter.
svndumpfilter include --drop-empty-revs --renumber-revs GinormousProject < c:\temp\MyHugeRepo.dump > C:\temp\GinormousProjectRepo.dump
Let’s break this down:
- svndumpfilter include – This means we want to do an include filter on the dump file. What folders we include depends on what we pass later in the command.
- --drop-empty-revs – This will remove any revisions from our new dump that were empty because of the filter.
- --renumber-revs – This will renumber the revisions for GinormousProject so that they will start from 1 when we import the dump file into our new repo. Keep in mind that if you have external tools (such as a bug tracker) that rely on the old revision numbers, they will no longer be linked properly.
- GinormousProject – This is the actual include filter for the command. It tells svndumpfilter to filter for only the GinormousProject directory. I believe you can specify multiple directories if you separate them with spaces.
- > c:\temp\MyHugeRepo.dump – This reads MyHugeRepo.dump and directs it into the svndumpfilter command — it tells svndumpfilter to use that file.
- > C:\temp\GinormousProjectRepo.dump – Like in step 1, this tells the command prompt to redirect the svndumpfilter output into the file GinormousProjectRepo.dump.
3. Create the new GinormousProject Repository
Ok, now we want to import our newly made dump file, C:\temp\GinormousProjectRepo.dump, into it’s own repo. We do this in two steps. First we create the new repository and then we load the dump file we made in step 2 into it.
svnadmin create c:\repos\GinormousProject
svnadmin load c:\repos\GinormousProject < C:\temp\GinormousProjectRepo.dump
- svnadmin create c:\repos\GinormousProject – This creates a new repository at c:\repos\GinormousProject
- svnadmin load c:\repos\GinormousProject – This loads the input into the GinormousProject repo.
- > C:\temp\GinormousProjectRepo.dump – This reads the dump file from step 2 and sends it to the svnadmin load command.
That’s it! Now we have new repo that only contains changes to GinormousProject and whose revision numbers start at 1. Woo hoo!
Wait, hang on a minute here, what about the GinormousProject folder that’s still in the MyHugeRepo repository?
4. Taking Care of MyHugeRepo\GinormousProject
There are a couple of things you could do here but, again, keep in mind that if you have any external tools that reference those revision numbers, you probably don’t want to renumber anything.
- The simplest thing to do would be to simply delete that folder from your repository by checking out the repo, deleteing the folder using svn delete, and then committing it. This will keep your revision numbers intact.
- As you may have guessed, there’s an svndumpfilter exclude command which essentially does the opposite of the include command — it excludes the folders that match the filter. If you choose to use it, remember what I said above regarding references from external tools.
I hope this was helpful. Let me know if you have any comments, questions or notice any issues by dropping a comment below. Thanks!