summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-05-07 03:00:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-05-07 17:40:01 (GMT)
commit26ecfe3e2041fe651c9682ebb73911777290ac62 (patch)
tree094257ada0bd8a4f3302ab374f2209ba1d09425c /builtin/grep.c
parent0bc85abb7aa9b24b093253018801a0fb43d01122 (diff)
downloadgit-26ecfe3e2041fe651c9682ebb73911777290ac62.zip
git-26ecfe3e2041fe651c9682ebb73911777290ac62.tar.gz
git-26ecfe3e2041fe651c9682ebb73911777290ac62.tar.bz2
grep: use run-command's "dir" option for --open-files-in-pager
Git generally changes directory to the repository root on startup. When running "grep --open-files-in-pager" from a subdirectory, we chdir back to the original directory before running the pager, so that we can feed the relative pathnames to the pager. We currently do this chdir manually, but we can ask run_command to do it for us. This is fewer lines of code, and as a bonus, the chdir is limited to the child process, which avoids any unexpected surprises for code running after the pager (there isn't any currently, but this is future-proofing). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 69ac2d8..43af5b7 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -361,9 +361,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix)
argv[i] = path_list->items[i].string;
argv[path_list->nr] = NULL;
- if (prefix && chdir(prefix))
- die(_("Failed to chdir: %s"), prefix);
- status = run_command_v_opt(argv, RUN_USING_SHELL);
+ status = run_command_v_opt_cd_env(argv, RUN_USING_SHELL, prefix, NULL);
if (status)
exit(status);
free(argv);