git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] add-patch: render hunks through the pager

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 26, 2024, 18:36 UTC
Message-ID
<xmqq8qxouhjv.fsf@gitster.g>
In-Reply-To
<38e190de-cbe4-4f75-acdb-fe566e541179@gmail.com>
Rubén Justo <rjusto@gmail.com> writes:
Show 16 quoted lines
> 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.
Up to this point, it is fine.
But ...
Show 27 quoted lines
> For the tests, avoid the common construct to set and export one-shot
> variables within the scope of a command:
>
>     VAR=VAL command args
>
> It happens that when "command" is a shell function that in turn executes
> a "command", the behavior with "VAR" varies depending on the shell:
>
>  ** Bash 5.2.21 **
>
>     $ f () { bash -c 'echo A=$A'; }
>     $ A=1 f
>     A=1
>
>  ** dash 0.5.12-9 **
>
>     $ f () { bash -c 'echo A=$A'; }
>     $ A=1 f
>     A=1
>
>  ** dash 0.5.10.2-6 **
>
>     $ f () { bash -c 'echo A=$A'; }
>     $ A=1 f
>     A=
>
> POSIX explicitly says the effect of this construct is unspecified.
... unless the patch is about changing an existing
	GIT_PAGER=... test_terminal git add -p
into
	(
		GIT_PAGER=...; export GIT_PAGER
		test_terminal git add -p
	)

then all of the above is irrelevant noise that says "as the coding guidelines tell us not to use the non-portable 'VAR=VAL shell_func' construct, we don't."

Always write your proposed log message to those who will read "git log -p" 6 months down the road. To them, the trouble we had while diagnosing the true cause of the breakage in the previous iteration do not exist. It is not part of the "log -p" output they see.

> One of our CI jobs on GitHub Actions uses Ubuntu 20.04 running dash
> 0.5.10.2-6, so avoid using the construct and use a subshell instead.

And it does not matter if all CI platforms are updated. As long as our coding guidelines say not to use this construct, we don't.

In any case, that is an appropriate thing to say in a commit that fixes use of such a construct, but not a commit that uses the right constuct from the get-go.

I have to say that the [4/4] in the previous round, i.e., fc87b2f7 (add-patch: render hunks through the pager, 2024-07-25) in my tree, is better than this version.

Thanks.
Previous: Rubén JustoNext: Junio C Hamano
Message 21 of 29 in “add-p P fixups”
  1. 0/2 add-p P fixupsRubén Justo, Jul 23, 2024
  2. 1/2 t3701: avoid one-shot export for shell functionsRubén Justo, Jul 23, 2024
  3. 2/2 pager: make wait_for_pager a no-op for "cat"Rubén Justo, Jul 23, 2024
  4. Junio C HamanoJul 23, 2024
  5. Phillip WoodJul 23, 2024
  6. Junio C HamanoJul 23, 2024
  7. Rubén JustoJul 23, 2024
  8. phillip.wood123@gmail.comJul 24, 2024
  9. Rubén JustoJul 24, 2024
  10. Phillip WoodJul 25, 2024
  11. Rubén JustoJul 25, 2024
  12. 0/4 squash fixups in rj/add-p-pagerRubén Justo, Jul 25, 2024
  13. 1/4 add-patch: test for 'p' commandRubén Justo, Jul 25, 2024
  14. 2/4 pager: do not close fd 2 unnecessarilyRubén Justo, Jul 25, 2024
  15. 3/4 pager: introduce wait_for_pagerRubén Justo, Jul 25, 2024
  16. 4/4 add-patch: render hunks through the pagerRubén Justo, Jul 25, 2024
  17. Junio C HamanoJul 25, 2024
  18. Re* [PATCH v2 0/2] add-p P fixupsRubén Justo, Jul 25, 2024
  19. 1/2 pager: introduce wait_for_pagerRubén Justo, Jul 25, 2024
  20. 2/2 add-patch: render hunks through the pagerRubén Justo, Jul 25, 2024
  21. Junio C HamanoJul 26, 2024
  22. Junio C HamanoJul 27, 2024
  23. Rubén JustoJul 27, 2024
  24. Junio C HamanoJul 26, 2024
  25. Rubén JustoJul 26, 2024
  26. Junio C HamanoJul 26, 2024
  27. Rubén JustoJul 26, 2024
  28. Rubén JustoJul 28, 2024
  29. Junio C HamanoJul 29, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.