diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-02-16 14:34:44 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-02-17 09:19:15 -0800 |
commit | 3e3a4a41b0dac564c0302ced4ccc423d0d39bc21 (patch) | |
tree | c3317045271879bd260981ce8d96d145021df8f4 /pager.c | |
parent | 43b019022478703758b3744fa242867ed620a9a6 (diff) | |
download | git-3e3a4a41b0dac564c0302ced4ccc423d0d39bc21.tar.gz |
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 <gitster@pobox.com>
Diffstat (limited to 'pager.c')
-rw-r--r-- | pager.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -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; |