08.18
While applying some (550) changesets I needed some good tools to show me the differences between files and revisions.
The first one I found very useful was:
svn diff --diff-cmd diff -x -uw -r REV1:REV2 FILE;
which is even better in combination with colordiff:
apt-get install colordiff; svn diff --diff-cmd diff -x -uw -r REV1:REV2 FILE | colordiff;
An other great tool is vimdiff, which starts Vim as usual, and additionally sets it up for viewing the differences between files. Here’s how I use it:
sudo apt-get install vim; vimdiff -O -c 'set diffopt+=iwhite,filler' FILE1 FILE2;
Some of you will probably prefer Meld, which is a visual diff and merge tool.
To combine the powers of all three I created a simple (Bash) wrapper. It downloads two revisions (svn) of a file and compares them using a diff tool of choice:
#!/bin/bash # # set -x; # if [ -z "${1}" ] || [ -z "${2}" ] || [ -z "${3}" ]; then echo ""; echo "Use the script as discribed below:"; echo "$0 [ filename ] [ revision1 ] [ revision2 ] [ diff tool (optionally) ]"; echo ""; else pid=$$; filename="${1}"; revision1="${2}"; revision2="${3}"; diff_command="${4}"; temp1="/tmp/${pid}.${revision1}.${filename}"; temp2="/tmp/${pid}.${revision2}.${filename}"; trap trap_function 0 1 2 15; trap_function() { if [ -f "${temp1}" ]; then rm "${temp1}"; fi if [ -f "${temp2}" ]; then rm "${temp2}"; fi } svn cat "${filename}" -r "${revision1}" > "${temp1}"; svn cat "${filename}" -r "${revision2}" > "${temp2}"; if [ "${diff_command}" == "vimdiff" ]; then vimdiff -O -c 'set diffopt+=iwhite,filler' "${temp1}" "${temp2}"; elif [ "${diff_command}" == "meld" ]; then meld --diff "${temp1}" "${temp2}"; else diff -uw "${temp1}" "${temp2}" | colordiff; fi fi