From 43b019022478703758b3744fa242867ed620a9a6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 16 Feb 2016 14:26:40 -0800 Subject: [PATCH 1/3] pager: lose a separate argv[] These days, using the embedded args array in the child_process structure is the norm. Follow that practice. Signed-off-by: Junio C Hamano --- pager.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pager.c b/pager.c index 070dc11cb..5dbcc5ace 100644 --- a/pager.c +++ b/pager.c @@ -11,7 +11,6 @@ * something different on Windows. */ -static const char *pager_argv[] = { NULL, NULL }; static struct child_process pager_process = CHILD_PROCESS_INIT; static void wait_for_pager(void) @@ -70,9 +69,8 @@ void setup_pager(void) setenv("GIT_PAGER_IN_USE", "true", 1); /* spawn the pager */ - pager_argv[0] = pager; + argv_array_push(&pager_process.args, pager); pager_process.use_shell = 1; - pager_process.argv = pager_argv; pager_process.in = -1; if (!getenv("LESS")) argv_array_push(&pager_process.env_array, "LESS=FRX"); From 3e3a4a41b0dac564c0302ced4ccc423d0d39bc21 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 16 Feb 2016 14:34:44 -0800 Subject: [PATCH 2/3] pager: factor out a helper to prepare a child process to run the pager When running a pager, we need to run the program git_pager() gave us, but we need to make sure we spawn it via the shell (i.e. it is valid to say PAGER='less -S', for example) and give default values to $LESS and $LV environment variables. Factor out these details to a separate helper function. Signed-off-by: Junio C Hamano --- cache.h | 3 +++ pager.c | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cache.h b/cache.h index 6bb711903..a839accbd 100644 --- a/cache.h +++ b/cache.h @@ -210,7 +210,9 @@ struct cache_entry { #error "CE_EXTENDED_FLAGS out of range" #endif +/* Forward structure decls */ struct pathspec; +struct child_process; /* * Copy the sha1 and stat state of a cache entry from one to @@ -1550,6 +1552,7 @@ extern int pager_use_color; extern int term_columns(void); extern int decimal_width(uintmax_t); extern int check_pager_config(const char *cmd); +extern void prepare_pager_args(struct child_process *, const char *pager); extern const char *editor_program; extern const char *askpass_program; diff --git a/pager.c b/pager.c index 5dbcc5ace..cb28207c4 100644 --- a/pager.c +++ b/pager.c @@ -53,6 +53,16 @@ const char *git_pager(int stdout_is_tty) return pager; } +void prepare_pager_args(struct child_process *pager_process, const char *pager) +{ + argv_array_push(&pager_process->args, pager); + pager_process->use_shell = 1; + if (!getenv("LESS")) + argv_array_push(&pager_process->env_array, "LESS=FRX"); + if (!getenv("LV")) + argv_array_push(&pager_process->env_array, "LV=-c"); +} + void setup_pager(void) { const char *pager = git_pager(isatty(1)); @@ -69,13 +79,8 @@ void setup_pager(void) setenv("GIT_PAGER_IN_USE", "true", 1); /* spawn the pager */ - argv_array_push(&pager_process.args, pager); - pager_process.use_shell = 1; + prepare_pager_args(&pager_process, pager); pager_process.in = -1; - if (!getenv("LESS")) - argv_array_push(&pager_process.env_array, "LESS=FRX"); - if (!getenv("LV")) - argv_array_push(&pager_process.env_array, "LV=-c"); argv_array_push(&pager_process.env_array, "GIT_PAGER_IN_USE"); if (start_command(&pager_process)) return; From 708b8cc9a114ea1e5b90f5f52fd24ecade4e8b40 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 16 Feb 2016 14:46:39 -0800 Subject: [PATCH 3/3] am -i: fix "v"iew The 'v'iew subcommand of the interactive mode of "git am -i" was broken by the rewrite to C we did at around 2.6.0 timeframe at 7ff26832 (builtin-am: implement -i/--interactive, 2015-08-04); we used to spawn the pager via the shell, accepting things like PAGER='less -S' in the environment, but the rewrite forgot and tried to directly spawn a command whose name is the entire string. The previous refactoring of the new helper function makes it easier for us to do the right thing. Signed-off-by: Junio C Hamano --- builtin/am.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/am.c b/builtin/am.c index 1399c8dd8..56cf26e8b 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1740,7 +1740,7 @@ static int do_interactive(struct am_state *state) if (!pager) pager = "cat"; - argv_array_push(&cp.args, pager); + prepare_pager_args(&cp, pager); argv_array_push(&cp.args, am_path(state, "patch")); run_command(&cp); }