Search code examples
svnsearchrevision

find svn revision by removed text


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.


Solution

  • 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.