Skip to content

Commit 3c8f6c8

Browse files
committed
Revert 3081623 and 7e62265
It seems that we have bad interaction with the code related to GIT_WORK_TREE and "grep --no-index", and broke running grep inside the .git directory. For now, just revert it and resurrect it after 1.7.0 ships. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8bff7c5 commit 3c8f6c8

File tree

4 files changed

+1
-96
lines changed

4 files changed

+1
-96
lines changed

Documentation/RelNotes-1.7.0.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ Updates since v1.6.6
133133
* "git grep" does not rely on external grep anymore. It can use more than
134134
one threads to accelerate the operation.
135135

136-
* "git grep" learned "--no-index" option, to search inside contents that
137-
are not managed by git.
138-
139136
* "git grep" learned "--quiet" option.
140137

141138
* "git log" and friends learned "--glob=heads/*" syntax that is a more

builtin-grep.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "userdiff.h"
1515
#include "grep.h"
1616
#include "quote.h"
17-
#include "dir.h"
1817

1918
#ifndef NO_PTHREADS
2019
#include "thread-utils.h"
@@ -646,24 +645,6 @@ static int grep_object(struct grep_opt *opt, const char **paths,
646645
die("unable to grep from object of type %s", typename(obj->type));
647646
}
648647

649-
static int grep_directory(struct grep_opt *opt, const char **paths)
650-
{
651-
struct dir_struct dir;
652-
int i, hit = 0;
653-
654-
memset(&dir, 0, sizeof(dir));
655-
setup_standard_excludes(&dir);
656-
657-
fill_directory(&dir, paths);
658-
for (i = 0; i < dir.nr; i++) {
659-
hit |= grep_file(opt, dir.entries[i]->name);
660-
if (hit && opt->status_only)
661-
break;
662-
}
663-
free_grep_patterns(opt);
664-
return hit;
665-
}
666-
667648
static int context_callback(const struct option *opt, const char *arg,
668649
int unset)
669650
{
@@ -758,12 +739,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
758739
const char **paths = NULL;
759740
int i;
760741
int dummy;
761-
int nongit = 0, use_index = 1;
762742
struct option options[] = {
763743
OPT_BOOLEAN(0, "cached", &cached,
764744
"search in index instead of in the work tree"),
765-
OPT_BOOLEAN(0, "index", &use_index,
766-
"--no-index finds in contents not managed by git"),
767745
OPT_GROUP(""),
768746
OPT_BOOLEAN('v', "invert-match", &opt.invert,
769747
"show non-matching lines"),
@@ -846,8 +824,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
846824
OPT_END()
847825
};
848826

849-
prefix = setup_git_directory_gently(&nongit);
850-
851827
/*
852828
* 'git grep -h', unlike 'git grep -h <pattern>', is a request
853829
* to show usage information and exit.
@@ -885,10 +861,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
885861
PARSE_OPT_STOP_AT_NON_OPTION |
886862
PARSE_OPT_NO_INTERNAL_HELP);
887863

888-
if (use_index && nongit)
889-
/* die the same way as if we did it at the beginning */
890-
setup_git_directory();
891-
892864
/* First unrecognized non-option token */
893865
if (argc > 0 && !opt.pattern_list) {
894866
append_grep_pattern(&opt, argv[0], "command line", 0,
@@ -950,18 +922,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
950922
paths[1] = NULL;
951923
}
952924

953-
if (!use_index) {
954-
int hit;
955-
if (cached)
956-
die("--cached cannot be used with --no-index.");
957-
if (list.nr)
958-
die("--no-index cannot be used with revs.");
959-
hit = grep_directory(&opt, paths);
960-
if (use_threads)
961-
hit |= wait_all();
962-
return !hit;
963-
}
964-
965925
if (!list.nr) {
966926
int hit;
967927
if (!cached)

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static void handle_internal_command(int argc, const char **argv)
317317
{ "fsck-objects", cmd_fsck, RUN_SETUP },
318318
{ "gc", cmd_gc, RUN_SETUP },
319319
{ "get-tar-commit-id", cmd_get_tar_commit_id },
320-
{ "grep", cmd_grep, USE_PAGER },
320+
{ "grep", cmd_grep, RUN_SETUP | USE_PAGER },
321321
{ "hash-object", cmd_hash_object },
322322
{ "help", cmd_help },
323323
{ "index-pack", cmd_index_pack },

t/t7002-grep.sh

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -434,56 +434,4 @@ test_expect_success 'grep -Fi' '
434434
test_cmp expected actual
435435
'
436436

437-
test_expect_success 'outside of git repository' '
438-
rm -fr non &&
439-
mkdir -p non/git/sub &&
440-
echo hello >non/git/file1 &&
441-
echo world >non/git/sub/file2 &&
442-
echo ".*o*" >non/git/.gitignore &&
443-
{
444-
echo file1:hello &&
445-
echo sub/file2:world
446-
} >non/expect.full &&
447-
echo file2:world >non/expect.sub
448-
(
449-
GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
450-
export GIT_CEILING_DIRECTORIES &&
451-
cd non/git &&
452-
test_must_fail git grep o &&
453-
git grep --no-index o >../actual.full &&
454-
test_cmp ../expect.full ../actual.full
455-
cd sub &&
456-
test_must_fail git grep o &&
457-
git grep --no-index o >../../actual.sub &&
458-
test_cmp ../../expect.sub ../../actual.sub
459-
)
460-
'
461-
462-
test_expect_success 'inside git repository but with --no-index' '
463-
rm -fr is &&
464-
mkdir -p is/git/sub &&
465-
echo hello >is/git/file1 &&
466-
echo world >is/git/sub/file2 &&
467-
echo ".*o*" >is/git/.gitignore &&
468-
{
469-
echo file1:hello &&
470-
echo sub/file2:world
471-
} >is/expect.full &&
472-
: >is/expect.empty &&
473-
echo file2:world >is/expect.sub
474-
(
475-
cd is/git &&
476-
git init &&
477-
test_must_fail git grep o >../actual.full &&
478-
test_cmp ../expect.empty ../actual.full &&
479-
git grep --no-index o >../actual.full &&
480-
test_cmp ../expect.full ../actual.full &&
481-
cd sub &&
482-
test_must_fail git grep o >../../actual.sub &&
483-
test_cmp ../../expect.empty ../../actual.sub &&
484-
git grep --no-index o >../../actual.sub &&
485-
test_cmp ../../expect.sub ../../actual.sub
486-
)
487-
'
488-
489437
test_done

0 commit comments

Comments
 (0)