Subversion Tips

This page is simply a collection of notes and tips I've assembled as I familiarize myself with Subversion and its integration with Eclipse and Ant.

Subversion Mirrors on Windows
Using Ant

Subversion Mirrors on Windows

Here is a quick-and-dirty way to get an SVN mirror working for you on windows. I'm not a Subversion admin; so this is probably not what you should for industrial-strength mirrors. But it seems to work fine for when you want to mirror a small repository on a thumb-drive so that you can bring it somewhere else (i.e. home) and work with the latest code. Note that if you decide to make changes, you will probably want to submit them as a patch file.

First Time Set-up

If you need to create several mirrors, then it's probably a good idea to have a directory on your thumb-drive like mirrors. For the rest of this guide, I'll assume a thumb-drive location of E:\mirrors.

  1. Start a command window and CD to E:\mirrors.

  2. Create a new repository:
       svnadmin create myproject
    You replace myproject with whatever your project is. If this didn't occur to you, stop now and abort.

  3. The SVN mirror synchronization command requires special permissions to do whatever it does. The SVN documentation provides a sample hook script in the form of a Unix shell script. This doesn't help those of us compelled to use Windows for whatever reason. So I use the following hack.

    Create a new empty file in hooks directory of your new repository. Name it pre-revprop-change.bat.

  4. Enter the following contents into this new file.
       set USER=%3
       if "%USER%=="svnsync" goto end
       echo "Only svnsync can change revprops"
       :end
  5. Initialize the synchronization mechanism with the following command.
       svnsync init --username svnsync file:///E:/mirrors/myproject svn://hostname/myproject
    The last URL is the repository you wish to mirror.

Synchronization

Whenever you wish to update your mirror, run
   svnsync sync file:///E:/mirrors/myproject
The first time you do this, it may take a long time (several hours) unless your repository is very small. But subsequent syncs are much quicker.

Troubleshooting

Sometimes your syncs take too long (especially your first one) and you get impatient and abort. This can cause your mirror to become locked. The next time you try to sync, you will get an error. You can unlock your mirror with the following command.
   svn propdel svn:sync-lock --revprop -r 0 file:///E:/mirrors/myproject

Accessing Subversion from Ant

Here is a quick guide to checking out code from a Subversion repository from within an Ant script.
  1. Download svnant - The svnant page is located at http://subclipse.tigris.org/svnant.html. Click on the Documents and Files link and download the latest stable version of svnant.zip.
  2. Unzip - You can unzip it anywhere on your file system.
  3. Copy JARs - Copy the JARs from <svnant>/lib to the <ant>/lib directory.
  4. Insert taskdef - In the build script, include a taskdef like this:
       <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask"/>
    
  5. Sample usage - You can check out a project like this.
       <svn>
          <checkout url="svn://server/repo/project" destPath="project"/>
       </svn>