Subversion is a bit lacking on the merging and branching front in comparison with some of the newer distributed version control systems, but it does make working with large projects easy. The single biggest reason for this is sparse checkouts.
At work we have a source tree that contains artwork, documentation, the source for all the third party libraries we use and compiled versions of these for multiple architectures and platforms (32bit, 64bit, windows, RHEL4, RHEL5 etc). This makes the full checkout rather large and there are many times when you only need a small fraction of all the files.
The problem with sparse checkouts is that it can become very laborious manually setting one up for anything beyond a few directories. For more details on the basics see here. As with many tedious tasks - computers can help!
I put together a little script for helping with this - get it here. I hope it's useful and keep reading for more details on how it works.
In Action ∞
The final version of the script makes doing a sparse checkout as simple as doing an standard checkout:
To checkout using a named subset of files:
./checkout.rb --map documentation svn://server/trunk
To checkout using a locally defined subset of files (rather than a subset stored on the sever):
./checkout.rb --map local.yaml svn://server/trunk
Map Files ∞
The map files are a simple YAML file that specifies which directories to checkout and to what depth. The map file allows other map files to be included meaning you can build up a new file map from existing ones.
Checkout maps (code.yaml):
description: Everything needed to compile and build base: build/ files: all: - build/thirdparty/* - build/code/buildtools/* - build/buildtools/@ - build/plugins/* linux: - build/libs/linux/* windows: - build/libs/windows/*
Storing Map Files ∞
In order to provide a centralised, easy to find location for the map files the script looks for a folder called sparse at the top level of a particular branch (e.g. svn://server/trunk/sparse). This folder contains all the sparse checkout file maps e.g.:
$ svn ls svn://server/trunk/sparse code.yaml docmentation.yaml
Storing the map files in subversion itself is one of the strengths of this system. This allows the file maps to be versioned along with the contents of the repository itself. If the maps were stored outside of subversion it would be impossible to keep them in sync with changes to the repository layout, something which became rapidly apparent in the first version of the script!
Map File Syntax ∞
;include :Named map file stored in the sparse folder or a local file ;description :Textual description to list when doing --listmaps ;base :Directories to strip from the paths when doing the checkout ;files :List of files to checkout, must contain one of all, linux or windows sections ;all :List of folders to checkout on all platforms ;linux :List of folders to checkout on linux ;windows :List of folders to checkout on windows The @ and * specify what to checkout inside the named folder: @ - Checkout only the files in the folder and don't recurse any deeper (--depth=files) * - Checkout the folder and everything inside it (--depth=infinity)
The Script ∞
Finally the script!.