Skip to content

Commit

Permalink
pager: factor out a helper to prepare a child process to run the pager
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Feb 17, 2016
1 parent 43b0190 commit 3e3a4a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 11 additions & 6 deletions pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand Down

0 comments on commit 3e3a4a4

Please sign in to comment.