Creating SVN patches and saving them as ZIP file

I use SVN as source control system for one of my projects. Sometimes I want to create patches in form of a zip file containing the changed/new files. Doing so manually is a pain and error prone. First you have to diff between your branches to find all change since your last release, export those files from SVN, then package them into a proper structured ZIP file.
So here is a PowerShell snippet doing exactly that automatically:

function new-patch
{
    param($from, $to)
    # get diff summary as XML
    [xml] $summary = (svn diff $to $from -x --ignore-eol-style --xml --summarize)
    # loop through all diff/paths/path nodes
    # each node represents a modified/new file
    foreach($item in $summary.diff.paths.path)
    {
        # the SVN url
        $url=$item."#text"
        # the relative filename
        $file=($item."#text".Substring($to.Length))
        # the parent directory
        $dir=($file | split-path -parent)
        # create parent directory if it doesn't exist already
        if((test-path $dir) -eq $false) { mkdir $dir -force}
        # export current files from the SVN repository
        svn export $url $file
    }
    # package the current dir (.) into patch.zip
    sevenzip.exe a patch.zip .
}

The function is then used like this:

PS> new-patch "https://actiongame.svn.sourceforge.net/svnroot/
actiongame/tags/v01_00_00/" "https://actiongame.svn.sourceforge.net/svnroot/actiongame/branches/v01_00_xx/"

I specified the old branch as first argument and the new branch as second argument. Now after processing I get all the changes as proper filetree inside a zip file. Ready to ship..

The whole process could be optimized quite a bit. Right now a new SVN request is sent for each single file, it could as well be batched into one request to improve the export performance.

Advertisements

1 Response to “Creating SVN patches and saving them as ZIP file”


  1. 1 link September 14, 2012 at 3:39 pm

    Amazing! Its genuinely remarkable paragraph, I have got much clear
    idea concerning from this article.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: