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

Re: git-diff should not fire up $PAGER if there is no diff

From
Jeff King <peff@peff.net>
Date
Dec 16, 2008, 07:44 UTC
Message-ID
<20081216074414.GB2468@coredump.intra.peff.net>
In-Reply-To
<d4bc1a2a0812152235l14ec80bbr130a7ab152ad6b8@mail.gmail.com>
On Tue, Dec 16, 2008 at 01:35:53AM -0500, Stefan Karpinski wrote:
Show 10 quoted lines
> > On Mon, Dec 15, 2008 at 7:56 PM, Jeff King <peff@peff.net> wrote:
> >  2. detect EOF before starting the pager. We in fact already delay
> >     running the pager in the forked process until we have some activity
> >     on the pipe, but I don't know if there is a portable way of
> >     detecting that that activity is EOF without performing an actual
> >     read() call (which is undesirable, since it eats the first byte of
> >     output that should go to the pager).
> 
> Wouldn't ungetc work? Or is that not portable enough? (It would only
> work here because the EOF has to be the first character.)

No, it won't work. ungetc works on the buffered stdio object, so it is useful for pushing back characters onto the buffer to be read later in the program from the same buffer. But in this case, we are going to execv() (or on Windows, spawn) the pager, meaning it will throw away anything that has been read() from the pipe and put in the buffer.

So we would need a system call to push a character back to the OS, so that it was available for read() by the pager process.

-Peff
Previous: Stefan KarpinskiNext: Stefan Karpinski
Message 4 of 13 in “git-diff should not fire up $PAGER if there is no diff”
  1. jidanni@jidanni.orgDec 16, 2008
  2. Jeff KingDec 16, 2008
  3. Stefan KarpinskiDec 16, 2008
  4. Jeff KingDec 16, 2008
  5. Stefan KarpinskiDec 16, 2008
  6. git-diff should not fire up $PAGER, period!jidanni@jidanni.org, Dec 17, 2008
  7. Junio C HamanoDec 17, 2008
  8. Linus TorvaldsDec 17, 2008
  9. Miles BaderDec 22, 2008
  10. Jeff KingDec 18, 2008
  11. Miles BaderDec 22, 2008
  12. Johannes SixtDec 22, 2008
  13. Junio C HamanoDec 22, 2008

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.