get_revision(): do not dig deeper when we know we are at the end.
[git/debian.git] / git-grep.sh
blobad4f2fe81046505c43684e8c26f0eeaac6cc6146
1 #!/bin/sh
3 # Copyright (c) Linus Torvalds, 2005
6 USAGE='[<option>...] [-e] <pattern> [<path>...]'
7 SUBDIRECTORY_OK='Yes'
8 . git-sh-setup
10 got_pattern () {
11 if [ -z "$no_more_patterns" ]
12 then
13 pattern="$1" no_more_patterns=yes
14 else
15 die "git-grep: do not specify more than one pattern"
19 no_more_patterns=
20 pattern=
21 flags=()
22 git_flags=()
23 while : ; do
24 case "$1" in
25 -o|--cached|--deleted|--others|--killed|\
26 --ignored|--modified|--exclude=*|\
27 --exclude-from=*|\--exclude-per-directory=*)
28 git_flags=("${git_flags[@]}" "$1")
30 -e)
31 got_pattern "$2"
32 shift
34 -A|-B|-C|-D|-d|-f|-m)
35 flags=("${flags[@]}" "$1" "$2")
36 shift
38 --)
39 # The rest are git-ls-files paths
40 shift
41 break
43 -*)
44 flags=("${flags[@]}" "$1")
47 if [ -z "$no_more_patterns" ]
48 then
49 got_pattern "$1"
50 shift
52 [ "$1" = -- ] && shift
53 break
55 esac
56 shift
57 done
58 [ "$pattern" ] || {
59 usage
61 git-ls-files -z "${git_flags[@]}" -- "$@" |
62 xargs -0 grep "${flags[@]}" -e "$pattern" --