Thursday, December 4, 2008

SVN -- recursive diffs

It's odd that svn (source control) doesn't have an easy way to see the entire evolution of a file. Since I'm usually wondering how and when something was changed, or just want to see the progression of the changes.

So I just wrote a quick shell script to do this:


#!/bin/bash

# 2008 GPL

if [[ $1 == "" ]]
then

echo "SVN RECURSIVE DIFF"
echo ""
echo "This script will list all svn changes to a file"
echo "the first and last file in the repository"
echo "and a series of diffs that connect them."
echo "IE, you can see the complete evolution of the file."
echo "It's probably best to pipe the output to a file."
echo ""
echo "USE"
echo " svnrdiff "
echo ""
echo "EXAMPLE"
echo " svnrdiff Model/ModelExample.cs > somefile.txt"
echo ""
echo "NOTES"
echo ""
echo "If your log is out of date, use"
echo ""
echo " svn up"
echo ""
echo "If you just want to see who last touched a line, use"
echo ""
echo " svn praise "
exit

fi

v1=""
v2=""
show_current="0"

while read log
do

echo ===================================================================
echo $log
echo ===================================================================

# grab revision numbers of file
v1=$( echo $log | sed -e 's/^r//' -e 's/ .*//' -e 's/-//g' )

if [[ $v2 != "" ]]
then

# print succesive diffs
svn diff -r $v2:$v1 $1

show_current="1"

else

# print first file
svn cat -r $v1 $1

fi

v2=$v1

# list in cronological order (tac)
done < <( svn log $1 | grep -E -e "^r[0-9]+ \| " | tac )

# print last file (if haven't already)
echo ===================================================================
echo "Current snapshot:"
echo ===================================================================
if [[ $show_current == "1" ]]
then
svn cat $1
else
echo "Same as above."
fi

No comments:

Post a Comment