Posts tagged ‘SVN’

Nant SVN changes between two revisions checkout

I went looking for a nant script to checkout changed files between two revisions from SVN. I found some Ant / Java based solutions. As we are using nant I figured I would give it a shot writing it myself. It is easy to get a list of files from SVN using diff. However that doesn’t do you any good if you need to get them from SVN by hand one by one. The trick is to use the list you get from SVN diff and then loop each file and bring it down to the local machine. The biggest gotcha was of course space in file or directory names. If you notice in the script that’s taken care of by inserting %20 in the URL location and local file names are quoted with double quote when doing the SVN export. List of deleted files are written to deletedfiles.txt in the checkout directory, Enjoy !

<?xml version=“1.0”?>
  Exports changes between revision from the given repository URL to checkout Directory
<project name=“SVN_changes”

   Register the sys.* properties; most specifically, sys.env.* for all environment vars

  <!– Properties / defaults –>
  <property name=“checkoutDir” value=“svnchanges”/>
  <property name=“changelog” value=“${checkoutDir}\changelog.txt”/>
  <property name=“delLog” value=“${checkoutDir}\deletedfiles.txt”/>
  <property name=“delFile” value=“”/>
  <property name=“deleteIndicator” value=“D      “/>

  <!– url to svn repository –>
  <property name=“repoURL” value=“”/>
  <property name=“repoUser” value=“testUser” dynamic=“true” />
  <property name=“repoPassword” value=“testPassword” dynamic=“true” />
  <property name=“startingRevision” value=“29455” />
  <property name=“endingRevision” value=“30692” />

  <target name=“getChanges” description=“Get changes from Subversion given two revisions “  >

    <echo message=“Exporting files between revisions ${startingRevision} and ${endingRevision}” />
    <echo message=“from ${repoURL}” />
    <echo message=“to ${checkoutDir}/” />
    <echo message=“——-“ />
    <echo message=“stand by….. “ />
    <echo message=“——-“ />

    <!– Start with a fresh local checkout directory –>
    <mkdir dir=“${checkoutDir}” />

    <!– creates log file comparison from start to end revision –>
    <exec program=“svn”
      commandline=“diff -r ${startingRevision}:${endingRevision} –summarize ${repoURL}”
      output=“${changelog}” />

    <!– Loop the files in the changelog and process –>
    <foreach item=“Line” in=“${changelog}” delim=“,” property=“svnfile”>

      <!– Extract the file name –>
      <property name=“startpos” value=“${string::index-of(svnfile, repoURL) +  string::get-length(repoURL) }” />
      <property name=“length” value=“${string::get-length(svnfile) – int::parse(startpos)}” />
      <property name=“tmpFile” value=“${string::substring( svnfile, startpos, length)}” />
      <!– Space in URL covered –>
      <property name=“repoFile” value=“${string::replace( tmpFile, ‘ ‘, ‘%20’)}” />
      <!– Extract the dir –>
      <property name=“endpos” value=“${string::last-index-of( tmpFile, ‘/’)}” />
      <property name=“localDir” value=“${string::substring( tmpFile, 0, int::parse(endpos))}” />

      <!– Sep –>
      <echo message=“—“/>
      <!– Advertise deleted files between revisions –>
      <if test=“${ string::contains(svnfile, deleteIndicator)}”>
          <echo message=“Deleted file=${tmpFile}”/>
          <property name=“delFile” value=“${tmpFile}”/>
          <call target=“WriteToTextFile” />

      <!– Files to bring down from repository  –>
      <if test=“${ not string::contains(svnfile, deleteIndicator)}”>
            Create the dir before checkout, this might happen multible times
            for files in the same dir, don‘t fail it.
          <mkdir dir="${checkoutDir}${localDir}" failonerror="false"/>
          <!– Check out the file –>
          <echo message="svn export ${repoURL}${repoFile} &quot;${checkoutDir}${tmpFile}&quot; -r ${endingRevision} –force " />
          <exec program="svn"
                commandline="export ${repoURL}${repoFile} &quot;${checkoutDir}${tmpFile}&quot; -r ${endingRevision} –force"

    <!– Show user that it’s all done –>
    <echo message=”   “ />
    <echo message=“——-“ />
    <echo message=“Changed and new files have been exported to the ${checkoutDir} directory” />
    <echo message=“List of deleted files can be found in the ${delLog} file” />
    <echo message=“——-“ />
    <echo message=“Done !” />

  <!– Appends deleted files to text file –>
  <target name=“WriteToTextFile” >
    <script language=“C#” mainclass=“writeToDelLog”>
        <include name=“System.Management.dll” />
      <div class=“codesnip-container” ><![CDATA[
            class writeToDelLog
                public static void ScriptMain(Project project)
                                      PropertyDictionary pd = project.Properties;       
                    string sDeletedFile = pd[“delLog”];
                    string sDeletedEntry = pd[“delFile”];
                    FileStream stream = new FileStream(sDeletedFile, FileMode.Append );
                    StreamWriter writer = new StreamWriter(stream);

                    catch( Exception ex )
                      Console.WriteLine( “NOT able to write to file, error=” + ex );
                      if( writer != null ) writer.Close();
                      if( stream != null ) stream.Close();


Bundled Apache + SVN

I finally installed Subversion as my local repository. I had used the windows CollabNet server at work it works great, but I decided to try VisualSVN at home. I have to say I like VisualSVN better. With the latest version both of them give you the ability to install Apache during install, but VisualSVN takes the win with their management console. Very easy to use GUI, similar to the Microsoft Sql Server. From the console you can setup up your repositories, users and groups. It is also very convenient to setup group permissions for your repositories.


Note, when you install the Apache server wants to use port 80 or 443 / SSL port. Of course if you have IIS running you will most likely be using those ports for IIS. So either shut down IIS, or figure out which ones gets to use the default port.

Installing on Windows and using the VisualSVN console I had one user and two repositories up in about 5 minutes, very snappy indeed.

Apache http access for SVN Repository

I had to add http access for our SVN repository at work, which was happily serving on the default SVN port. However after changing to our new network the SVN port has been shut down and the IT guys are in no hurry to open it up. I thought I remembered Apache can be chained with SVN for http access, went looking and sure enough. So here is a quick step tutorial with minimum configuration if you need to do the same.

1 – Download and install Apache 2.2
I’m installing at c:\apps\apache2.

2 – Copy modules from Subversion to Apache modules

if needed

3 – Modify the Apache httpd.conf to load the SVN modules
Add the following two lines to your
file, just look for all of the lines that start with LoadModule, put them at the end of the list

LoadModule dav_svn_module modules/
LoadModule authz_svn_module modules/

Now un-comment this line in httpd.conf, it will look like this
LoadModule dav_module modules/

4 – Add your svn location info to httpd.conf
At the very bottom of your httpd.conf file add these lines:

<Location /svn>
DAV svn
SVNParentPath  c:\apps\subversion\svn_repos

AuthType Basic
AuthName "Subversion Repository"
AuthUserFile conf/password.pass
Require valid-user

5 – Create an Apache password file
To allow Apache to handle authentication for you, you’ll need to create a password file. Open a command prompt,
cd c:\apps\apache2\bin
htpasswd –c passwords.pass newuser

Enter the password for newuser, to add additional users

htpasswd passwords.pass anotherUser

When you have added all the users copy the passwords.pass file over to the

6 – Start the Apache service from Services
If you get errors open dos window and run Apache manually
You should see the errors reported.

7 – Access your repository over http
With Tortiese goto the repo browser, enter the appropriate path, something like the following.
You will be prompted for the user and password and should be all good to go. You should also be able to open the location in a web browser.

This quick step guide is based on the more comprehensive guide at inetsolution. That guide is great and covers setup of SVN+Apache, SSL access and group permissions.