Code

Revert 30816237 and 7e62265
authorJunio C Hamano <gitster@pobox.com>
Fri, 5 Feb 2010 17:20:01 +0000 (09:20 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Feb 2010 17:27:25 +0000 (09:27 -0800)
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 <gitster@pobox.com>
Documentation/RelNotes-1.7.0.txt
builtin-grep.c
git.c
t/t7002-grep.sh

index 255666f15d73b266ef896f28ab8fcbb2e4200bca..f632662612ea0a68777a4f51cd711b20545b185e 100644 (file)
@@ -133,9 +133,6 @@ Updates since v1.6.6
  * "git grep" does not rely on external grep anymore.  It can use more than
    one threads to accelerate the operation.
 
- * "git grep" learned "--no-index" option, to search inside contents that
-   are not managed by git.
-
  * "git grep" learned "--quiet" option.
 
  * "git log" and friends learned "--glob=heads/*" syntax that is a more
index 0ef849cb84650705ffc840aed8a3fcedbeb48f9a..26d4deb1cce3e5540411a47fdf35085649669d06 100644 (file)
@@ -14,7 +14,6 @@
 #include "userdiff.h"
 #include "grep.h"
 #include "quote.h"
-#include "dir.h"
 
 #ifndef NO_PTHREADS
 #include "thread-utils.h"
@@ -646,24 +645,6 @@ static int grep_object(struct grep_opt *opt, const char **paths,
        die("unable to grep from object of type %s", typename(obj->type));
 }
 
-static int grep_directory(struct grep_opt *opt, const char **paths)
-{
-       struct dir_struct dir;
-       int i, hit = 0;
-
-       memset(&dir, 0, sizeof(dir));
-       setup_standard_excludes(&dir);
-
-       fill_directory(&dir, paths);
-       for (i = 0; i < dir.nr; i++) {
-               hit |= grep_file(opt, dir.entries[i]->name);
-               if (hit && opt->status_only)
-                       break;
-       }
-       free_grep_patterns(opt);
-       return hit;
-}
-
 static int context_callback(const struct option *opt, const char *arg,
                            int unset)
 {
@@ -758,12 +739,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
        const char **paths = NULL;
        int i;
        int dummy;
-       int nongit = 0, use_index = 1;
        struct option options[] = {
                OPT_BOOLEAN(0, "cached", &cached,
                        "search in index instead of in the work tree"),
-               OPT_BOOLEAN(0, "index", &use_index,
-                       "--no-index finds in contents not managed by git"),
                OPT_GROUP(""),
                OPT_BOOLEAN('v', "invert-match", &opt.invert,
                        "show non-matching lines"),
@@ -846,8 +824,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                OPT_END()
        };
 
-       prefix = setup_git_directory_gently(&nongit);
-
        /*
         * 'git grep -h', unlike 'git grep -h <pattern>', is a request
         * to show usage information and exit.
@@ -885,10 +861,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                             PARSE_OPT_STOP_AT_NON_OPTION |
                             PARSE_OPT_NO_INTERNAL_HELP);
 
-       if (use_index && nongit)
-               /* die the same way as if we did it at the beginning */
-               setup_git_directory();
-
        /* First unrecognized non-option token */
        if (argc > 0 && !opt.pattern_list) {
                append_grep_pattern(&opt, argv[0], "command line", 0,
@@ -950,18 +922,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                paths[1] = NULL;
        }
 
-       if (!use_index) {
-               int hit;
-               if (cached)
-                       die("--cached cannot be used with --no-index.");
-               if (list.nr)
-                       die("--no-index cannot be used with revs.");
-               hit = grep_directory(&opt, paths);
-               if (use_threads)
-                       hit |= wait_all();
-               return !hit;
-       }
-
        if (!list.nr) {
                int hit;
                if (!cached)
diff --git a/git.c b/git.c
index b3e23f10441924de45ab768e086ead90b214d4c7..4c3028c098c03c842d2a635d054d3c27653dd511 100644 (file)
--- a/git.c
+++ b/git.c
@@ -317,7 +317,7 @@ static void handle_internal_command(int argc, const char **argv)
                { "fsck-objects", cmd_fsck, RUN_SETUP },
                { "gc", cmd_gc, RUN_SETUP },
                { "get-tar-commit-id", cmd_get_tar_commit_id },
-               { "grep", cmd_grep, USE_PAGER },
+               { "grep", cmd_grep, RUN_SETUP | USE_PAGER },
                { "hash-object", cmd_hash_object },
                { "help", cmd_help },
                { "index-pack", cmd_index_pack },
index bf4d4dcb2bc577715a02ae01f95a5be348e40384..7144f815c07a46e4f39a0f739fb964467fd27a16 100755 (executable)
@@ -434,56 +434,4 @@ test_expect_success 'grep -Fi' '
        test_cmp expected actual
 '
 
-test_expect_success 'outside of git repository' '
-       rm -fr non &&
-       mkdir -p non/git/sub &&
-       echo hello >non/git/file1 &&
-       echo world >non/git/sub/file2 &&
-       echo ".*o*" >non/git/.gitignore &&
-       {
-               echo file1:hello &&
-               echo sub/file2:world
-       } >non/expect.full &&
-       echo file2:world >non/expect.sub
-       (
-               GIT_CEILING_DIRECTORIES="$(pwd)/non/git" &&
-               export GIT_CEILING_DIRECTORIES &&
-               cd non/git &&
-               test_must_fail git grep o &&
-               git grep --no-index o >../actual.full &&
-               test_cmp ../expect.full ../actual.full
-               cd sub &&
-               test_must_fail git grep o &&
-               git grep --no-index o >../../actual.sub &&
-               test_cmp ../../expect.sub ../../actual.sub
-       )
-'
-
-test_expect_success 'inside git repository but with --no-index' '
-       rm -fr is &&
-       mkdir -p is/git/sub &&
-       echo hello >is/git/file1 &&
-       echo world >is/git/sub/file2 &&
-       echo ".*o*" >is/git/.gitignore &&
-       {
-               echo file1:hello &&
-               echo sub/file2:world
-       } >is/expect.full &&
-       : >is/expect.empty &&
-       echo file2:world >is/expect.sub
-       (
-               cd is/git &&
-               git init &&
-               test_must_fail git grep o >../actual.full &&
-               test_cmp ../expect.empty ../actual.full &&
-               git grep --no-index o >../actual.full &&
-               test_cmp ../expect.full ../actual.full &&
-               cd sub &&
-               test_must_fail git grep o >../../actual.sub &&
-               test_cmp ../../expect.empty ../../actual.sub &&
-               git grep --no-index o >../../actual.sub &&
-               test_cmp ../../expect.sub ../../actual.sub
-       )
-'
-
 test_done