Suppose you want to find the first Subversion checkin where a particular string appeared. `svn blame [filename]` gets you some distance toward that goal, but it doesn’t entirely work: `svn blame` will tell you the person *most recently* responsible for tweaking the particular line of code where that string appears. If someone came along between when that line was introduced and now and, say, changed all Unix line endings to DOS ones, `svn blame` will suggest that the interloper is the one responsible for that line.
So what you want is the *first* revision number in which that change appeared. So far as I can tell, there’s no built-in svn command to give you this information. This shell-scripting business is the best I could come up with:
#!/bin/bash
string=$1
filename=$2
if test -z $string; then
echo “Must supply a string to search for”
exit 1
fi
if test -z $filename; then
echo “Must supply a filename to search”
exit 1
fi
# Get all svn revision numbers in which $filename
# was involved, in ascending order.
all_rev_nums=`svn log $filename
|grep -o ‘^r[0-9]+’
|grep -o ‘[0-9]+$’
|sort -n`
for revnum in $all_rev_nums; do
if svn cat -r$revnum $filename |grep -q $string; then
svn blame -r $revnum $filename |grep $string
# Since they’re in ascending order, we’ve found
# the first one. So we can quit now.
exit 0
fi
done
# If we never found $string in any revision
# of $filename, return an error.
exit 1
1) Use git-svn instead of bare svn
2) Run git blame -w
LikeLike
I need to be switching to git right quick. Either that or hg. Seems like all the cool kids are using those these days.
LikeLike
0 Pingbacks