Question

I have a repo containing lots of directories and files. For a scratchbuild I only need a subset of the tree starting at the root. Some unneeded subtrees deep down contain huge files not needed for scratchbuilding. I've played around with the --depth empty option to checkout only a sparse tree but this is cumbersome and backwards, because I ended up with a big whitelist of directories I want, instead of a tiny blacklist of directories I don't want. The whitelist approach is further complicated by the need to monitor for new directories I might need for scratchbuilding.

Is there a way to express Checkout recursively dir but skip dir/foo/bar/baz and dir/frob/tweak without jumping through hoops? Something like the -prune predicate of find(1)?

Was it helpful?

Solution

Subversion assumes that you want the whole directory tree. There is a way to do sparse checkouts, but it is sort-of a hoop jumping through mechanism:

First, do a checkout and set the --depth to immediates:

 $ svn co --depth=immediates svn://localhost/myproject/trunk myproject-trunk

This will checkout all files and directories immediately under the root.

Next, you can use all sort of shell script magic to update with the --set-depth flag only those directories you want:

$ shopt -s extglob   #Needed on BASH, but not Kornshell
$ svn co --depth=immediates $REPO_URL
$ svn up --set-depth=infinity !(foo|frob)

The above will do a checkout of all the directory trees except for foo and frob.

You could do similar things with find too.

The problem is that Subversion is very simple and was designed to be that way. In other version control systems like Perforce and ClearCase, you specify what you want to checkout and in Perforce, how you want it checked out.

However, that requires you to setup a view which makes using these version control systems much, much more complicated. I like Perforce. It's quick and powerful, but the developers hated it because of the need for views. To them, it added a measure of complexity that really didn't give them much in the way of benefit. They rarely needed to do sparse checkouts.

If this is a common problem with your Subversion repository, you might want to rethink your layout to make it more convenient. This isn't too difficult in Subversion since the entire repository is just a file tree including branches and tags. THere are many times we've decided to abandon a trunk and replace it with a particular branch, or renaming and restructuring our repository to make it easier to work with.

Just be sure to coordinate any massive restructuring with your developers. If you move a directory tree they were working on, they'll suddenly discover they can't commit their changes (Most of the time, they can do a svn switch --relocate to get around this problem. However, my experience has been that developers rather check in their stuff and start with a clean checkout.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top