Tuesday, July 27, 2010

Using SVN Externals as Organization Links

Here's the problem: you have a large SVN code base with many sub-projects.  Setting up your SVN as a straightforward hierarchical organization (each sub-projects is a sub-folders in your grand scheme) will eventually cause problems, since you will want to significantly reorganize components over time without breaking builds that may be dependent on the older directory layouts.

We've found SVN externals to be a good way to handle the problem of linking across far-flung directories within the same SVN repository. In this setup, each major sub-component still gets its own directory. The organization appropriate for your current system is a simple organizing/aggregating directory.  Sub-components are then linked into this directory using svn:external properties that are defined in a properties file (this is the only file you need in your aggregating directory).  

The easiest way to do this is to create a file (svn_ext_val.txt) in your new aggregating directory and define properties within it.  Call your aggregating directory "myagg".  Then for example (from our OGCE project)

[shell-prompt> svn co http://ogce.svn.sourceforge.net/svnroot/ogce/myagg
[shell-prompt> cd myagg
[shell-prompt>cat svn_ext_val.txt 

sgfac https://ogce.svn.sourceforge.net/svnroot/ogce/ogce-xsul-services/sgfac/
xregistry https://ogce.svn.sourceforge.net/svnroot/ogce/ogce-xsul-services/xregistry/
ogce-xbaya https://ogce.svn.sourceforge.net/svnroot/ogce/ogce-xbaya-gui/
gadget-container https://ogce.svn.sourceforge.net/svnroot/ogce/ShindigOGCE/ishindig-trunk/
xregistryinterface https://ogce.svn.sourceforge.net/svnroot/ogce/ogce-gadget-interfaces/xregistryinterface/
experimentbuilder https://ogce.svn.sourceforge.net/svnroot/ogce/ogce-gadget-interfaces/experimentbuilder/
gadget-sharedlib https://ogce.svn.sourceforge.net/svnroot/ogce/ogce-gadget-interfaces/gadget-sharedlib/gadget-sharedlib/

Each property points to the appropriate component directory within SVN.  Set these for your project with the command 

svn propset svn:externals -F svn_ext_val.txt  .

Verify everything is correct with 

svn propget svn:externals

Then commit with "svn commit" as usual.   Now run "svn update" and it should check out all the external components.  If you edit code in any of the subcomponents and commit, the external directory will be updated correctly.