How to remove SVN Properties from SVN Diff

Filed Under: Scripts

I use SVN for my projects version control system. Sometimes I need to see the difference between two tags or two branches but when I run “svn diff” command, it gives a whole bunch of SVN Properties changes in output. I was looking for a way to remove these but built in svn diff options doesn’t provide this feature.

So I wrote a shell script that does this job for me, the idea is to first use SVN Diff summarise option with grep and awk to find out the file names where text changes are present, then iterate over this list to generate SVN diff and append that to a file to generate the final diff.


#!/bin/bash
# Call this script to generate clean svn diff
url1=$1
url2=$2
#If URLs don't end with /, add them
if [ "${url1#${url1%?}}" != "/" ];
then
url1=$url1"/"
fi
if [ "${url2#${url2%?}}" != "/" ];
then
url2=$url2"/"
fi

echo $url1
echo $url2
#Get the length of url1, will be used later on
length1=${#url1}

# Below command will get all the files with text changes and store them in files variable
files=$(svn diff $url1 $url2 --summarize | grep -v '^ ' | awk '{print substr($0,9)}')
#Generate diff for each of the files and save it in a new file
for f in $files
	do
		f2=${url2}${f:${length1}}
		$(svn diff $f $f2 >> svn_diff_clean.txt)
		echo "processed $f and $f2"
	done
echo "done"

When I execute the above script by passing two URLs, it generates svn_diff_clean.txt having full-text diffs. I used this script to generate diff in my project and the number of lines in output was reduced by almost 50%. However, it depends on project structure and metadata usage.

Tip: If you need to give a password every time while running SVN commands, try to delete the .subversion folder from home directory and then run it, it will ask password only for first time and then use the cached password.

The script doesn’t handle bad URLs or null inputs, but I am too lazy to do that. 🙂

Comments

  1. Sean says:

    svn diff –ignore-properties

  2. Craig Condit says:

    There’s actually a much simpler way:

    $ svn diff … | filterdiff

    filterdiff is included in the patchutils package in most Linux distros (not sure about Mac OS X, but Fink or MacPorts probably has it too). Called with no arguments, it strips invalid markers from patch files. It can also be used to do things like filter a diff based on file patterns, or even line numbers.

    1. Pankaj says:

      Thats a new thing for me. Thanks for the information.

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages