Moving to Google Code

Part of the process of moving away from my old, potentially-hard-to-maintain-in-the-future project-publishing model involved moving my local SVN repositories to Google Code, Google’s open-source-friendly project-hosting service.

Setting up the project pages and moving my existing code over there was quite easy. However, I wanted to keep local read-only repositories to avoid breaking links while I get set up for future development work and because I like having redundant backups of things I consider important.

I figured I should kick this blog off with a post that others might consider helpful, so I’m documenting the actions I took below. Note that this will not preserve SVN UUIDs, so you’ll need to diff and patch any dirty working copies you or other committers may have or otherwise adapt the steps to suit your needs. I’m also assuming you’ve set up sudo. If not, do everything post-committing-to-Google as a user, like root, who has permissions that will prevent other users from being able to touch the mirror repository (only svnsync should ever be allowed to write to it, and you’ll be crontabbing that).

  1. Create and reset your Google Code repository
    1. Create a Google Code project
    2. Find and follow the “reset” link at the bottom of any page under the “source” tab
  2. Migrate your existing code to Google Code
    1. svnsync init EXISTING_REPOSITORY
      • You’ll be prompted to provide credentials to commit to Google Code; these can be found in your profile
      • If your old repository requires credentials to be read, you may also be prompted for those
    2. svnsync sync --non-interactive
  3. Wait while each commit is played out; if you have mature projects, this can take quite a while. Do NOT interrupt this process or you may be left with a locked repository on Google’s end, which you’ll need to handle manually (either by clearing the lock or resetting the repository again)
  4. At this point, everything you’ve ever done has been duplicated on Google’s side, so it’s time to create the local mirror to make sure that, in the unlikely event that Google suddenly disappears, you’ll still have access to your work
    • Before proceeding, it would be a good idea to grab a fresh checkout of your code from Google’s servers and make sure it matches your working copy, using diff and ignoring the .svn subpaths.
    • When satisfied that nothing was lost in the move, you may want to delete your old repository to avoid confusion; you can’t, using this method, just have it sync against Google’s repositories as-is (UUID mismatch); additionally, after remaking the repository, the same UUID-mismatch problem will prevent committers from updating a non-master repository, so this is a good thing
  5. Create a new repository to house code mirrored from Google Code
    1. sudo svnadmin create NEW_REPOSITORY_PATH
      • NEW_REPOSITORY_PATH should be specified in absolute terms, just to avoid confusion later
    2. sudo bash -c 'echo "#!/bin/bash" > NEW_REPOSITORY_PATH/hooks/pre-revprop-change'
    3. sudo chmod u+x NEW_REPOSITORY_PATH/hooks/pre-revprop-change
      • This avoids an error normally raised to prevent accidental damage to repositories
      • The command in step 2 may look a little funny — this is because the redirect needs to be caught within the scope of sudo, so the whole thing needs to be passed as a single argument to a new bash instance
  6. Synchronize your repository with the one on Google’s servers
    1. sudo svnsync init file://NEW_REPOSITORY_PATH
      • Note that you’ll have something that looks like ‘file:///var/svn/my_project’ here, with three forward slashes
    2. sudo svnsync sync --non-interactive file://NEW_REPOSITORY_PATH
  7. Set up a cron job to keep things synchronized every night
    1. sudo crontab -e
      • 0 3 * * * svnsync sync --non-interactive file://NEW_REPOSITORY_PATH
        • Adding this line will make your system synchronize the repository with Google’s servers every day at 3:00 AM; the first two values are minute and hour, so play with them as you see fit
  8. Everything’s done! Your code’s now on Google’s highly accessible servers, and surrounded by Google’s excellent project-management resources, and you have a local copy for paranoia’s sake