Is there a way to perform a full text search of a subversion repository, including all the history?
For example, I\'ve written a feature that I used somewhere, but t
I wrote this as a cygwin bash script to solve this problem.
However it requires that the search term is currently within the filesystem file. For all the files that match the filesystem grep, an grep of all the svn diffs for that file are then performed. Not perfect, but should be good enough for most usage. Hope this helps.
/usr/local/bin/svngrep
#!/bin/bash
# Usage: svngrep $regex @grep_args
regex="$@"
pattern=`echo $regex | perl -p -e 's/--?\S+//g; s/^\\s+//;'` # strip --args
if [[ ! $regex ]]; then
echo "Usage: svngrep \$regex @grep_args"
else
for file in `grep -irl --no-messages --exclude=\*.tmp --exclude=\.svn $regex ./`; do
revs="`svnrevisions $file`";
for rev in $revs; do
diff=`svn diff $file -r$[rev-1]:$rev \
--diff-cmd /usr/bin/diff -x "-Ew -U5 --strip-trailing-cr" 2> /dev/null`
context=`echo "$diff" \
| grep -i --color=none -U5 "^\(+\|-\).*$pattern" \
| grep -i --color=always -U5 $pattern \
| grep -v '^+++\|^---\|^===\|^Index: ' \
`
if [[ $context ]]; then
info=`echo "$diff" | grep '^+++\|^---'`
log=`svn log $file -r$rev`
#author=`svn info -r$rev | awk '/Last Changed Author:/ { print $4 }'`;
echo "========================================================================"
echo "========================================================================"
echo "$log"
echo "$info"
echo "$context"
echo
fi;
done;
done;
fi
/usr/local/bin/svnrevisions
#!/bin/sh
# Usage: svnrevisions $file
# Output: list of fully numeric svn revisions (without the r), one per line
file="$@"
svn log "$file" 2> /dev/null | awk '/^r[[:digit:]]+ \|/ { sub(/^r/,"",$1); print $1 }'