{"thread":{"id":"16746","subject":"git-diff should not fire up $PAGER if there is no diff","startedAt":"2008-12-16T00:21:33Z","lastAt":"2008-12-22T08:30:44Z","messageCount":13,"participants":["jidanni@jidanni.org","Jeff King","Stefan Karpinski","Junio C Hamano","Linus Torvalds","Miles Bader","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"98014","messageId":"874p15x94i.fsf@jidanni.org","threadId":"16746","inReplyTo":null,"subject":"git-diff should not fire up $PAGER if there is no diff","fromName":"","fromEmail":"jidanni@jidanni.org","sentAt":"2008-12-16T00:21:33Z","receivedAt":"2008-12-16T00:21:33Z","isPatch":false,"sender":{"key":"jidanni@jidanni.org","avatar":"https://gravatar.com/avatar/36568d4af4c8d3e71627ef3b8c8d00e39065b12f29676cccd38ced75e68fa2a6?d=mp&s=160"},"body":"git-diff should not fire up $PAGER if there is no diff output.\nJust exit. The man page doesn't even mention $PAGER too.\n"},{"id":"98018","messageId":"20081216005658.GB3679@coredump.intra.peff.net","threadId":"16746","inReplyTo":"874p15x94i.fsf@jidanni.org","subject":"Re: git-diff should not fire up $PAGER if there is no diff","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-12-16T00:56:58Z","receivedAt":"2008-12-16T00:56:58Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 16, 2008 at 08:21:33AM +0800, jidanni@jidanni.org wrote:\n\n> git-diff should not fire up $PAGER if there is no diff output.\n> Just exit. The man page doesn't even mention $PAGER too.\n\nI agree that would be nice, but it is a little difficult to implement.\nThe current behavior forks early and then pipes the output to the pager.\nSo we would have to:\n\n  1. change that behavior to instead delay starting the pager until the\n     first output. Which means intercepting every\n     write/fwrite/printf/fputs/etc call.\n\n  2. detect EOF before starting the pager. We in fact already delay\n     running the pager in the forked process until we have some activity\n     on the pipe, but I don't know if there is a portable way of\n     detecting that that activity is EOF without performing an actual\n     read() call (which is undesirable, since it eats the first byte of\n     output that should go to the pager).\n\n  3. a hacky solution to (2) above would be to make _2_ pipes, one of\n     which signals to the pager sub-process either \"exit now\" or \"proceed\n     with running the pager\".\n\nThe usual workaround is to ask the pager to exit immediately if the\noutput is small. I.e., putting \"F\" in your LESS variable (which git does\nautomatically if you don't already have LESS set).\n\n-Peff\n"},{"id":"98045","messageId":"d4bc1a2a0812152235l14ec80bbr130a7ab152ad6b8@mail.gmail.com","threadId":"16746","inReplyTo":"20081216005658.GB3679@coredump.intra.peff.net","subject":"Re: git-diff should not fire up $PAGER if there is no diff","fromName":"Stefan Karpinski","fromEmail":"stefan.karpinski@gmail.com","sentAt":"2008-12-16T06:35:53Z","receivedAt":"2008-12-16T06:35:53Z","isPatch":false,"sender":{"key":"stefan.karpinski@gmail.com","avatar":"https://gravatar.com/avatar/780cfb8dd7d7dc749d7276a4ca2ec24e7f0482cfce509717c5ddd165fd2cc9d9?d=mp&s=160"},"body":"> On Mon, Dec 15, 2008 at 7:56 PM, Jeff King <peff@peff.net> wrote:\n>  2. detect EOF before starting the pager. We in fact already delay\n>     running the pager in the forked process until we have some activity\n>     on the pipe, but I don't know if there is a portable way of\n>     detecting that that activity is EOF without performing an actual\n>     read() call (which is undesirable, since it eats the first byte of\n>     output that should go to the pager).\n\nWouldn't ungetc work? Or is that not portable enough? (It would only\nwork here because the EOF has to be the first character.)\n"},{"id":"98049","messageId":"20081216074414.GB2468@coredump.intra.peff.net","threadId":"16746","inReplyTo":"d4bc1a2a0812152235l14ec80bbr130a7ab152ad6b8@mail.gmail.com","subject":"Re: git-diff should not fire up $PAGER if there is no diff","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-12-16T07:44:14Z","receivedAt":"2008-12-16T07:44:14Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Dec 16, 2008 at 01:35:53AM -0500, Stefan Karpinski wrote:\n\n> > On Mon, Dec 15, 2008 at 7:56 PM, Jeff King <peff@peff.net> wrote:\n> >  2. detect EOF before starting the pager. We in fact already delay\n> >     running the pager in the forked process until we have some activity\n> >     on the pipe, but I don't know if there is a portable way of\n> >     detecting that that activity is EOF without performing an actual\n> >     read() call (which is undesirable, since it eats the first byte of\n> >     output that should go to the pager).\n> \n> Wouldn't ungetc work? Or is that not portable enough? (It would only\n> work here because the EOF has to be the first character.)\n\nNo, it won't work. ungetc works on the buffered stdio object, so it is\nuseful for pushing back characters onto the buffer to be read later in\nthe program from the same buffer. But in this case, we are going to\nexecv() (or on Windows, spawn) the pager, meaning it will throw away\nanything that has been read() from the pipe and put in the buffer.\n\nSo we would need a system call to push a character back to the OS, so\nthat it was available for read() by the pager process.\n\n-Peff\n"},{"id":"98085","messageId":"d4bc1a2a0812161443k62e4b53s841ac32f653037fe@mail.gmail.com","threadId":"16746","inReplyTo":"20081216074414.GB2468@coredump.intra.peff.net","subject":"Re: git-diff should not fire up $PAGER if there is no diff","fromName":"Stefan Karpinski","fromEmail":"stefan.karpinski@gmail.com","sentAt":"2008-12-16T22:43:28Z","receivedAt":"2008-12-16T22:43:28Z","isPatch":false,"sender":{"key":"stefan.karpinski@gmail.com","avatar":"https://gravatar.com/avatar/780cfb8dd7d7dc749d7276a4ca2ec24e7f0482cfce509717c5ddd165fd2cc9d9?d=mp&s=160"},"body":"On Tue, Dec 16, 2008 at 2:44 AM, Jeff King <peff@peff.net> wrote:\n> On Tue, Dec 16, 2008 at 01:35:53AM -0500, Stefan Karpinski wrote:\n>\n>> > On Mon, Dec 15, 2008 at 7:56 PM, Jeff King <peff@peff.net> wrote:\n>> >  2. detect EOF before starting the pager. We in fact already delay\n>> >     running the pager in the forked process until we have some activity\n>> >     on the pipe, but I don't know if there is a portable way of\n>> >     detecting that that activity is EOF without performing an actual\n>> >     read() call (which is undesirable, since it eats the first byte of\n>> >     output that should go to the pager).\n>>\n>> Wouldn't ungetc work? Or is that not portable enough? (It would only\n>> work here because the EOF has to be the first character.)\n>\n> No, it won't work. ungetc works on the buffered stdio object, so it is\n> useful for pushing back characters onto the buffer to be read later in\n> the program from the same buffer. But in this case, we are going to\n> execv() (or on Windows, spawn) the pager, meaning it will throw away\n> anything that has been read() from the pipe and put in the buffer.\n>\n> So we would need a system call to push a character back to the OS, so\n> that it was available for read() by the pager process.\n\nYeah, I realized that after I sent the message. Late night sending bad!\n"},{"id":"98189","messageId":"8763lixyps.fsf_-_@jidanni.org","threadId":"16746","inReplyTo":"20081216005658.GB3679@coredump.intra.peff.net","subject":"git-diff should not fire up $PAGER, period!","fromName":"","fromEmail":"jidanni@jidanni.org","sentAt":"2008-12-17T21:45:35Z","receivedAt":"2008-12-17T21:45:35Z","isPatch":false,"sender":{"key":"jidanni@jidanni.org","avatar":"https://gravatar.com/avatar/36568d4af4c8d3e71627ef3b8c8d00e39065b12f29676cccd38ced75e68fa2a6?d=mp&s=160"},"body":"Gentlemen, I have found the solution to your problem.\n\nUnbundle git-diff and $PAGER.\n\nAsk yourself, does diff(1) call $PAGER?\n\nNo. That's because the Unix designers were smart enough not to glue\neverything together.\n\nNow's your chance to repent, as you haven't even yet mentioned $PAGER\non the git-diff man page. Yes, do mention it: \"EXAMPLES: git-diff|less\"\nI.e., the user can page the output if he feels inclined, just like any\nother output. I mean one already has a wallet. The bank need not give\nthe user one every time they make a withdraw.\n\nI mean here I am in emacs, and\n\n-*- mode: compilation; default-directory: \"...coreutils/\" -*-\nCompilation started at Thu Dec 18 03:15:14\ngit-diff\nWARNING: terminal is not fully functional^M\n^M-  (press RETURN)\n\n\"It's all emacs' fault for emulating a tty too well\"... no, it's all\nyour fault for gumming things together. No I don't want my cookies\nwith obligatory milk. I'll using git-diff|cat for now instead of\ncomplaining that emacs is all wrong. Even using git-diff|cat|less is\nbetter than messing with the LESS=F bug. Repent, whippersnappers!\n\nOK, doing test x$EMACS = xt && PAGER=cat in .bashrc. That will help\nfor emacs' shell buffers, but not compilation mode buffers... \"then\njust make a hook\"... 13 hooks to combat one poor design choice.\nAnd one notices git-show is gummed up too.\n\nHmm, looking in changelogs, we see\n\n * Error messages used to be sent to stderr, only to get hidden,\n   when $PAGER was in use.  They now are sent to stdout along\n   with the command output to be shown in the $PAGER.\n\nWell, if you had left paging to the user, no one would have blamed you\nfor making error messages disappear, and you could have left stderr as\nthe elders intended.\n\nWait,\n$ git-config --global core.pager \"\"\nCool. Bye.\n"},{"id":"98191","messageId":"7viqpijw92.fsf@gitster.siamese.dyndns.org","threadId":"16746","inReplyTo":"8763lixyps.fsf_-_@jidanni.org","subject":"Re: git-diff should not fire up $PAGER, period!","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-17T22:02:33Z","receivedAt":"2008-12-17T22:02:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"jidanni@jidanni.org writes:\n\n> I mean here I am in emacs, and\n>\n> -*- mode: compilation; default-directory: \"...coreutils/\" -*-\n> Compilation started at Thu Dec 18 03:15:14\n> git-diff\n> WARNING: terminal is not fully functional^M\n> ^M-  (press RETURN)\n\nAny semi-good emacs users (let alone hackers) export PAGER=cat to be used\nin compilation mode (and possibly shell mode), so this is not a problem in\npractice.\n\nI have something like this in my .emacs:\n\n    (setenv \"PAGER\" \"cat\")\n\nI suspect (I am just a user not a hacker) this will have bad interaction\nwith emacs terminal emulation mode, but I do not use the mode, so it is\nenough for me.\n"},{"id":"98192","messageId":"alpine.LFD.2.00.0812171401300.14014@localhost.localdomain","threadId":"16746","inReplyTo":"8763lixyps.fsf_-_@jidanni.org","subject":"Re: git-diff should not fire up $PAGER, period!","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2008-12-17T22:04:30Z","receivedAt":"2008-12-17T22:04:30Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 18 Dec 2008, jidanni@jidanni.org wrote:\n>\n> Gentlemen, I have found the solution to your problem.\n\nUmm. YOUR problem.\n\nDo that whole\n\n\t[core]\n\t\tpager = \n\nand you can get the behaviour you want.\n\nOr just get rid of emacs. Your problem has nothing to do with git, and \neverything to do with emacs. And then you have the _gall_ to talk about \n\"unix design\" and not gumming programs together, when you yourself use the \nmost gummed-up piece of absolute sh*t there is!\n\n\t\t\tLinus\n"},{"id":"98221","messageId":"20081218033116.GC20749@coredump.intra.peff.net","threadId":"16746","inReplyTo":"8763lixyps.fsf_-_@jidanni.org","subject":"Re: git-diff should not fire up $PAGER, period!","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-12-18T03:31:16Z","receivedAt":"2008-12-18T03:31:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Dec 18, 2008 at 05:45:35AM +0800, jidanni@jidanni.org wrote:\n\n> Gentlemen, I have found the solution to your problem.\n> \n> Unbundle git-diff and $PAGER.\n\nIf you are going to argue this, please at least go back and read the\nnumerous times it has been brought up in the past on the list archive.\n\nThe last discussion ended up showing that some people really like the\nautomatic pager for some commands, and some people really detest it.\nSo I implemented 4e10738 (Allow per-command pager config, 2008-07-03),\nand now you can do:\n\n  git config pager.diff false\n\nand be happy (or, as you obviously disocvered, simply unsetting\ncore.pager will disable all).\n\n-Peff\n"},{"id":"98533","messageId":"buo3aggyjmy.fsf@dhapc248.dev.necel.com","threadId":"16746","inReplyTo":"8763lixyps.fsf_-_@jidanni.org","subject":"Re: git-diff should not fire up $PAGER, period!","fromName":"Miles Bader","fromEmail":"miles@gnu.org","sentAt":"2008-12-22T03:27:17Z","receivedAt":"2008-12-22T03:27:17Z","isPatch":false,"sender":{"key":"miles@gnu.org","avatar":"https://gravatar.com/avatar/01069b69593af7bff28e2f97afeb3644ae6fe2f5f56cb3a8cf34c5fb8c36efe5?d=mp&s=160"},"body":"Just (setenv \"PAGER\" \"cat\") in .emacs.\n\n[I actually have it set to /bin/cat, not sure if that's meaningful or not.]\n\n-Miles\n\n-- \n.Numeric stability is probably not all that important when you're guessing.\n"},{"id":"98534","messageId":"buowsdsx50q.fsf@dhapc248.dev.necel.com","threadId":"16746","inReplyTo":"alpine.LFD.2.00.0812171401300.14014@localhost.localdomain","subject":"Re: git-diff should not fire up $PAGER, period!","fromName":"Miles Bader","fromEmail":"miles@gnu.org","sentAt":"2008-12-22T03:28:21Z","receivedAt":"2008-12-22T03:28:21Z","isPatch":false,"sender":{"key":"miles@gnu.org","avatar":"https://gravatar.com/avatar/01069b69593af7bff28e2f97afeb3644ae6fe2f5f56cb3a8cf34c5fb8c36efe5?d=mp&s=160"},"body":"Linus Torvalds <torvalds@linux-foundation.org> writes:\n> And then you have the _gall_ to talk about \"unix design\"...\n\nAnother beer?\n\n-Miles\n\n-- \nSuburbia: where they tear out the trees and then name streets after them.\n"},{"id":"98536","messageId":"494F47E1.8070105@viscovery.net","threadId":"16746","inReplyTo":"buo3aggyjmy.fsf@dhapc248.dev.necel.com","subject":"Re: git-diff should not fire up $PAGER, period!","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-12-22T07:55:13Z","receivedAt":"2008-12-22T07:55:13Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Miles Bader schrieb:\n> Just (setenv \"PAGER\" \"cat\") in .emacs.\n> \n> [I actually have it set to /bin/cat, not sure if that's meaningful or not.]\n\nNo, really, you should set it to plain \"cat\": As a special case git\nrecognizes this token and does not run any pager. If you set it to\n\"/bin/cat\" it does run a pager, namely /bin/cat.\n\n-- Hannes\n"},{"id":"98537","messageId":"7vfxkgk3wr.fsf@gitster.siamese.dyndns.org","threadId":"16746","inReplyTo":"494F47E1.8070105@viscovery.net","subject":"Re: git-diff should not fire up $PAGER, period!","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-12-22T08:30:44Z","receivedAt":"2008-12-22T08:30:44Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n> Miles Bader schrieb:\n>> Just (setenv \"PAGER\" \"cat\") in .emacs.\n>> \n>> [I actually have it set to /bin/cat, not sure if that's meaningful or not.]\n>\n> No, really, you should set it to plain \"cat\": As a special case git\n> recognizes this token and does not run any pager. If you set it to\n> \"/bin/cat\" it does run a pager, namely /bin/cat.\n\nBut that would not hurt ;-).\n\nOn the other hand, using PAGER=cat or PAGER=/bin/cat is the right thing to\ndo in compilation and shell modes in Emacs, regardless of your use of git.\n"}]}