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>
Jeff King committed
May 6, 2014 at 23:00 UTC
26ecfe3e2041fe651c9682ebb73911777290ac62
1 file changed
+1
-3
builtin/grep.c
+1
-3
@@ -361,9 +361,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix)
361
argv[i] = path_list->items[i].string;
362
argv[path_list->nr] = NULL;
363
364
- if (prefix && chdir(prefix))
365
- die(_("Failed to chdir: %s"), prefix);
366
- status = run_command_v_opt(argv, RUN_USING_SHELL);
364
+ status = run_command_v_opt_cd_env(argv, RUN_USING_SHELL, prefix, NULL);
365
if (status)
366
exit(status);
367
free(argv);