Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-23 Thread Junio C Hamano
Lars Schneider  writes:

>> Of course it is possible, if you really wanted to.  The code knows
>> if it gave the "we launched and waiting for you" notice, so it can
>> maintain not just one (i.e. "how I close the notice?") but another
>> one (i.e. "how I do so upon an error?") and use it in the error
>> codepath.
>
> I think a newline makes sense. I'll look into this for v3.

As this is an error codepath, I am OK to waste one more line with a
line break after the "we launched and are waiting..." message, but
with a shorter "we are waiting..." message, I do not know if it is
bad enough to have these two on the same line, so I am on the fence.


Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-22 Thread Kaartic Sivaraam

On Wednesday 22 November 2017 10:25 PM, Lars Schneider wrote:



On 20 Nov 2017, at 01:11, Junio C Hamano  wrote:

Kaartic Sivaraam  writes:

It might be a good thing to keep the notice but I think it would be
better to have that error message in a "new line". I'm not sure if
it's possible or not.


Of course it is possible, if you really wanted to.  The code knows
if it gave the "we launched and waiting for you" notice, so it can
maintain not just one (i.e. "how I close the notice?") but another
one (i.e. "how I do so upon an error?") and use it in the error
codepath.


I think a newline makes sense. I'll look into this for v3.



If I remember correctly, I don't think it's as simple as printing a 
newline character in case of an error.  That's because the error message 
that shows up in the same line as "Launched your ..." comes from a 
different function (possibly finish_command() though I'm not sure)



Thanks,
Lars





Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-22 Thread Eric Sunshine
On Wed, Nov 22, 2017 at 11:53 AM, Lars Schneider
 wrote:
>> On 17 Nov 2017, at 20:41, Eric Sunshine  wrote:
>> * emacsclient already prints its own message ("Waiting for Emacs...",
>> which runs together with Git's message). Perhaps treat emacsclient as
>> a special case and skip printing this message if emacsclient is in
>> use: if (strstr(...,"emacsclient"))
>
> If Junio et al. are ok with the special handling of emacs, then I am happy
> to add this change in v3. If we look for "emacsclient", then would this
> cover emacs on Linux and Windows, too? (I am no emacs user)

Yes, searching for "emacsclient" should work on all platforms (Linux,
MacOS, Windows, BSD). Most of the time, the full value of EDITOR is
just "emacsclient", but sometimes emacsclient is located at an
out-of-the-way location, not in PATH, such as in my example
(/long/path/to/emacsclient). On Windows, it's actually called
"emacsclientw", but that should be matched just fine when searching
for "emacsclient".


Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-22 Thread Lars Schneider

> On 20 Nov 2017, at 01:11, Junio C Hamano  wrote:
> 
> Kaartic Sivaraam  writes:
> 
 However, it's not clear how much benefit you gain from stashing this
 away in a static variable. Premature optimization?
>>> 
>>> The variable being "static" could be (but it was done primarily
>>> because it allowed me not to worry about freeing),
> 
> The current code happens to be safe because I do not allocate.  I do
> not know what others will do to the code in the future, and at that
> point, instinct kicks in to futureproof against the worst ;-).
> 
 Should printing of close_notice be done before the error()? Otherwise,
 you get this:
 
 --- 8< ---
 Launched your editor (...) ...There was a problem...
 --- 8< ---
>>> 
>>> In my version with a far shorter message, I deliberately chose not
>>> to clear the notice.  We ran the editor, and we saw a problem.  That
>>> is what happened and that is what will be left on the terminal.
>>> 
>> 
>> It might be a good thing to keep the notice but I think it would be
>> better to have that error message in a "new line". I'm not sure if
>> it's possible or not.
> 
> Of course it is possible, if you really wanted to.  The code knows
> if it gave the "we launched and waiting for you" notice, so it can
> maintain not just one (i.e. "how I close the notice?") but another
> one (i.e. "how I do so upon an error?") and use it in the error
> codepath.

I think a newline makes sense. I'll look into this for v3.

Thanks,
Lars


Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-22 Thread Lars Schneider

> On 17 Nov 2017, at 20:41, Eric Sunshine  wrote:
> 
> On Fri, Nov 17, 2017 at 8:51 AM,   wrote:
> 
>> +   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 ('%s'). Adjust, save, 
>> and close the "
>> +   "file to continue. Waiting for your input... 
>> ", editor
>> +   );
> 
> Here's what this looks like for me:
> 
> --- 8< ---
> Launched your editor
> ('/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'). Adjust,
> save, and close the file to continue. Waiting for your input...
> Waiting for Emacs...
> --- 8< ---
> 
> Very, very noisy, so much so that it's almost unreadable. There are at
> least three reasons for the noise:
> 
> * The raw message itself is already overly long. Do we really need to
> assume that newcomers are so clueless that they need it spelled out to
> such a level of detail? "Launched editor" should be enough for most
> people, and one would hope that "Launched editor; waiting for
> input..." would be enough for the rest.
> 
> * Does not take into consideration that EDITOR might be very long;
> perhaps you could just print the basename and strip arguments (i.e.
> "/my/long/path/edit -x --foo --zap" becomes "edit"). Or, just omit the
> editor altogether.

Agreed already in another reply here:
https://public-inbox.org/git/0dd1ee8a-47f1-41aa-8f86-c9fdf99d2...@gmail.com/

> 
> * emacsclient already prints its own message ("Waiting for Emacs...",
> which runs together with Git's message). Perhaps treat emacsclient as
> a special case and skip printing this message if emacsclient is in
> use: if (strstr(...,"emacsclient"))

If Junio et al. are ok with the special handling of emacs, then I am happy 
to add this change in v3. If we look for "emacsclient", then would this 
cover emacs on Linux and Windows, too? (I am no emacs user)


> 
> And, of course, with a "dumb" terminal, it's even noisier with the
> extra "done." at the end:
> 
> --- 8< ---
> Launched your editor
> ('/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'). Adjust,
> save, and close the file to continue. Waiting for your input...
> Waiting for Emacs...
> done.
> --- 8< ---
> 
> As Junio pointed out in [1], emacsclient has already emitted a
> newline, so the clear-line sequence is ineffective; likewise, for a
> dumb terminal, "done." ends up on its own line. Aside from the noise,
> this also suggests making a special case for emacsclient.
> 
> And, as Junio pointed out in [2], with a message so long, once it has
> wrapped, the clear-line sequence does not work as intended. For those
> of us with 80-column terminals, we're left with a bunch of noise on
> the screen.
> 
>> +   fflush(stderr);
>> +   }
>> 
>>p.argv = args;
>>p.env = env;
>> @@ -53,11 +79,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);
> 
> Should printing of close_notice be done before the error()? Otherwise,
> you get this:
> 
> --- 8< ---
> Launched your editor (...) ...There was a problem...
> --- 8< ---

I think we should keep it as I agree with Junio's argument here:
https://public-inbox.org/git/xmqqh8tsqs83@gitster.mtv.corp.google.com/

- Lars

Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-22 Thread Lars Schneider

> On 17 Nov 2017, at 19:40, Junio C Hamano  wrote:
> 
> lars.schnei...@autodesk.com writes:
> 
>> Junio posted the original version of this patch [1] as response to my RFC 
>> [2].
>> I took Junio's patch and slightly changed the commit message as well as the
>> message printed to the user after GIT_EDITOR is invoked [3].
>> 
>> Thanks,
>> Lars
> 
> Thanks.
> 
>> diff --git a/editor.c b/editor.c
>> index 7519edecdc..23db92d8c6 100644
>> --- a/editor.c
>> +++ b/editor.c
>> @@ -40,6 +40,32 @@ int launch_editor(const char *path, struct strbuf...
>> ...
>> +if (close_notice) {
>> +fprintf(
>> +stderr,
>> +"Launched your editor ('%s'). Adjust, save, and 
>> close the "
>> +"file to continue. Waiting for your input... ", 
>> editor
> 
> How wide is your typical terminal window?  With message this long, a
> sample standalone program I used while developing the prototype of
> this feature no longer can retract this "temporary" message.
> 
> Would something shorter like "Waiting for you to finish editing..."
> work well enough?

Yeah, Eric criticized the verbosity elsewhere, too. I understand your point
of view. Let's revert it to your initial short version. 

- Lars

> 
> -- -- --
> #include 
> 
> int main(void)
> {
>   const char *EL = "\033[K"; /* Erase in Line */
>   const char *editor = "emacsclient";
> 
>   fprintf(
>   stderr,
>   "Launched your editor ('%s'). Adjust, save, and close the "
>   "file to continue. Waiting for your input... ", editor);
>   fflush(stderr);
>   sleep(2);
>   fprintf(stderr, "\r%s", EL);
>   fflush(stderr);
>   return 0;
> }
> -- -- --
> 



Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-19 Thread Junio C Hamano
Kaartic Sivaraam  writes:

>>> However, it's not clear how much benefit you gain from stashing this
>>> away in a static variable. Premature optimization?
>>
>> The variable being "static" could be (but it was done primarily
>> because it allowed me not to worry about freeing),

The current code happens to be safe because I do not allocate.  I do
not know what others will do to the code in the future, and at that
point, instinct kicks in to futureproof against the worst ;-).

>>> Should printing of close_notice be done before the error()? Otherwise,
>>> you get this:
>>>
>>> --- 8< ---
>>> Launched your editor (...) ...There was a problem...
>>> --- 8< ---
>>
>> In my version with a far shorter message, I deliberately chose not
>> to clear the notice.  We ran the editor, and we saw a problem.  That
>> is what happened and that is what will be left on the terminal.
>>
>
> It might be a good thing to keep the notice but I think it would be
> better to have that error message in a "new line". I'm not sure if
> it's possible or not.

Of course it is possible, if you really wanted to.  The code knows
if it gave the "we launched and waiting for you" notice, so it can
maintain not just one (i.e. "how I close the notice?") but another
one (i.e. "how I do so upon an error?") and use it in the error
codepath.



Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-19 Thread Kaartic Sivaraam

On Saturday 18 November 2017 07:10 AM, Junio C Hamano wrote:

Eric Sunshine  writes:


@@ -40,6 +40,32 @@ int launch_editor(const char *path, struct strbuf *buffer, 
const char *const *en
+   static const char *close_notice = NULL;
+
+   if (isatty(2) && !close_notice) {


If you reverse this condition to say (!close_notice && isatty(2)),
then you save an isatty() invocation each time if close_notice is
already assigned.

However, it's not clear how much benefit you gain from stashing this
away in a static variable. Premature optimization?


The variable being "static" could be (but it was done primarily
because it allowed me not to worry about freeing),


AFAIK, observing the way the variable 'close_notice' is used, I guess 
you don't need to worry about freeing it up even if it wasn't "static".

That's my interpretation of the following section of the C standard,


6.5.2.5 Compound literals

...

9 EXAMPLE 2
In contrast, in
void f(void)
{
int *p;
/*...*/
p = (int [2]){*p};
/*...*/
}
p is assigned the address of the first element of an array of two ints, 
the first having the value previously pointed to by p and the second, 
zero. The expressions in this compound literal need not be constant. The

unnamed object has automatic storage duration.
=

So the unnamed objects created as a consequence of the string literals 
assigned to 'close_notice' should have "automatic" storage duration 
which means you don't have to worry about allocating memory for them 
which would make you worry about freeing it up. If I'm stating something 
wrong, let me know.


BTW, I find making the variable 'close_notice' to be 'static' unwanted 
as I couldn't find any piece of code that invokes 'launch_editor' more 
than once within a single run. What could be the possible cases in which 
'launch_editor' could be called twice ?




Should printing of close_notice be done before the error()? Otherwise,
you get this:

--- 8< ---
Launched your editor (...) ...There was a problem...
--- 8< ---


In my version with a far shorter message, I deliberately chose not
to clear the notice.  We ran the editor, and we saw a problem.  That
is what happened and that is what will be left on the terminal.



It might be a good thing to keep the notice but I think it would be 
better to have that error message in a "new line". I'm not sure if it's 
possible or not.



---
Kaartic


Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-17 Thread Junio C Hamano
Eric Sunshine  writes:

>> @@ -40,6 +40,32 @@ int launch_editor(const char *path, struct strbuf 
>> *buffer, const char *const *en
>> +   static const char *close_notice = NULL;
>> +
>> +   if (isatty(2) && !close_notice) {
>
> If you reverse this condition to say (!close_notice && isatty(2)),
> then you save an isatty() invocation each time if close_notice is
> already assigned.
>
> However, it's not clear how much benefit you gain from stashing this
> away in a static variable. Premature optimization?

The variable being "static" could be (but it was done primarily
because it allowed me not to worry about freeing), but during a
single invocation, it primarily is used as a flag "are we showing
the editor invocation notice?" two places in the function can use
without having to do the same checks twice.

If we want this as an optimization "we've already checked the
condition in our previous call, so let's use the result without
checking again", then this has to become tristate:

 - We haven't checked, and needs checking (probably NULL);

 - We have checked, and we know we want to show the notice---here is
   a string to use when we clear the notice (what we have here);

 - We have checked, and we know we do not want to show the notice
   (there is no provision for this in the posted code---that makes
   this not an optimization yet).

Perhaps an empty string can be used for the last one, but if/when it
is done, the above needs to go in a comment near the definition of
the variable.

> Should printing of close_notice be done before the error()? Otherwise,
> you get this:
>
> --- 8< ---
> Launched your editor (...) ...There was a problem...
> --- 8< ---

In my version with a far shorter message, I deliberately chose not
to clear the notice.  We ran the editor, and we saw a problem.  That
is what happened and that is what will be left on the terminal.

I agree that the verbose message Lars substituted makes it harder to
read.


Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-17 Thread Eric Sunshine
On Fri, Nov 17, 2017 at 8:51 AM,   wrote:
> When a graphical GIT_EDITOR is spawned by a Git command that opens
> and waits for user input (e.g. "git rebase -i"), then the editor window
> might be obscured by other windows. The user may be left staring at the
> original Git terminal window without even realizing that s/he needs to
> interact with another window before Git can proceed. To this user Git
> appears hanging.
>
> Show a message in the original terminal and get rid of it when the
> editor returns.
>
> Signed-off-by: Junio C Hamano 
> Signed-off-by: Lars Schneider 
> ---
> diff --git a/editor.c b/editor.c
> @@ -40,6 +40,32 @@ int launch_editor(const char *path, struct strbuf *buffer, 
> const char *const *en
> +   static const char *close_notice = NULL;
> +
> +   if (isatty(2) && !close_notice) {

If you reverse this condition to say (!close_notice && isatty(2)),
then you save an isatty() invocation each time if close_notice is
already assigned.

However, it's not clear how much benefit you gain from stashing this
away in a static variable. Premature optimization?

> +   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 ('%s'). Adjust, save, 
> and close the "
> +   "file to continue. Waiting for your input... 
> ", editor
> +   );

Here's what this looks like for me:

--- 8< ---
Launched your editor
('/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'). Adjust,
save, and close the file to continue. Waiting for your input...
Waiting for Emacs...
--- 8< ---

Very, very noisy, so much so that it's almost unreadable. There are at
least three reasons for the noise:

* The raw message itself is already overly long. Do we really need to
assume that newcomers are so clueless that they need it spelled out to
such a level of detail? "Launched editor" should be enough for most
people, and one would hope that "Launched editor; waiting for
input..." would be enough for the rest.

* Does not take into consideration that EDITOR might be very long;
perhaps you could just print the basename and strip arguments (i.e.
"/my/long/path/edit -x --foo --zap" becomes "edit"). Or, just omit the
editor altogether.

* emacsclient already prints its own message ("Waiting for Emacs...",
which runs together with Git's message). Perhaps treat emacsclient as
a special case and skip printing this message if emacsclient is in
use: if (strstr(...,"emacsclient"))

And, of course, with a "dumb" terminal, it's even noisier with the
extra "done." at the end:

--- 8< ---
Launched your editor
('/Applications/Emacs.app/Contents/MacOS/bin/emacsclient'). Adjust,
save, and close the file to continue. Waiting for your input...
Waiting for Emacs...
done.
--- 8< ---

As Junio pointed out in [1], emacsclient has already emitted a
newline, so the clear-line sequence is ineffective; likewise, for a
dumb terminal, "done." ends up on its own line. Aside from the noise,
this also suggests making a special case for emacsclient.

And, as Junio pointed out in [2], with a message so long, once it has
wrapped, the clear-line sequence does not work as intended. For those
of us with 80-column terminals, we're left with a bunch of noise on
the screen.

> +   fflush(stderr);
> +   }
>
> p.argv = args;
> p.env = env;
> @@ -53,11 +79,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);

Should printing of close_notice be done before the error()? Otherwise,
you get this:

--- 8< ---
Launched your editor (...) ...There was a problem...
--- 8< ---

> }

[1]: https://public-inbox.org/git/xmqqr2syvjxb...

Re: [PATCH v2] launch_editor(): indicate that Git waits for user input

2017-11-17 Thread Junio C Hamano
lars.schnei...@autodesk.com writes:

> Junio posted the original version of this patch [1] as response to my RFC [2].
> I took Junio's patch and slightly changed the commit message as well as the
> message printed to the user after GIT_EDITOR is invoked [3].
>
> Thanks,
> Lars

Thanks.

> diff --git a/editor.c b/editor.c
> index 7519edecdc..23db92d8c6 100644
> --- a/editor.c
> +++ b/editor.c
> @@ -40,6 +40,32 @@ int launch_editor(const char *path, struct strbuf...
> ...
> + if (close_notice) {
> + fprintf(
> + stderr,
> + "Launched your editor ('%s'). Adjust, save, and 
> close the "
> + "file to continue. Waiting for your input... ", 
> editor

How wide is your typical terminal window?  With message this long, a
sample standalone program I used while developing the prototype of
this feature no longer can retract this "temporary" message.

Would something shorter like "Waiting for you to finish editing..."
work well enough?

-- -- --
#include 

int main(void)
{
const char *EL = "\033[K"; /* Erase in Line */
const char *editor = "emacsclient";

fprintf(
stderr,
"Launched your editor ('%s'). Adjust, save, and close the "
"file to continue. Waiting for your input... ", editor);
fflush(stderr);
sleep(2);
fprintf(stderr, "\r%s", EL);
fflush(stderr);
return 0;
}
-- -- --