From: Junio C Hamano <gitster@pobox.com>
To: "Rubén Justo" <rjusto@gmail.com>
Cc: phillip.wood@dunelm.org.uk, Git List <git@vger.kernel.org>,
Dragan Simic <dsimic@manjaro.org>, Jeff King <peff@peff.net>
Subject: Re: [PATCH v3 4/4] add-patch: render hunks through the pager
Date: Mon, 22 Jul 2024 10:22:58 -0700 [thread overview]
Message-ID: <xmqqv80xcpe5.fsf@gitster.g> (raw)
In-Reply-To: <a2ea00e2-08e4-4e6b-b81c-ef3ba02b4b1f@gmail.com> ("Rubén Justo"'s message of "Sun, 21 Jul 2024 00:29:44 +0200")
Rubén Justo <rjusto@gmail.com> writes:
>> > + test_write_lines P q |
>> > + (
>> > + GIT_PAGER="head -n 1" &&
>> > + export GIT_PAGER &&
>> > + test_terminal git add -p >actual
>> > + )
>>
>> That's surprising, why does running git in a sub-shell stop it from
>> segfaulting?
>
> The fix isn't the sub-shell; it's "export GIT_PAGER".
> ...
> Because GIT_PAGER is not being set correctly in the test, "git add -p"
> can use the values defined in the environment where the test is running.
> Usually PAGER is empty or contains "less", but in the environment where
> the fault occurs, it happens to be: "PAGER=cat".
>
> Since we have an optimization to avoid forking if the pager is "cat",
> courtesy of caef71a535 (Do not fork PAGER=cat, 2006-04-16), then we fail
> in `wait_for_pager()` because we are calling `finish_command()` with an
> uninitialized `pager_process`.
Attached at the end is a test tweak patch, taking inspirations from
Phillip's comments, to see what value GIT_PAGER has in the shell
function. I shortened the huge_file a bit so that I do not have to
have an infinite scrollback buffer,but otherwise, the test_quirk
intermediate shell function should work just like the test_terminal
helper in the original position would.
And I see in the output from "sh t3701-add-interactive.sh -i -v":
expecting success of 3701.51 'P handles SIGPIPE when writing to pager':
test_when_finished "rm -f huge_file; git reset" &&
printf "\n%250s" Y >huge_file &&
git add -N huge_file &&
echo "in env: GIT_PAGER=$(env | grep GIT_PAGER=)" &&
test_write_lines P q | GIT_PAGER="head -n 1" test_quirk &&
echo "after test_quirk returns: GIT_PAGER=$GIT_PAGER"
in env: GIT_PAGER=
in test_quirk: GIT_PAGER=head -n 1
in env: GIT_PAGER=GIT_PAGER=head -n 1
In test_terminal: GIT_PAGER=GIT_PAGER=head -n 1
test-terminal: GIT_PAGER=head -n 1
diff --git a/huge_file b/huge_file
new file mode 100644
index 0000000..d06820d
--- /dev/null
+++ b/huge_file
@@ -0,0 +1,2 @@
+
+ Y
\ No newline at end of file
(1/1) Stage addition [y,n,q,a,d,e,p,?]? @@ -0,0 +1,2 @@
(1/1) Stage addition [y,n,q,a,d,e,p,?]?
after test_quirk returns: GIT_PAGER=
Unstaged changes after reset:
M test
ok 51 - P handles SIGPIPE when writing to pager
So:
- before the one-shot thing, in the envrionment GIT_PAGER is empty.
- in the helper function,
- shell variable GIT_PAGER is set to the expected value.
- GIT_PAGER env is exported.
- test-terminal.perl sees $ENV{GIT_PAGER} set to the expected value.
- after the helper returns GIT_PAGER is empty
It's a very convincing theory but it does not seem to match my
observation. Is there a difference in shells used, or something?
t/lib-terminal.sh | 3 +++
t/t3701-add-interactive.sh | 15 +++++++++++++--
t/test-terminal.perl | 2 ++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git c/t/lib-terminal.sh w/t/lib-terminal.sh
index e3809dcead..558db9aa33 100644
--- c/t/lib-terminal.sh
+++ w/t/lib-terminal.sh
@@ -9,6 +9,9 @@ test_terminal () {
echo >&4 "test_terminal: need to declare TTY prerequisite"
return 127
fi
+
+ echo >&4 "In test_terminal: GIT_PAGER=$(env | grep GIT_PAGER=)"
+
perl "$TEST_DIRECTORY"/test-terminal.perl "$@" 2>&7
} 7>&2 2>&4
diff --git c/t/t3701-add-interactive.sh w/t/t3701-add-interactive.sh
index c60589cb94..f7037cbed4 100755
--- c/t/t3701-add-interactive.sh
+++ w/t/t3701-add-interactive.sh
@@ -612,13 +612,24 @@ test_expect_success TTY 'print again the hunk (PAGER)' '
test_cmp expect actual.trimmed
'
+test_quirk () {
+ echo "in test_quirk: GIT_PAGER=$GIT_PAGER"
+ echo "in env: GIT_PAGER=$(env | grep GIT_PAGER=)"
+ test_terminal git add -p
+ true
+}
+
test_expect_success TTY 'P handles SIGPIPE when writing to pager' '
test_when_finished "rm -f huge_file; git reset" &&
- printf "\n%2500000s" Y >huge_file &&
+ printf "\n%250s" Y >huge_file &&
git add -N huge_file &&
- test_write_lines P q | GIT_PAGER="head -n 1" test_terminal git add -p
+ echo "in env: GIT_PAGER=$(env | grep GIT_PAGER=)" &&
+ test_write_lines P q | GIT_PAGER="head -n 1" test_quirk &&
+ echo "after test_quirk returns: GIT_PAGER=$GIT_PAGER"
'
+exit
+
test_expect_success 'split hunk "add -p (edit)"' '
# Split, say Edit and do nothing. Then:
#
diff --git c/t/test-terminal.perl w/t/test-terminal.perl
index b8fd6a4f13..92b1c13675 100755
--- c/t/test-terminal.perl
+++ w/t/test-terminal.perl
@@ -67,6 +67,8 @@ sub copy_stdio {
if ($#ARGV < 1) {
die "usage: test-terminal program args";
}
+print STDERR "test-terminal: GIT_PAGER=$ENV{GIT_PAGER}\n";
+
$ENV{TERM} = 'vt100';
my $parent_out = new IO::Pty;
my $parent_err = new IO::Pty;
next prev parent reply other threads:[~2024-07-22 17:23 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-12 0:57 [PATCH 0/4] use the pager in 'add -p' Rubén Justo
2024-07-12 1:00 ` [PATCH 1/4] add-patch: test for 'p' command Rubén Justo
2024-07-12 1:00 ` [PATCH 2/4] pager: do not close fd 2 unnecessarily Rubén Justo
2024-07-12 1:00 ` [PATCH 3/4] pager: introduce wait_for_pager Rubén Justo
2024-07-12 13:17 ` Phillip Wood
2024-07-12 1:00 ` [PATCH 4/4] add-patch: render hunks through the pager Rubén Justo
2024-07-12 8:58 ` Dragan Simic
2024-07-12 13:26 ` Phillip Wood
2024-07-12 16:24 ` Rubén Justo
2024-07-13 3:23 ` Rubén Justo
2024-07-13 9:12 ` Junio C Hamano
2024-07-13 13:17 ` phillip.wood123
2024-07-13 23:13 ` Rubén Justo
2024-07-12 8:56 ` [PATCH 0/4] use the pager in 'add -p' Dragan Simic
2024-07-13 16:26 ` [PATCH v2 " Rubén Justo
2024-07-13 16:29 ` [PATCH v2 1/4] add-patch: test for 'p' command Rubén Justo
2024-07-13 16:29 ` [PATCH v2 2/4] pager: do not close fd 2 unnecessarily Rubén Justo
2024-07-13 16:29 ` [PATCH v2 3/4] pager: introduce wait_for_pager Rubén Justo
2024-07-13 16:30 ` [PATCH v2 4/4] add-patch: render hunks through the pager Rubén Justo
2024-07-13 17:08 ` [PATCH v2 0/4] use the pager in 'add -p' Junio C Hamano
2024-07-13 23:21 ` Rubén Justo
2024-07-14 1:18 ` Junio C Hamano
2024-07-14 16:00 ` [PATCH v3 " Rubén Justo
2024-07-14 16:04 ` [PATCH v3 1/4] add-patch: test for 'p' command Rubén Justo
2024-07-14 16:04 ` [PATCH v3 2/4] pager: do not close fd 2 unnecessarily Rubén Justo
2024-07-14 16:04 ` [PATCH v3 4/4] add-patch: render hunks through the pager Rubén Justo
2024-07-15 14:10 ` Phillip Wood
2024-07-15 23:54 ` Junio C Hamano
2024-07-17 17:20 ` Rubén Justo
2024-07-17 19:39 ` phillip.wood123
2024-07-17 20:03 ` Junio C Hamano
2024-07-17 20:09 ` Eric Sunshine
2024-07-17 20:21 ` Junio C Hamano
2024-07-20 22:37 ` Rubén Justo
2024-07-22 7:18 ` Eric Sunshine
2024-07-22 14:53 ` Rubén Justo
2024-07-18 9:48 ` phillip.wood123
2024-07-17 20:31 ` Junio C Hamano
2024-07-18 9:56 ` phillip.wood123
2024-07-20 22:39 ` Rubén Justo
2024-07-20 22:29 ` Rubén Justo
2024-07-22 10:18 ` Phillip Wood
2024-07-22 16:45 ` Rubén Justo
2024-07-22 17:22 ` Junio C Hamano [this message]
2024-07-22 19:06 ` Rubén Justo
2024-07-22 19:27 ` Junio C Hamano
2024-07-22 21:06 ` Re* " Junio C Hamano
2024-07-22 22:00 ` Rubén Justo
2024-07-22 23:12 ` Kyle Lippincott
2024-07-22 23:28 ` Junio C Hamano
2024-07-23 2:31 ` Junio C Hamano
2024-07-22 21:25 ` Junio C Hamano
2024-07-22 23:20 ` Rubén Justo
2024-07-22 23:24 ` [PATCH 1/2] t3701: avoid one-shot export for shell functions Rubén Justo
2024-07-22 23:44 ` Junio C Hamano
2024-07-22 23:57 ` Junio C Hamano
2024-07-22 23:24 ` [PATCH 2/2] pager: make wait_for_pager a no-op for "cat" Rubén Justo
2024-07-22 23:54 ` Junio C Hamano
2024-07-18 9:58 ` [PATCH v3 4/4] add-patch: render hunks through the pager phillip.wood123
2024-07-20 22:45 ` Rubén Justo
2024-07-14 16:04 ` [PATCH v3 3/4] pager: introduce wait_for_pager Rubén Justo
2024-07-15 14:13 ` Phillip Wood
2024-07-15 20:04 ` Rubén Justo
2024-07-17 14:58 ` phillip.wood123
2024-07-15 20:16 ` [PATCH v4 0/4] add-patch: render hunks through the pager Rubén Justo
2024-07-15 20:20 ` [PATCH v4 1/4] add-patch: test for 'p' command Rubén Justo
2024-07-15 20:21 ` [PATCH v4 2/4] pager: do not close fd 2 unnecessarily Rubén Justo
2024-07-15 20:21 ` [PATCH v4 3/4] pager: introduce wait_for_pager Rubén Justo
2024-07-15 20:22 ` [PATCH v4 4/4] add-patch: render hunks through the pager Rubén Justo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqv80xcpe5.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=dsimic@manjaro.org \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=phillip.wood@dunelm.org.uk \
--cc=rjusto@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).