eibrand.net

svn – moving part of repository to another repository

July 2nd, 2008 by

I’ve recently had the pleasure of having to move part of a repository to another specific location within another repository, while needing to keep all the history. This had been a task that had been lurking around for a while at work, and in the past I had run into problems with svndumpfilter, and even svndumpfilter2 (including Bill’s modification).

As I had to revisit the problem, and get it working this time, I spent a little time at it. The end result is that it worked nicely, and in the spirit of sharing, I wrote up the procedure I carried out. You can find it below, and are welcome to share any comments and thoughts you have on this.

R

General procedure

1. Dump svn repository or get a hold of already dumped repository (make sure no commits are being made at the time)

2. Run svndumpfilter2 on the dump file, for this command, svndumpfilter2 must be available on the machine [1].

svnadmin dump /path/to/repo | svndumpfilter2 /path/to/repo folder_to_dump/subfolder > dump_file_name

Imagine the following scenerio, path/to/repo == /usr/svnrepo/project, folder_to_dump == trunk and subfolder == sample_code, the above line would read as follows

svnadmin dump /usr/svnrepo/projectname | svndumpfilter2 /usr/svnrepo/projectname trunk/sample_code > trunk_sample.dump

Note: in the above example, the folder_to_dump is mainly a top level folder, but you can also specify a subdirectory, e.g. folder_to_dump/subfolder/subsubfolder

3. Edit dump file to specify where the new dump is going to be imported, take special note of the sed expressions. This is needed to allow for easier importing into the destination repository. The svnadmin dump command will dump the repository, but it will dump it with the full path, so from our example above, this would be trunk/sample_code, and that is how it will be imported. But what if we want to import somewhere else than trunk? This is why we might need to edit the actual dump file.

Care must taken in this operation, as otherwise, the dump file may get partially corrupted, or generated an md5 checksum error, (see [2]).

A generic find/replace would be dangerous, as one might inadvertently edit the content of the code in the repository. To avoid this, our search must take into consideration both the Node-path: and Node-copyfrom-path parameters. This is shown in the example below.

The 1st part of our sed expression reads as follows:

sed -e “s/Node-path: trunk\/sample_code/Node-path: sample_code/g”

The 2nd part of our sed expression reads as follows:

sed -e “s/Node-copyfrom-path: trunk\/sample_code/Node-copyfrom-path: sample_code/g”

The output of the these sed commands is then piped into a new file, ready for importing, see below:

#renaming path of where the file will end up – sed complicated but this is because of md5-error

cat trunk_sample.dump | sed -e “s/Node-path: trunk\/sample_code/Node-path: sample_code/g” | sed -e “s/Node-copyfrom-path: trunk\/sample_code/Node-copyfrom-path: sample_code/g” > cleaned_trunk_sample.dump

4. Load new dump file into destination repository (make sure no commits are being made at the time). In the example shown below, we are importing our sample_code into a subdirectory of trunk in our new directory. This directory needs to exist prior to executing the svnadmin load command.

sudo svnadmin load /usr/svnrepo/new_projectname –ignore-uuid –parent-dir trunk/server < cleaned_trunk_sample.dump > repo_import.log

The above command will import the sample_code part of original repository into the trunk/server/sample_code, with all the history from the previous repository where the sample_code resided.

References

[1] svndumpfilter2 url: http://svn.tartarus.org/svn-tools/ using version 8055
http://svn.tartarus.org/*checkout*/svn-tools/svndumpfilter2?rev=8055

[2] md5 mismatch – good tips here and helped me in my procedure
http://blog.fredrikbostrom.net/2007/03/14/migrating-part-of-repository-in-svn
Read the rest of this entry »

Posted in general, infrastructure, svn | 4 Comments »