I use subversion quite extensively for PHP code versioning (in particular the excellent Redmine software project management tool has a built in subversion server) and recently had a requirement to produce a set of files that had changed from one revision to another. Specifically my repository has some changes committed to it that I don’t want propagating to the live server just yet, but I want some later changes moving across.
Subversion offers excellent branch / tag support, so if I’d thought this through properly I could have created a new branch for the dangerous changes I didn’t want to move to live, then merged any changes from there onwards back into the ‘live’ trunk…basically keeping two seperate branches in the repository.
However, as usual I didn’t think it through and had to hack together a solution to fit the problem.
Here’s the solution, it’s a bash shell script that takes 2 revisions as an argument and produces a directory containing all the files that have changed between those two revisions, maintaining the directory structure. You pretty much end up with a directory that you can drop straight into your live site to update it to whatever revision you like.
For example, my live site is at revision 10. I committed changes at revision 11 that I don’t want going into the live site, but everything from 12 onwards to the current revision of 15 needs patching in. run ‘make patch 12 15’ and then drop the produced directory into your live site.
#!/bin/bash #simple script to make a very simple patch from a repository #call with make patch.sh low high # # where low is the revision your unpatched project is currently at # and high is the revision you want the patch to go up to # eg: if your live system is at revision 100 and you want to # patch it to revision 120 you'd do: # #our subversion url url=svn://svn-server/my-repo/ #first we need to get a list of changes since requested revision svn diff -r$1:$2 $url --summarize > filelist.txt #now remove the repo information from each line, so we're just left with the path from the root upwards sed -i "s#svn://redmine.tyrrellsystems.com/tms/tms_dev/Trunk/# #g" filelist.txt sed -i "s#M # #g" filelist.txt sed -i "s#A # #g" filelist.txt #now loop through what we've got #create the relevant folder, and export the file into it for i in $(cat filelist.txt); do filename=$(basename $i); path=$(dirname $i); mkdir -p patch-r$1/$path svn export --force $url$path/$filename patch-r$1/$path/$filename echo "$filename"; done