@matheusbsbs / matheus-bagliano / commits / ff38d1a995
Fork 0

grep: run setup_git_directory_gently() sooner

git grep already runs a repository search unconditionally, even when the --no-index option is supplied; running such a search earlier is not very risky. Just like with shortlog, without this change, the “[pager] grep” configuration is not respected at all. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 5, 2010 at 22:06 UTC ff38d1a9953b3bce7741f8f962c5e067fda2d9ea
3 files changed +16 -5
builtin/grep.c
+2 -4
@@ -839,7 +839,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
839 struct string_list path_list = { NULL, 0, 0, 0 };
840 int i;
841 int dummy;
842 - int nongit = 0, use_index = 1;
842 + int use_index = 1;
843 struct option options[] = {
844 OPT_BOOLEAN(0, "cached", &cached,
845 "search in index instead of in the work tree"),
@@ -930,8 +930,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
930 OPT_END()
931 };
932
933 - prefix = setup_git_directory_gently(&nongit);
934 -
933 /*
934 * 'git grep -h', unlike 'git grep -h <pattern>', is a request
935 * to show usage information and exit.
@@ -976,7 +974,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
974 PARSE_OPT_STOP_AT_NON_OPTION |
975 PARSE_OPT_NO_INTERNAL_HELP);
976
979 - if (use_index && nongit)
977 + if (use_index && !startup_info->have_repository)
978 /* die the same way as if we did it at the beginning */
979 setup_git_directory();
980
git.c
+1 -1
@@ -336,7 +336,7 @@ static void handle_internal_command(int argc, const char **argv)
336 { "fsck-objects", cmd_fsck, RUN_SETUP },
337 { "gc", cmd_gc, RUN_SETUP },
338 { "get-tar-commit-id", cmd_get_tar_commit_id },
339 - { "grep", cmd_grep },
339 + { "grep", cmd_grep, RUN_SETUP_GENTLY },
340 { "hash-object", cmd_hash_object },
341 { "help", cmd_help },
342 { "index-pack", cmd_index_pack },
t/t7006-pager.sh
+13
@@ -106,6 +106,19 @@ test_expect_success TTY 'no pager with --no-pager' '
106 ! test -e paginated.out
107 '
108
109 +test_expect_success TTY 'configuration can disable pager' '
110 + rm -f paginated.out &&
111 + test_might_fail git config --unset pager.grep &&
112 + test_terminal git grep initial &&
113 + test -e paginated.out &&
114 +
115 + rm -f paginated.out &&
116 + git config pager.grep false &&
117 + test_when_finished "git config --unset pager.grep" &&
118 + test_terminal git grep initial &&
119 + ! test -e paginated.out
120 +'
121 +
122 # A colored commit log will begin with an appropriate ANSI escape
123 # for the first color; the text "commit" comes later.
124 colorful() {