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

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

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jul 22, 2024, 10:18 UTC
Message-ID
<5360ab9d-6d3e-4da0-b1c4-2ff381372c1a@gmail.com>
In-Reply-To
<a2ea00e2-08e4-4e6b-b81c-ef3ba02b4b1f@gmail.com>
Hi Rubén
On 20/07/2024 23:29, Rubén Justo wrote:
Show 12 quoted lines
> On Wed, Jul 17, 2024 at 08:39:12PM +0100, phillip.wood123@gmail.com wrote:
> 
>> On 17/07/2024 18:20, Rubén Justo wrote:
>>
>>> However, this error has exposed a problem: calling `wait_for_pager` if
>>> `setup_pager` hasn't worked is an issue that needs to be addressed in this
>>> series: `setup_pager` should return a result.  I was planning to do that
>>> in a future series, for the other commented command: `|[cmd]`.
>>
>> What was causing setup pager to fail in this test?
> 
> Because GIT_PAGER is not being set correctly in the test,

Oh I see, I had assumed that the shell would report an error if it didn't support setting environment variables like this when running a function but instead it silently ignored it. This highlights the importance of testing the output of "git add -p" in this test so we can be sure the pager is doing what we think it should. Using

	GIT_PAGER="sed -e s/^/PAGER\ / -e q"
would make it clear what the pager is printing while also causing SIGPIPE
Show 12 quoted lines
> "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`.
> 
> That's why I thought, aligned with what we are already doing in
> `wait_for_pager_at_exit()`, that this is a sensible approach:
That extra information is important. When I said [1]
 > Isn't it a bug to call this with old_fd1 == -1 or have I missed
 > something?

What I'd missed was that we can return early without executing anything. We cannot do

	if (!git_pager(asatty(1))
		return

at the beginning of wait_for_pager() because if we're running a pager isatty(1) will return false so I think the old_fd as you suggested is the easiest fix. The existing callers do not need to know if setup_pager() applied the "cat" optimization because they only setup the pager once. For "add -p" this no-longer applies so we should think about returning a flag to say "there was an error"/"there is no pager or the pager is 'cat'"/"the pager has been started"

Best Wishes
Phillip

[1] https://lore.kernel.org/git/3f085795-79bd-4a56-9df8-659e32179925@gmail.com

Show 19 quoted lines
>>> I'm wondering if the best way to proceed here is to revert to:
>>>
>>> diff --git a/pager.c b/pager.c
>>> index 5f0c1e9cce..5586e751dc 100644
>>> --- a/pager.c
>>> +++ b/pager.c
>>> @@ -46,6 +46,8 @@ static void wait_for_pager_atexit(void)
>>>
>>>    void wait_for_pager(void)
>>>    {
>>> +	if (old_fd1 == -1)
>>> +		return;
>>>    	finish_pager();
>>>    	sigchain_pop_common();
>>>    	unsetenv("GIT_PAGER_IN_USE");
>>>
>>> This was a change already commented here:
>>>
>>> https://lore.kernel.org/git/3f085795-79bd-4a56-9df8-659e32179925@gmail.com/
Previous: Rubén JustoNext: Rubén Justo
Message 42 of 69 in “use the pager in 'add -p'”
  1. 0/4 use the pager in 'add -p'Rubén Justo, Jul 12, 2024
  2. 1/4 add-patch: test for 'p' commandRubén Justo, Jul 12, 2024
  3. 2/4 pager: do not close fd 2 unnecessarilyRubén Justo, Jul 12, 2024
  4. 3/4 pager: introduce wait_for_pagerRubén Justo, Jul 12, 2024
  5. Phillip WoodJul 12, 2024
  6. 4/4 add-patch: render hunks through the pagerRubén Justo, Jul 12, 2024
  7. Dragan SimicJul 12, 2024
  8. Phillip WoodJul 12, 2024
  9. Rubén JustoJul 12, 2024
  10. Rubén JustoJul 13, 2024
  11. Junio C HamanoJul 13, 2024
  12. phillip.wood123@gmail.comJul 13, 2024
  13. Rubén JustoJul 13, 2024
  14. Dragan SimicJul 12, 2024
  15. 0/4 use the pager in 'add -p'Rubén Justo, Jul 13, 2024
  16. 1/4 add-patch: test for 'p' commandRubén Justo, Jul 13, 2024
  17. 2/4 pager: do not close fd 2 unnecessarilyRubén Justo, Jul 13, 2024
  18. 3/4 pager: introduce wait_for_pagerRubén Justo, Jul 13, 2024
  19. 4/4 add-patch: render hunks through the pagerRubén Justo, Jul 13, 2024
  20. Junio C HamanoJul 13, 2024
  21. Rubén JustoJul 13, 2024
  22. Junio C HamanoJul 14, 2024
  23. 0/4 use the pager in 'add -p'Rubén Justo, Jul 14, 2024
  24. 1/4 add-patch: test for 'p' commandRubén Justo, Jul 14, 2024
  25. 2/4 pager: do not close fd 2 unnecessarilyRubén Justo, Jul 14, 2024
  26. 4/4 add-patch: render hunks through the pagerRubén Justo, Jul 14, 2024
  27. Phillip WoodJul 15, 2024
  28. Junio C HamanoJul 15, 2024
  29. Rubén JustoJul 17, 2024
  30. phillip.wood123@gmail.comJul 17, 2024
  31. Junio C HamanoJul 17, 2024
  32. Eric SunshineJul 17, 2024
  33. Junio C HamanoJul 17, 2024
  34. Rubén JustoJul 20, 2024
  35. Eric SunshineJul 22, 2024
  36. Rubén JustoJul 22, 2024
  37. phillip.wood123@gmail.comJul 18, 2024
  38. Junio C HamanoJul 17, 2024
  39. phillip.wood123@gmail.comJul 18, 2024
  40. Rubén JustoJul 20, 2024
  41. Rubén JustoJul 20, 2024
  42. Phillip WoodJul 22, 2024
  43. Rubén JustoJul 22, 2024
  44. Junio C HamanoJul 22, 2024
  45. Rubén JustoJul 22, 2024
  46. Junio C HamanoJul 22, 2024
  47. Re* [PATCH v3 4/4] add-patch: render hunks through the pagerJunio C Hamano, Jul 22, 2024
  48. Rubén JustoJul 22, 2024
  49. Kyle LippincottJul 22, 2024
  50. Junio C HamanoJul 22, 2024
  51. Junio C HamanoJul 23, 2024
  52. Junio C HamanoJul 22, 2024
  53. Rubén JustoJul 22, 2024
  54. 1/2 t3701: avoid one-shot export for shell functionsRubén Justo, Jul 22, 2024
  55. Junio C HamanoJul 22, 2024
  56. Junio C HamanoJul 22, 2024
  57. 2/2 pager: make wait_for_pager a no-op for "cat"Rubén Justo, Jul 22, 2024
  58. Junio C HamanoJul 22, 2024
  59. phillip.wood123@gmail.comJul 18, 2024
  60. Rubén JustoJul 20, 2024
  61. 3/4 pager: introduce wait_for_pagerRubén Justo, Jul 14, 2024
  62. Phillip WoodJul 15, 2024
  63. Rubén JustoJul 15, 2024
  64. phillip.wood123@gmail.comJul 17, 2024
  65. 0/4 add-patch: render hunks through the pagerRubén Justo, Jul 15, 2024
  66. 1/4 add-patch: test for 'p' commandRubén Justo, Jul 15, 2024
  67. 2/4 pager: do not close fd 2 unnecessarilyRubén Justo, Jul 15, 2024
  68. 3/4 pager: introduce wait_for_pagerRubén Justo, Jul 15, 2024
  69. 4/4 add-patch: render hunks through the pagerRubén Justo, Jul 15, 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.