From: Rubén Justo Date: Sat, 13 Jul 2024 16:26:00 GMT Subject: [PATCH v2 0/4] use the pager in 'add -p' Message-ID: In-Reply-To: <2653fb37-c8a8-49b1-a804-4be6654a2cad@gmail.com> Rubén Justo (4): add-patch: test for 'p' command pager: do not close fd 2 unnecessarily pager: introduce wait_for_pager add-patch: render hunks through the pager add-patch.c | 18 ++++++++++++--- pager.c | 45 +++++++++++++++++++++++++++++++++----- pager.h | 1 + t/t3701-add-interactive.sh | 44 +++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 8 deletions(-) Range-diff against v1: 1: 4a5b6e6815 = 1: 6b37507ddd add-patch: test for 'p' command 2: bf8a68ac37 = 2: 5497fa020b pager: do not close fd 2 unnecessarily 3: aabd7da4d6 = 3: 30e772cf7c pager: introduce wait_for_pager 4: ff51cc32bd ! 4: f7cb00b654 add-patch: render hunks through the pager @@ Metadata ## Commit message ## add-patch: render hunks through the pager - Make the print command to trigger the pager when invoked using a capital + Make the print command trigger the pager when invoked using a capital 'P', to make it easier for the user to review long hunks. + Note that if the PAGER ends unexpectedly before we've been able to send + the payload, perhaps because the user is not interested in the whole + thing, we might receive a SIGPIPE, which would abruptly and unexpectedly + terminate the interactive session for the user. + + Therefore, we need to ignore a possible SIGPIPE signal. Add a test for + this, in addition to the test for normal operation. + + For the SIGPIPE test, we need to make sure that we completely fill the + operating system's buffer, otherwise we might not trigger the SIGPIPE + signal. The normal size of this buffer in different OSs varies from a + few KBs to 1MB. Use a payload large enough to guarantee that we exceed + this limit. + Signed-off-by: Rubén Justo ## add-patch.c ## @@ t/t3701-add-interactive.sh: test_expect_success 'print again the hunk' ' + test_cmp expect actual.trimmed +' + -+test_expect_success TTY 'P does not break if pager ends unexpectly' ' ++test_expect_success TTY 'P does not break if pager ends unexpectedly' ' + test_when_finished "rm -f huge_file; git reset" && + printf "%2500000s" Y >huge_file && + git add -N huge_file && -+ cat >expect <<-EOF && -+ +22 -+ +23 -+ +24 -+ 30 -+ 40 -+ 50 -+ (1/1) Stage this hunk [y,n,q,a,d,s,e,p,?]? -+ EOF -+ test_write_lines P | -+ ( -+ GIT_PAGER="head -1" && -+ export GIT_PAGER && -+ test_terminal git add -p >actual -+ ) && -+ tail -n 7 actual.trimmed && -+ test_cmp expect actual.trimmed ++ test_write_lines P q | GIT_PAGER="head -c 1" test_terminal git add -p >actual +' + test_expect_success 'split hunk "add -p (edit)"' ' -- 2.45.2.831.g9e4974e3d4