Skip to content

Commit 3e3a4a4

Browse files
committed
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 <[email protected]>
1 parent 43b0190 commit 3e3a4a4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ struct cache_entry {
210210
#error "CE_EXTENDED_FLAGS out of range"
211211
#endif
212212

213+
/* Forward structure decls */
213214
struct pathspec;
215+
struct child_process;
214216

215217
/*
216218
* Copy the sha1 and stat state of a cache entry from one to
@@ -1550,6 +1552,7 @@ extern int pager_use_color;
15501552
extern int term_columns(void);
15511553
extern int decimal_width(uintmax_t);
15521554
extern int check_pager_config(const char *cmd);
1555+
extern void prepare_pager_args(struct child_process *, const char *pager);
15531556

15541557
extern const char *editor_program;
15551558
extern const char *askpass_program;

pager.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ const char *git_pager(int stdout_is_tty)
5353
return pager;
5454
}
5555

56+
void prepare_pager_args(struct child_process *pager_process, const char *pager)
57+
{
58+
argv_array_push(&pager_process->args, pager);
59+
pager_process->use_shell = 1;
60+
if (!getenv("LESS"))
61+
argv_array_push(&pager_process->env_array, "LESS=FRX");
62+
if (!getenv("LV"))
63+
argv_array_push(&pager_process->env_array, "LV=-c");
64+
}
65+
5666
void setup_pager(void)
5767
{
5868
const char *pager = git_pager(isatty(1));
@@ -69,13 +79,8 @@ void setup_pager(void)
6979
setenv("GIT_PAGER_IN_USE", "true", 1);
7080

7181
/* spawn the pager */
72-
argv_array_push(&pager_process.args, pager);
73-
pager_process.use_shell = 1;
82+
prepare_pager_args(&pager_process, pager);
7483
pager_process.in = -1;
75-
if (!getenv("LESS"))
76-
argv_array_push(&pager_process.env_array, "LESS=FRX");
77-
if (!getenv("LV"))
78-
argv_array_push(&pager_process.env_array, "LV=-c");
7984
argv_array_push(&pager_process.env_array, "GIT_PAGER_IN_USE");
8085
if (start_command(&pager_process))
8186
return;

0 commit comments

Comments
 (0)