Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 934
martin_ljchan Avatar asked Apr 29 '10 08:04

martin_ljchan


People also ask

How do I checkout a specific revision in svn?

Click the revision button at top-right and change it to the revision you want. Then right-click your file in the browser and use 'Copy to working copy...' but change the filename it will check out, to avoid a clash.

How do you find the difference between two svn revisions?

Display the differences between two paths. The ways you can use svn diff are: Use just svn diff'to display local modifications in a working copy. Display the changes made to TARGET s as they are seen in REV between two revisions.

What is WC revision?

Your working revision is the your latest update revision. Your working revision may be behind server's latest revision. For example. You update all of your files and get 1002 revision number.


2 Answers

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.

like image 158
martin_ljchan Avatar answered Sep 24 '22 01:09

martin_ljchan


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.

like image 22
khmarbaise Avatar answered Sep 24 '22 01:09

khmarbaise