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

Re: [PATCH v2 4/4] allow recovery from command name typos

From
Jeff King <peff@peff.net>
Date
Jul 26, 2012, 18:37 UTC
Message-ID
<20120726183734.GA16037@sigill.intra.peff.net>
In-Reply-To
<7vy5m67694.fsf@alter.siamese.dyndns.org>
On Thu, Jul 26, 2012 at 10:59:51AM -0700, Junio C Hamano wrote:
Show 9 quoted lines
> > The credential code uses git_terminal_prompt, which actually opens
> > /dev/tty directly. So it is probably sane to use for your new prompt,
> > but it does not (and should not) rely on isatty.
> 
> I think using git_terminal_prompt() after doing a looser "does the
> user sit at a terminal and is capable of answering interactive
> prompt" check with isatty(2) is OK, as long as we know that all
> implementations of git_terminal_prompt() never read from whatever
> happens to be connected to the standard input.

I don't think isatty(2) is correct, though. It would yield false negatives when the user has redirected stderr but /dev/tty is still available. I don't know if it possible for getpass to fallback to stdin when stderr is a tty (it would mean that opening /dev/tty failed, which would mean that we have no controlling terminal _but_ our stderr is still connected to some terminal. That might be bizarre enough not to care about).

I think the right answer would be a real is_prompt_available() that checked /dev/tty when HAVE_DEV_TTY was set, and otherwise checked isatty(2) (or whatever was appropriate for the platform).

> The function falls back to getpass() on platforms without DEV_TTY,
> and if getpass() on some platforms reads from the standard input,
> that would be a disaster.  I wasn't sure about that part.

Yeah, although it is already a disaster in those cases, as the main caller of git_terminal_prompt is remote-curl, whose stdin is connected to git via the remote-helper protocol. Which isn't to say this wouldn't make things worse. It would, but the real solution is to implement a sane git_terminal_prompt for those platforms. Erik had a patch for Windows to use their magical CONIN$, but I think it is temporarily stalled. I don't know if there are any other platforms that do not have /dev/tty (I know we do not set HAVE_DEV_TTY by default, but that is only because I was being conservative and waiting for people on particular platforms to confirm that it works before tweaking our Makefile defaults).

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 25 of 37 in “allow recovery from command name typos”
  1. 0/4 allow recovery from command name typosTay Ray Chuan, May 6, 2012
  2. 1/4 help.c::uniq: plug a leakTay Ray Chuan, May 6, 2012
  3. 2/4 help.c::exclude_cmds: plug a leakTay Ray Chuan, May 6, 2012
  4. 3/4 help.c: plug a leak when help.autocorrect is setTay Ray Chuan, May 6, 2012
  5. 4/4 allow recovery from command name typosTay Ray Chuan, May 6, 2012
  6. Jeff KingMay 6, 2012
  7. Tay Ray ChuanMay 6, 2012
  8. Thomas RastMay 7, 2012
  9. Tay Ray ChuanMay 7, 2012
  10. Junio C HamanoMay 7, 2012
  11. Tay Ray ChuanMay 9, 2012
  12. Junio C HamanoMay 9, 2012
  13. Jeff KingMay 6, 2012
  14. Tay Ray ChuanMay 6, 2012
  15. Jeff KingMay 7, 2012
  16. 0/4 allow recovery from command name typosTay Ray Chuan, Jul 25, 2012
  17. 1/4 help.c::uniq: plug a leakTay Ray Chuan, Jul 25, 2012
  18. 2/4 help.c::exclude_cmds: realloc() before copy, plug a leakTay Ray Chuan, Jul 25, 2012
  19. 3/4 help.c: plug leaks with(out) help.autocorrectTay Ray Chuan, Jul 25, 2012
  20. 4/4 allow recovery from command name typosTay Ray Chuan, Jul 25, 2012
  21. Junio C HamanoJul 25, 2012
  22. Tay Ray ChuanJul 26, 2012
  23. Jeff KingJul 26, 2012
  24. Junio C HamanoJul 26, 2012
  25. Jeff KingJul 26, 2012
  26. Junio C HamanoJul 26, 2012
  27. Junio C HamanoJul 25, 2012
  28. Junio C HamanoJul 25, 2012
  29. 0/2 allow recovery from command name typosTay Ray Chuan, Aug 5, 2012
  30. 1/2 add interface for /dev/tty interactionTay Ray Chuan, Aug 5, 2012
  31. 2/2 allow recovery from command name typosTay Ray Chuan, Aug 5, 2012
  32. Junio C HamanoAug 6, 2012
  33. Junio C HamanoAug 5, 2012
  34. Jeff KingAug 6, 2012
  35. Jeff KingAug 6, 2012
  36. Junio C HamanoAug 6, 2012
  37. Tay Ray ChuanMay 6, 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.