我把它写成一个 cygwin bash 脚本来解决这个问题。
但是,它要求搜索词当前位于文件系统文件中。对于与文件系统 grep 匹配的所有文件,然后执行该文件的所有 svn 差异的 grep。不完美,但对于大多数用途来说应该足够好。希望这可以帮助。
/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 }'