git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] merge: use editor by default in interactive sessions

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 23, 2012, 19:23 UTC
Message-ID
<7vd3954ame.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CABPQNSZVOjOKpqv4s1ZCEQRd_yT3us3mqC9aN-KK5PHqztYQQg@mail.gmail.com>
Erik Faye-Lund <kusmabite@gmail.com> writes:
Show 14 quoted lines
>> +       /* Use editor if stdin and stdout are the same and is a tty */
>> +       return (!fstat(0, &st_stdin) &&
>> +               !fstat(1, &st_stdout) &&
>> +               isatty(0) &&
>> +               st_stdin.st_dev == st_stdout.st_dev &&
>> +               st_stdin.st_ino == st_stdout.st_ino &&
>> +               st_stdin.st_mode == st_stdout.st_mode);
>
> I just stumbled over this code, and I got a bit worried; the
> stat-implementation we use on Windows sets st_ino to 0, so
> "st_stdin.st_ino == st_stdout.st_ino" will always evaluate to true.
>
> Perhaps we should add a check for isatty(1) here as well? ...
> Or is there something I'm missing here?

No, the intention was not "we do this whether standard output is tty or not", but was "we check that fd#0 and fd#1 are connected to the same device by trusting stat() to do the right thing, so checking isatty(0) is sufficient". As that "trusting stat()" assumption does not hold for your platform, we would need to add isatty(1) to accomodate it.

Thanks for a set of sharp eyes.
Previous: Erik Faye-LundNext: Junio C Hamano
Message 12 of 14 in “merge: use editor by default in interactive sessions”
  1. merge: use editor by default in interactive sessionsJunio C Hamano, Jan 23, 2012
  2. Michael HaggertyJan 23, 2012
  3. Junio C HamanoJan 23, 2012
  4. Thomas RastJan 30, 2012
  5. Junio C HamanoJan 30, 2012
  6. merge: add instructions to the commit message when editingThomas Rast, Jan 30, 2012
  7. Junio C HamanoJan 30, 2012
  8. Thomas RastJan 30, 2012
  9. Junio C HamanoJan 30, 2012
  10. Thomas RastJan 31, 2012
  11. Erik Faye-LundFeb 23, 2012
  12. Junio C HamanoFeb 23, 2012
  13. Junio C HamanoFeb 23, 2012
  14. Erik Faye-LundFeb 23, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.