Skip to content

Commit

Permalink
Merge branch 'maint-1.6.4' into maint
Browse files Browse the repository at this point in the history
* maint-1.6.4:
  grep: do not segfault when -f is used
  • Loading branch information
Junio C Hamano committed Oct 17, 2009
2 parents b3118bd + cfe370c commit 050dfc4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
struct grep_opt *grep_opt = opt->value;
FILE *patterns;
int lno = 0;
struct strbuf sb;
struct strbuf sb = STRBUF_INIT;

patterns = fopen(arg, "r");
if (!patterns)
Expand Down
66 changes: 66 additions & 0 deletions t/t7002-grep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,72 @@ test_expect_success 'grep -e A --and --not -e B' '
test_cmp expected actual
'

test_expect_success 'grep -f, non-existent file' '
test_must_fail git grep -f patterns
'

cat >expected <<EOF
file:foo mmap bar
file:foo_mmap bar
file:foo_mmap bar mmap
file:foo mmap bar_mmap
file:foo_mmap bar mmap baz
EOF

cat >pattern <<EOF
mmap
EOF

test_expect_success 'grep -f, one pattern' '
git grep -f pattern >actual &&
test_cmp expected actual
'

cat >expected <<EOF
file:foo mmap bar
file:foo_mmap bar
file:foo_mmap bar mmap
file:foo mmap bar_mmap
file:foo_mmap bar mmap baz
t/a/v:vvv
t/v:vvv
v:vvv
EOF

cat >patterns <<EOF
mmap
vvv
EOF

test_expect_success 'grep -f, multiple patterns' '
git grep -f patterns >actual &&
test_cmp expected actual
'

cat >expected <<EOF
file:foo mmap bar
file:foo_mmap bar
file:foo_mmap bar mmap
file:foo mmap bar_mmap
file:foo_mmap bar mmap baz
t/a/v:vvv
t/v:vvv
v:vvv
EOF

cat >patterns <<EOF
mmap
vvv
EOF

test_expect_success 'grep -f, ignore empty lines' '
git grep -f patterns >actual &&
test_cmp expected actual
'

cat >expected <<EOF
y:y yy
--
Expand Down

0 comments on commit 050dfc4

Please sign in to comment.