Subversion sparse checkouts
I’ve been using Subversion for a few years now but as with lots of technology I work with, I’ve learned enough about it to do the job I need to do but I’ve never dug into it exhaustively. It turns out a nice feature called sparse checkouts was introduced into Subversion 1.5. With Subversion, you can either create one repository for each project or use a single repository for multiple projects. I like using a single repository for multiple projects but there are advantages and disadvantages to both approaches and it’s yet another source of religious debate and flamage so I won’t suggest which would suit your needs best.
One of the disadvantages of using a single repository for multiple projects is that any time you want to check out part of your repository, you either had to do something like this,
svn checkout http://www.example.com/svn/myrepo
to check out the whole repository (and if it’s a big repository, and you’re on a slow connection, you get to watch the world wide wait in action) or something like this
svn checkout http://www.example.com/svn/myrepo/oneofmyprojects
to just check out a teensie part of your repository which should happen faster than the former approach. The disadvantage to the second approach is that you end up with only part of the repository checked out and if you want another part in the future, you’ll have to check that out separately like
svn checkout http://www.example.com/svn/myrepo/anotheroneofmyprojects
Pretty soon, you’ll have a directory full of separately checked out projects, each of which you have to individually svn update, svn commit and so on. Hey, it starts looking like you have one repository for each project. Ideally, what you want to be able to do is to check out your entire repository but only the bits your are interested in, while keeping the option open of checking out other parts in the future and managing them all as the one repository that they are. Sparse checkouts introduced this functionality.
With svn’s sparse directory support, you can do the following,
svn checkout --depth=immediates http://www.example.com/svn/myrepo
This checks out the myrepo repository, but only to a depth of 1, that is, all files and directories immediately under myrepo but not any further subdirectories and files. So a directory listing of your checked out repository might look like,
oneofmyprojects/ anotheroneofmyprojects/ README.txt
This gives you an overview of the myrepo hierarchy without pulling all the files. Furthermore, it is sticky – any subsequent svn update commands you run will honour the scope you set in the first checkout.
If you now want to flesh out parts of the tree, you can do the following
svn update --set-depth=infinity myrepo/oneofmyprojects
This updates the contents of myrepo/oneofmyprojects with all children (files and subdirectories) ensuring you have a full copy of that part of the repository. If you subsequent run an svn update in myrepo – the behaviour for oneofmyprojects continues to be sticky and will result in an update of all files and subdirectories (while not checking out the children of any of the other myrepo top-level directories).
Unfortunately, you cannot checkout a directory with depth=infinity and then update it to a reduced a depth (the behaviour only works in the direction of increasing depth for now).
More detail is available at http://svnbook.red-bean.com/en/1.5/svn.advanced.sparsedirs.html
I took a quick look at TortoiseSVN (a very nice graphical Subversion client for Windows) and if you do an SVN checkout it has an option for Checkout Depth which I’m guessing provides the same functionality (but I haven’t tested it).
5 Comments to Subversion sparse checkouts
Good explanation. I’ve had this problem loads of times. Nice to know this option is there now.
January 6, 2010
Hi,
What about the problem of tagging a sparse dir ?
Suppose I have this structure:
myproj
dA1
…
dB1
…
I want user A to work on dA1, and user B – on dB1.
But both are contributing to the same release, let’s call it rel_X.
So, user A builds sparse working copy of myproj
% svn co $SVNROOT/myproj -–depth empty myproj
% svn update -–depth infinity myproj/dA1
.. possibly modifies it in some way and tries to tag:
% svn mkdir $SVNROOT/tags/rel_X
% svn copy myproj $SVNROOT/tags/rel_X/ -m “tagging my part”
The problem that we see is SVN for some reason also copies dB1 under $SVNROOT/branches/rel_X !!
% svn ls $SVNROOT/tags/rel_X/myproj
dA1
dB1 <- this should not be there !
Any ideas ? (SVN version: 1.6.2 (r37639) )
thanks !
Stas
January 7, 2010
Hi Stas,
Thanks for your comment. The bevaviour of subversion in this case seems reasonable to me – you are tagging the project – not just the part that an individual developer can see.
-stephen
September 20, 2011
TortoiseSVN 1.7 has sparse checkouts. It is very easy to use. However the question is, will we be able to add stuff (files/directories) into the omitted directories in the future?
September 21, 2011
I can’t see why not, if you check out the parent directories to at least that depth before trying to. But I guess one should test this 🙂
April 17, 2009