Merge branch 'rj/add-p-pager'
A 'P' command to "git add -p" that passes the patch hunk to the pager has been added. * rj/add-p-pager: add-patch: render hunks through the pager pager: introduce wait_for_pager pager: do not close fd 2 unnecessarily add-patch: test for 'p' command
This commit is contained in:
18
add-patch.c
18
add-patch.c
@@ -7,9 +7,11 @@
|
||||
#include "environment.h"
|
||||
#include "gettext.h"
|
||||
#include "object-name.h"
|
||||
#include "pager.h"
|
||||
#include "read-cache-ll.h"
|
||||
#include "repository.h"
|
||||
#include "strbuf.h"
|
||||
#include "sigchain.h"
|
||||
#include "run-command.h"
|
||||
#include "strvec.h"
|
||||
#include "pathspec.h"
|
||||
@@ -1398,7 +1400,7 @@ N_("j - leave this hunk undecided, see next undecided hunk\n"
|
||||
"/ - search for a hunk matching the given regex\n"
|
||||
"s - split the current hunk into smaller hunks\n"
|
||||
"e - manually edit the current hunk\n"
|
||||
"p - print the current hunk\n"
|
||||
"p - print the current hunk, 'P' to use the pager\n"
|
||||
"? - print help\n");
|
||||
|
||||
static int patch_update_file(struct add_p_state *s,
|
||||
@@ -1409,7 +1411,7 @@ static int patch_update_file(struct add_p_state *s,
|
||||
struct hunk *hunk;
|
||||
char ch;
|
||||
struct child_process cp = CHILD_PROCESS_INIT;
|
||||
int colored = !!s->colored.len, quit = 0;
|
||||
int colored = !!s->colored.len, quit = 0, use_pager = 0;
|
||||
enum prompt_mode_type prompt_mode_type;
|
||||
enum {
|
||||
ALLOW_GOTO_PREVIOUS_HUNK = 1 << 0,
|
||||
@@ -1459,9 +1461,18 @@ static int patch_update_file(struct add_p_state *s,
|
||||
strbuf_reset(&s->buf);
|
||||
if (file_diff->hunk_nr) {
|
||||
if (rendered_hunk_index != hunk_index) {
|
||||
if (use_pager) {
|
||||
setup_pager();
|
||||
sigchain_push(SIGPIPE, SIG_IGN);
|
||||
}
|
||||
render_hunk(s, hunk, 0, colored, &s->buf);
|
||||
fputs(s->buf.buf, stdout);
|
||||
rendered_hunk_index = hunk_index;
|
||||
if (use_pager) {
|
||||
sigchain_pop(SIGPIPE);
|
||||
wait_for_pager();
|
||||
use_pager = 0;
|
||||
}
|
||||
}
|
||||
|
||||
strbuf_reset(&s->buf);
|
||||
@@ -1682,8 +1693,9 @@ soft_increment:
|
||||
hunk->use = USE_HUNK;
|
||||
goto soft_increment;
|
||||
}
|
||||
} else if (s->answer.buf[0] == 'p') {
|
||||
} else if (ch == 'p') {
|
||||
rendered_hunk_index = -1;
|
||||
use_pager = (s->answer.buf[0] == 'P') ? 1 : 0;
|
||||
} else if (s->answer.buf[0] == '?') {
|
||||
const char *p = _(help_patch_remainder), *eol = p;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user