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, 00:56 UTC
Message-ID
<20081216005658.GB3679@coredump.intra.peff.net>
In-Reply-To
<874p15x94i.fsf@jidanni.org>
On Tue, Dec 16, 2008 at 08:21:33AM +0800, jidanni@jidanni.org wrote:
> git-diff should not fire up $PAGER if there is no diff output.
> Just exit. The man page doesn't even mention $PAGER too.

I agree that would be nice, but it is a little difficult to implement. The current behavior forks early and then pipes the output to the pager. So we would have to:

  1. change that behavior to instead delay starting the pager until the
     first output. Which means intercepting every
     write/fwrite/printf/fputs/etc call.
  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).
  3. a hacky solution to (2) above would be to make _2_ pipes, one of
     which signals to the pager sub-process either "exit now" or "proceed
     with running the pager".

The usual workaround is to ask the pager to exit immediately if the output is small. I.e., putting "F" in your LESS variable (which git does automatically if you don't already have LESS set).

-Peff
Previous: jidanni@jidanni.orgNext: Stefan Karpinski
Message 2 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.