All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Christian Rösch" <christian@croesch.de>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] add--interactive: handle EOF in prompt_yesno
Date: Wed, 21 Jun 2017 15:26:36 -0400	[thread overview]
Message-ID: <20170621192636.e5odne2lojuq63gm@sigill.intra.peff.net> (raw)
In-Reply-To: <20170621192315.3umx4lszvzwjffnb@sigill.intra.peff.net>

The prompt_yesno function loops indefinitely waiting for a
"y" or "n" response. But it doesn't handle EOF, meaning
that we can end up in an infinite loop of reading EOF from
stdin. One way to simulate that is with:

  echo e | GIT_EDITOR='echo corrupt >' git add -p

Let's break out of the loop and propagate the undef to the
caller. Without modifying the callers that effectively turns
it into a "no" response. This is reasonable for both of the
current callers, and it leaves room for any future caller to
check for undef explicitly.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-add--interactive.perl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 79d675b5b..fc722fe8a 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1136,6 +1136,7 @@ sub prompt_yesno {
 	while (1) {
 		print colored $prompt_color, $prompt;
 		my $line = prompt_single_character;
+		return undef unless defined $line;
 		return 0 if $line =~ /^n/i;
 		return 1 if $line =~ /^y/i;
 	}
-- 
2.13.1.792.g159074dab


  reply	other threads:[~2017-06-21 19:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21 16:31 git add -p does not work with custom comment char currently Christian Rösch
2017-06-21 18:20 ` Jeff King
2017-06-21 19:23   ` [PATCH 0/2] " Jeff King
2017-06-21 19:26     ` Jeff King [this message]
2017-06-21 19:28     ` [PATCH 2/2] add--interactive: quote commentChar regex Jeff King
2017-06-21 21:12       ` Christian Rösch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170621192636.e5odne2lojuq63gm@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=christian@croesch.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.