2005-09-13 03:06:10 +08:00
|
|
|
#!/bin/sh
|
2005-09-13 07:46:53 +08:00
|
|
|
#
|
|
|
|
# Copyright (c) Linus Torvalds, 2005
|
|
|
|
#
|
|
|
|
|
2006-01-21 07:00:12 +08:00
|
|
|
USAGE='[<option>...] [-e] <pattern> [<path>...]'
|
2005-12-14 06:30:31 +08:00
|
|
|
SUBDIRECTORY_OK='Yes'
|
|
|
|
. git-sh-setup
|
|
|
|
|
2006-01-21 07:00:12 +08:00
|
|
|
got_pattern () {
|
|
|
|
if [ -z "$no_more_patterns" ]
|
|
|
|
then
|
|
|
|
pattern="$1" no_more_patterns=yes
|
|
|
|
else
|
|
|
|
die "git-grep: do not specify more than one pattern"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
no_more_patterns=
|
2005-09-13 07:46:53 +08:00
|
|
|
pattern=
|
|
|
|
flags=()
|
|
|
|
git_flags=()
|
|
|
|
while : ; do
|
|
|
|
case "$1" in
|
2006-01-21 07:00:12 +08:00
|
|
|
-o|--cached|--deleted|--others|--killed|\
|
|
|
|
--ignored|--modified|--exclude=*|\
|
2005-09-13 07:46:53 +08:00
|
|
|
--exclude-from=*|\--exclude-per-directory=*)
|
|
|
|
git_flags=("${git_flags[@]}" "$1")
|
|
|
|
;;
|
|
|
|
-e)
|
2006-01-21 07:00:12 +08:00
|
|
|
got_pattern "$2"
|
2005-09-13 07:46:53 +08:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-A|-B|-C|-D|-d|-f|-m)
|
|
|
|
flags=("${flags[@]}" "$1" "$2")
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--)
|
2006-01-21 07:00:12 +08:00
|
|
|
# The rest are git-ls-files paths
|
2005-09-13 07:46:53 +08:00
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
flags=("${flags[@]}" "$1")
|
|
|
|
;;
|
|
|
|
*)
|
2006-01-21 07:00:12 +08:00
|
|
|
if [ -z "$no_more_patterns" ]
|
|
|
|
then
|
|
|
|
got_pattern "$1"
|
2005-09-13 07:46:53 +08:00
|
|
|
shift
|
|
|
|
fi
|
2006-01-21 07:00:12 +08:00
|
|
|
[ "$1" = -- ] && shift
|
2005-09-13 07:46:53 +08:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2005-09-13 03:06:10 +08:00
|
|
|
done
|
2005-11-17 01:38:46 +08:00
|
|
|
[ "$pattern" ] || {
|
2005-12-14 06:30:31 +08:00
|
|
|
usage
|
2005-11-17 01:38:46 +08:00
|
|
|
}
|
2006-01-21 07:00:12 +08:00
|
|
|
git-ls-files -z "${git_flags[@]}" -- "$@" |
|
|
|
|
xargs -0 grep "${flags[@]}" -e "$pattern" --
|