git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	Lars Schneider <larsxschneider@gmail.com>
Cc: git <git@vger.kernel.org>
Subject: Re: [PATCH] launch_editor(): indicate that Git waits for user input
Date: Sat, 18 Nov 2017 23:17:14 +0530	[thread overview]
Message-ID: <26256555-4463-7bc9-5d07-8617932cf6cb@gmail.com> (raw)
In-Reply-To: <xmqqr2syvjxb.fsf@gitster.mtv.corp.google.com>

On Thursday 16 November 2017 11:34 AM, Junio C Hamano wrote:
> 
>   * I tried this with "emacsclient" but it turns out that Emacs folks
>     have already thought about this issue, and the program says
>     "Waiting for Emacs..." while it does its thing, so from that
>     point of view, perhaps as Stefan said originally, the editor Lars
>     had trouble with is what is at fault and needs fixing?  I dunno.
> 
>     Also, emacsclient seems to conclude its message, once the editing
>     is done, by emitting LF _before_ we have a chance to do the "go
>     back to the beginning and clear" dance, so it probably is not a
>     very good example to emulate the situation Lars had trouble with.
>     You cannot observe the nuking of the "launched, waiting..." with
>     it.
>

I tried this patch with 'gedit' and it seems to work fine except for one 
particular case. When the launched editor gets killed somehow when 
waiting for user input, the error message shown in the terminal seems to 
be following the "Launched editor..." message immediately, making it 
hard to identify it.

$ GIT_EDITOR=gedit ./git commit --allow-empty
Launched your editor, waiting...error: gedit died of signal 15
error: There was a problem with the editor 'gedit'.
Please supply the message using either -m or -F option.

Though this is not something that's going to happen very often, I'm not 
sure if this is to be considered. Just wanted to note what I observed.


>   editor.c | 25 +++++++++++++++++++++++++
>   1 file changed, 25 insertions(+)
> 
> diff --git a/editor.c b/editor.c
> index 7519edecdc..1321944716 100644
> --- a/editor.c
> +++ b/editor.c
> @@ -40,6 +40,28 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
>   		const char *args[] = { editor, real_path(path), NULL };
>   		struct child_process p = CHILD_PROCESS_INIT;
>   		int ret, sig;
> +		static const char *close_notice = NULL;

Just a little curious, what's the advantage of making 'close_notice' 
'static' over 'auto' ?


> +
> +		if (isatty(2) && !close_notice) {
> +			char *term = getenv("TERM");
> +
> +			if (term && strcmp(term, "dumb"))
> +				/*
> +				 * go back to the beginning and erase the
> +				 * entire line if the terminal is capable
> +				 * to do so, to avoid wasting the vertical
> +				 * space.
> +				 */
> +				close_notice = "\r\033[K";
> +			else
> +				/* otherwise, complete and waste the line */
> +				close_notice = "done.\n";
> +		}
> +
> +		if (close_notice) {
> +			fprintf(stderr, "Launched your editor, waiting...");
> +			fflush(stderr);

Being curious again, is flushing 'stderr' required ? AFAIK, 'stderr' is 
unbuffered by default and I didn't notice any calls that changed the 
buffering mode of it along this code path.


> +		}
>   
>   		p.argv = args;
>   		p.env = env;
> @@ -53,11 +75,14 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
>   		sig = ret - 128;
>   		sigchain_pop(SIGINT);
>   		sigchain_pop(SIGQUIT);
> +
>   		if (sig == SIGINT || sig == SIGQUIT)
>   			raise(sig);
>   		if (ret)
>   			return error("There was a problem with the editor '%s'.",
>   					editor);
> +		if (close_notice)
> +			fputs(close_notice, stderr);
>   	}
>   
>   	if (!buffer)
> 


  parent reply	other threads:[~2017-11-18 17:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-15 15:08 [RFC] Indicate that Git waits for user input via editor Lars Schneider
2017-11-15 17:51 ` Stefan Beller
2017-11-15 18:07   ` Lars Schneider
2017-11-15 18:37     ` Stefan Beller
2017-11-15 22:32 ` Junio C Hamano
2017-11-16  0:06   ` Stefan Beller
2017-11-16  0:33     ` Junio C Hamano
2017-11-16  0:37       ` Stefan Beller
2017-11-16  5:37   ` Junio C Hamano
2017-11-16  6:04 ` [PATCH] launch_editor(): indicate that Git waits for user input Junio C Hamano
2017-11-16 10:25   ` Lars Schneider
2017-11-16 14:58     ` Junio C Hamano
2017-11-16 15:24       ` Lars Schneider
2017-11-17  1:09         ` Junio C Hamano
2017-11-18 17:47   ` Kaartic Sivaraam [this message]
2017-11-19  1:07     ` Junio C Hamano

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=26256555-4463-7bc9-5d07-8617932cf6cb@gmail.com \
    --to=kaartic.sivaraam@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=larsxschneider@gmail.com \
    /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 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).