Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jc/am-i-v-fix'
The "v(iew)" subcommand of the interactive "git am -i" command was
broken in 2.6.0 timeframe when the command was rewritten in C.

* jc/am-i-v-fix:
  am -i: fix "v"iew
  pager: factor out a helper to prepare a child process to run the pager
  pager: lose a separate argv[]
  • Loading branch information
Junio C Hamano committed Feb 24, 2016
2 parents 595bfef + 708b8cc commit c3b1e8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion builtin/am.c
Expand Up @@ -1806,7 +1806,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);
}
Expand Down
3 changes: 3 additions & 0 deletions cache.h
Expand Up @@ -229,7 +229,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 @@ -1685,6 +1687,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
19 changes: 11 additions & 8 deletions pager.c
Expand Up @@ -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(int in_signal)
Expand Down Expand Up @@ -64,6 +63,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 @@ -80,14 +89,8 @@ void setup_pager(void)
setenv("GIT_PAGER_IN_USE", "true", 1);

/* spawn the pager */
pager_argv[0] = pager;
pager_process.use_shell = 1;
pager_process.argv = pager_argv;
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 c3b1e8d

Please sign in to comment.