It is good practice to remove old code instead of just commenting it out. It is often claimed that the old code parts can always be found again in the old SVN repository revision, if needed.
But practically, it's not that easy, right? If the old code is in some unknown old SVN revision then it can be quite hard to find.
I'm exactly in that situation right now: There's a function that I don't need anymore, and I should throw it out, since it's in SVN, but I hesitate because I might need it again, and I'm afraid it's going to be hard to find in the repository.
Of course, one can always make a commit message, saying "removed function myFunction", but sometimes you can't note every little code removal in the commit message, and it can also be tedious to look through all commit messages to find something again.
An automatic tool would be better, something like
svn find "void myFunction\(" my-file.cc
which would tell me the different results from different revisions. Does something like that exist?
EDIT: Do other version control systems have it? Git maybe? (That'd be a reason to switch, I'd say.)
UPDATE: So there's no real answer except the tiny brittle shell
script I found more or less by accident (see my answer below). I think, that's really a shame for SVN. Finding something in earlier revisions should be one of the central functionalities of version control. Does anyone have more info?
I googled some more and found the following script (see here). I tested it briefly and it seems to be working fine:
rev_grep.sh
=====================
#!/bin/ksh
URL=$1
REGEX=$2
LAST_REV="n/a"
svn log -q $URL | perl -ne 'print "$1\n" if /^r(\d+)/' |
while read r
do
##svn cat -r $r $URL | grep "$REGEX" > /dev/null
BUFFER=`svn cat -r $r $URL | grep "$REGEX"`
RET=$?
if [ $RET -eq 0 ]
then
echo "Match in revision: $r. Removed in $LAST_REV."
echo $BUFFER
exit 0
elif [ $RET -ne 1 ]
then
## grep hit an error
exit 2
fi
LAST_REV=$r
done
exit 1
The only problem is that, if your repository requires a password, you'll have to enter it many times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With