Tuesday 27 September 2011

Bash script to extract a range of revision diffs

A quick Bash script hack to extract all CVS/SVN diffs from a range of revisions:

for start_ver in {1..25};
do end_ver=`echo "$start_ver + 1" | bc`;
cvs diff -kk -c -r 1.$start_ver -r 1.$end_ver source.file >> diff_output.txt;
done;

This script will incrementally extract all differences between version 1.1 and 1.26 and write them to the diff_output.txt file. Incremental in this context means changes between each revision, so the output will contain the diff between version 1.1 and 1.2 followed by the diff between 1.2 and 1.3, then 1.3 and 1.4 etc.

A few notes (as always):

  • The script should be run in the directory containing the file the diff is being run for (source.file in the example)
  • The physical revision numbers can be replaced with tags (assuming sequential numerical naming of the tags)
  • The diff options (-kk -c) can be changed for the required diff output format
  • This was a quick hack and can almost certainly be improved