summaryrefslogtreecommitdiffstats
path: root/add-patch.c
diff options
context:
space:
mode:
Diffstat (limited to 'add-patch.c')
-rw-r--r--add-patch.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/add-patch.c b/add-patch.c
index 46f6bddfe5..557903310d 100644
--- a/add-patch.c
+++ b/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"
@@ -1140,7 +1142,8 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
"removed, then the edit is\n"
"aborted and the hunk is left unchanged.\n"));
- if (strbuf_edit_interactively(&s->buf, "addp-hunk-edit.diff", NULL) < 0)
+ if (strbuf_edit_interactively(the_repository, &s->buf,
+ "addp-hunk-edit.diff", NULL) < 0)
return -1;
/* strip out commented lines */
@@ -1398,7 +1401,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 +1412,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 +1462,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 +1694,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;