Is there a way to find an SVN revision by searching for a text string that got removed in the file? I know the exact text to search for and which file to look in, but there are hundreds of revisions.
+1
A:
Hi...just a little bash script which filters out the changed lines...If you change pom.xml into your file may with supplemental URL you have what you need...(If you are on Unix like system). Put the following into a script file (xyz.sh) and do a filter on the output.
#!/bin/bash
REVISIONS=`svn log pom.xml -q|grep "^r" | cut -d"r" -f2 | cut -d" " -f1`
for rev in $REVISIONS; do
svn blame -r$rev:$rev pom.xml | tr -s " " | grep -v " -\ \- "
done
xyz.sh | grep "Text you are searching for"
The printout will be something like:
256 ......
The 256 is the revision in which the change had been made.
khmarbaise
2010-04-29 09:06:54
A:
Building on khmarbaise's script, I came up with this:
#!/bin/bash
file="$1"
REVISIONS=`svn log $file -q --stop-on-copy |grep "^r" | cut -d"r" -f2 | cut -d" " -f1`
for rev in $REVISIONS; do
prevRev=$(($rev-1))
difftext=`svn diff --old=$file@$prevRev --new=$file@$rev | tr -s " " | grep -v " -\ \- " | grep -e "$2"`
if [ -n "$difftext" ]; then
echo "$rev: $difftext"
fi
done
pass the file name and search string on the command line:
xyz.sh "filename" "text to search"
svn diff gives me both the rev where it's added and where it's deleted; I'll leave it here in case it's useful to anyone. There's an error message at the last revision that I don't know how to get rid of (I still got a lot of bash to learn :) ) but the rev numbers are correct.
martin_ljchan
2010-04-30 07:07:15