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
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.
- Start a command window and CD to E:\mirrors.
- 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.
- 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.
- Enter the following contents into this new file.
set USER=%3
if "%USER%=="svnsync" goto end
echo "Only svnsync can change revprops"
:end
- 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.
- 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.
- Unzip - You can unzip it anywhere on your file system.
- Copy JARs - Copy the JARs from
<svnant>/lib to the
<ant>/lib directory.
- Insert taskdef - In the build script, include a
taskdef like this:
<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask"/>
- Sample usage - You can check out a project like this.
<svn>
<checkout url="svn://server/repo/project" destPath="project"/>
</svn>