Selfupdate-git and -svn, take two

This is a rebased version of the selfupdate-git branch we have in our repository. I wanted to make this because (a) an open pull requests makes this branch much more visible, (b) it allows us to conduct discussion, and (c) because I wanted to clean it up.

In fact, part (c) is not yet quite complete, so expect things to be shuffled around a bit more (in particular, my commits here might go into master first). For now, though, it would be great if we could collect what exactly is needed to get this merged.