git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] sending errors to stdout under $PAGER
@ 2008-02-16 19:15 Junio C Hamano
  2008-02-17  7:50 ` Shawn O. Pearce
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Junio C Hamano @ 2008-02-16 19:15 UTC (permalink / raw)
  To: git

If you do this (and you are not an Emacs user who uses PAGER=cat
in your *shell* buffer):

        $ git init
        Initialized empty Git repository in .git/
        $ echo hello world >foo
        $ H=$(git hash-object -w foo)
        $ git tag -a foo-tag -m "Tags $H" $H
        $ echo $H
        3b18e512dba79e4c8300dd08aeb37f8e728b8dad
        $ rm -f .git/objects/3b/18e5*
        $ git show foo-tag
        tag foo-tag
        Tagger: Junio C Hamano <gitster@pobox.com>
        Date:   Sat Feb 16 10:43:23 2008 -0800

        Tags 3b18e512dba79e4c8300dd08aeb37f8e728b8dad

you do not get any indication of error.  If you are careful, you
would notice that no contents from the tagged object is
displayed, but that is about it.  If you run the "show" command
without pager, however, you will see the error:

        $ git --no-pager show foo-tag
        tag foo-tag
        Tagger: Junio C Hamano <gitster@pobox.com>
        Date:   Sat Feb 16 10:43:23 2008 -0800

        Tags 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
        error: Could not read object 3b18e512dba79e4c8300dd08aeb37f8e728b8dad

Because we spawn the pager as the foreground process and feed
its input via pipe from the real command, we cannot affect the
exit status the shell sees from git command when the pager is in
use (I think there is not much gain we can have by working it
around, though).  But at least it may make sense to show the
error message to the user sitting in front of the pager, perhaps
like this.

What do people think?  Have I overlooked any downsides?

---
 usage.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/usage.c b/usage.c
index a5fc4ec..681b84a 100644
--- a/usage.c
+++ b/usage.c
@@ -4,12 +4,15 @@
  * Copyright (C) Linus Torvalds, 2005
  */
 #include "git-compat-util.h"
+#include "cache.h"
 
 static void report(const char *prefix, const char *err, va_list params)
 {
 	char msg[256];
+	FILE *outto = (pager_in_use() ? stdout : stderr);
+
 	vsnprintf(msg, sizeof(msg), err, params);
-	fprintf(stderr, "%s%s\n", prefix, msg);
+	fprintf(outto, "%s%s\n", prefix, msg);
 }
 
 static NORETURN void usage_builtin(const char *err)

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [RFC] sending errors to stdout under $PAGER
  2008-02-16 19:15 [RFC] sending errors to stdout under $PAGER Junio C Hamano
@ 2008-02-17  7:50 ` Shawn O. Pearce
  2008-02-17 12:35 ` Jeff King
  2008-02-17 13:48 ` Edgar Toernig
  2 siblings, 0 replies; 9+ messages in thread
From: Shawn O. Pearce @ 2008-02-17  7:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano <gitster@pobox.com> wrote:
> Because we spawn the pager as the foreground process and feed
> its input via pipe from the real command, we cannot affect the
> exit status the shell sees from git command when the pager is in
> use (I think there is not much gain we can have by working it
> around, though).  But at least it may make sense to show the
> error message to the user sitting in front of the pager, perhaps
> like this.
> 
> What do people think?  Have I overlooked any downsides?

I think this is a good idea.

If you are using an interactive pager, you have asked for the content
to come to you through that.  Not unlike how I have chosen to have
the content come to me through a virtual pty and not a printer with
green-and-white bar paper.  :)

I've been bitten by this in the past a few times, but I have also
been knowledgable enough about git, the command I ran, and the
project I ran it on to realize something wasn't right with the
output I am seeing in the pager and retry without the pager to see
the real error(s).

> +++ b/usage.c
> @@ -4,12 +4,15 @@
>   * Copyright (C) Linus Torvalds, 2005
>   */
>  #include "git-compat-util.h"
> +#include "cache.h"
>  
>  static void report(const char *prefix, const char *err, va_list params)
>  {
>  	char msg[256];
> +	FILE *outto = (pager_in_use() ? stdout : stderr);
> +
>  	vsnprintf(msg, sizeof(msg), err, params);
> -	fprintf(stderr, "%s%s\n", prefix, msg);
> +	fprintf(outto, "%s%s\n", prefix, msg);
>  }

-- 
Shawn.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] sending errors to stdout under $PAGER
  2008-02-16 19:15 [RFC] sending errors to stdout under $PAGER Junio C Hamano
  2008-02-17  7:50 ` Shawn O. Pearce
@ 2008-02-17 12:35 ` Jeff King
  2008-02-17 13:48 ` Edgar Toernig
  2 siblings, 0 replies; 9+ messages in thread
From: Jeff King @ 2008-02-17 12:35 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Sat, Feb 16, 2008 at 11:15:41AM -0800, Junio C Hamano wrote:

> Because we spawn the pager as the foreground process and feed
> its input via pipe from the real command, we cannot affect the
> exit status the shell sees from git command when the pager is in
> use (I think there is not much gain we can have by working it
> around, though).  But at least it may make sense to show the
> error message to the user sitting in front of the pager, perhaps
> like this.
> 
> What do people think?  Have I overlooked any downsides?

I think this makes sense. It could be annoying if chatty stderr output
got mixed in with the actual output, making things harder to read. But
git is not very chatty in general, and the point is that things sent to
stderr _should_ grab the user's attention.

The only downside I see is that it disrupts the parsing of the output.
In most cases, this doesn't matter, since anything parsing the output
will disable the pager. The notable exception is something like 'tig',
which I believe can act as a git pager which understands the output; it
can potentially be confused by the extra lines on stdout.

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] sending errors to stdout under $PAGER
  2008-02-16 19:15 [RFC] sending errors to stdout under $PAGER Junio C Hamano
  2008-02-17  7:50 ` Shawn O. Pearce
  2008-02-17 12:35 ` Jeff King
@ 2008-02-17 13:48 ` Edgar Toernig
  2008-02-17 15:15   ` Johannes Schindelin
  2008-02-17 17:56   ` Junio C Hamano
  2 siblings, 2 replies; 9+ messages in thread
From: Edgar Toernig @ 2008-02-17 13:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano wrote:
>
> +	FILE *outto = (pager_in_use() ? stdout : stderr);
> +
>  	vsnprintf(msg, sizeof(msg), err, params);
> -	fprintf(stderr, "%s%s\n", prefix, msg);
> +	fprintf(outto, "%s%s\n", prefix, msg);
>
> What do people think?  Have I overlooked any downsides?

Wouldn't it be better/safer to redirect stderr to the pager
in the first place?

So, instead of the current

	foo | less
use
	foo 2>&1 | less

or, in pager.c:

         /* return in the child */
        if (!pid) {
                dup2(fd[1], 1);
+               dup2(fd[1], 2);
                close(fd[0]);
                close(fd[1]);
                return;
        }

Ciao, ET.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] sending errors to stdout under $PAGER
  2008-02-17 13:48 ` Edgar Toernig
@ 2008-02-17 15:15   ` Johannes Schindelin
  2008-02-17 17:56   ` Junio C Hamano
  1 sibling, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2008-02-17 15:15 UTC (permalink / raw)
  To: Edgar Toernig; +Cc: Junio C Hamano, git

Hi,

On Sun, 17 Feb 2008, Edgar Toernig wrote:

> Junio C Hamano wrote:
> >
> > +	FILE *outto = (pager_in_use() ? stdout : stderr);
> > +
> >  	vsnprintf(msg, sizeof(msg), err, params);
> > -	fprintf(stderr, "%s%s\n", prefix, msg);
> > +	fprintf(outto, "%s%s\n", prefix, msg);
> >
> > What do people think?  Have I overlooked any downsides?
> 
> Wouldn't it be better/safer to redirect stderr to the pager
> in the first place?
> 
> [...]
>
>          /* return in the child */
>         if (!pid) {
>                 dup2(fd[1], 1);
> +               dup2(fd[1], 2);
>                 close(fd[0]);
>                 close(fd[1]);
>                 return;
>         }

I like it.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] sending errors to stdout under $PAGER
  2008-02-17 13:48 ` Edgar Toernig
  2008-02-17 15:15   ` Johannes Schindelin
@ 2008-02-17 17:56   ` Junio C Hamano
  2008-02-17 18:15     ` Jeff King
  1 sibling, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2008-02-17 17:56 UTC (permalink / raw)
  To: Edgar Toernig; +Cc: git

Edgar Toernig <froese@gmx.de> writes:

> Junio C Hamano wrote:
>>
>> +	FILE *outto = (pager_in_use() ? stdout : stderr);
>> +
>>  	vsnprintf(msg, sizeof(msg), err, params);
>> -	fprintf(stderr, "%s%s\n", prefix, msg);
>> +	fprintf(outto, "%s%s\n", prefix, msg);
>>
>> What do people think?  Have I overlooked any downsides?
>
> Wouldn't it be better/safer to redirect stderr to the pager
> in the first place?
>
> So, instead of the current
>
> 	foo | less
> use
> 	foo 2>&1 | less

I like it.  Much nicer.  Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] sending errors to stdout under $PAGER
  2008-02-17 17:56   ` Junio C Hamano
@ 2008-02-17 18:15     ` Jeff King
  2008-02-17 18:23       ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2008-02-17 18:15 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Edgar Toernig, git

On Sun, Feb 17, 2008 at 09:56:27AM -0800, Junio C Hamano wrote:

> > Wouldn't it be better/safer to redirect stderr to the pager
> > in the first place?
> >
> > So, instead of the current
> >
> > 	foo | less
> > use
> > 	foo 2>&1 | less
> 
> I like it.  Much nicer.  Thanks.

This will also put the stderr of any sub-programs into the pager, which
is probably worse if you have, e.g., a chatty external diff program. I
don't know if we care enough about that.

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] sending errors to stdout under $PAGER
  2008-02-17 18:15     ` Jeff King
@ 2008-02-17 18:23       ` Junio C Hamano
  2008-02-17 19:38         ` Johannes Schindelin
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2008-02-17 18:23 UTC (permalink / raw)
  To: Jeff King; +Cc: Edgar Toernig, git

Jeff King <peff@peff.net> writes:

> On Sun, Feb 17, 2008 at 09:56:27AM -0800, Junio C Hamano wrote:
>
>> > Wouldn't it be better/safer to redirect stderr to the pager
>> > in the first place?
>> >
>> > So, instead of the current
>> >
>> > 	foo | less
>> > use
>> > 	foo 2>&1 | less
>> 
>> I like it.  Much nicer.  Thanks.
>
> This will also put the stderr of any sub-programs into the pager, which
> is probably worse if you have, e.g., a chatty external diff program. I
> don't know if we care enough about that.

We'll soon find out and the change would be a single liner that
is very easy to back out, so let's put it in and see what
happens ;-).

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFC] sending errors to stdout under $PAGER
  2008-02-17 18:23       ` Junio C Hamano
@ 2008-02-17 19:38         ` Johannes Schindelin
  0 siblings, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2008-02-17 19:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Edgar Toernig, git

Hi,

On Sun, 17 Feb 2008, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > On Sun, Feb 17, 2008 at 09:56:27AM -0800, Junio C Hamano wrote:
> >
> >> > Wouldn't it be better/safer to redirect stderr to the pager in the 
> >> > first place?
> >> >
> >> > So, instead of the current
> >> >
> >> > 	foo | less
> >> > use
> >> > 	foo 2>&1 | less
> >> 
> >> I like it.  Much nicer.  Thanks.
> >
> > This will also put the stderr of any sub-programs into the pager, 
> > which is probably worse if you have, e.g., a chatty external diff 
> > program. I don't know if we care enough about that.
> 
> We'll soon find out and the change would be a single liner that is very 
> easy to back out, so let's put it in and see what happens ;-).

I think this is a non-problem.  External diff programs are virtually all 
scripts written for git, because of the calling convention.  So all this 
does is tell the people who use external diff wrappers (and let them be 
chatty) to fix their scripts.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-02-17 19:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-16 19:15 [RFC] sending errors to stdout under $PAGER Junio C Hamano
2008-02-17  7:50 ` Shawn O. Pearce
2008-02-17 12:35 ` Jeff King
2008-02-17 13:48 ` Edgar Toernig
2008-02-17 15:15   ` Johannes Schindelin
2008-02-17 17:56   ` Junio C Hamano
2008-02-17 18:15     ` Jeff King
2008-02-17 18:23       ` Junio C Hamano
2008-02-17 19:38         ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).