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

Re: [PATCH 1/2] prompt.h: clarify the non-use of git_prompt

From
Junio C Hamano <gitster@pobox.com>
Date
May 13, 2021, 23:03 UTC
Message-ID
<xmqqmtsy8cdt.fsf@gitster.g>
In-Reply-To
<xmqqv97m8dnw.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 16 quoted lines
> I have a strong objection against the above phrasing.
>
> If we are asking user for interactive input, this SHOULD be used,
> especially if we might be reading the data to work on from the
> standard input and we may need to ask the user to interactively
> instruct us what to do to that data.  The only plausible reason that
> we may want to avoid it and instead prefer the (misnamed)
> read_line_interactively() to read whatever from the standard input
> (which may not be "interactive" at all, which is why I said
> "misnamed") is because our test framework does not use setsid (and
> setsid(1) may not be universally available) with pty to emulate tty
> input, isn't it?
>
>>  char *git_prompt(const char *prompt, int flags);
>>  
>>  int git_read_line_interactively(struct strbuf *line);

So, here is an alternative that nudges users away from this helper, but with honesty. I also suggest a better name for that misnamed "interactively" function in the comment, but will leave it as an exercise to readers to come up with a patch to rename the function.

/*
 * Give prompt to the user and accept interactive input from the
 * controlling terminal (/dev/tty).  This function can be used even
 * when the standard input is being used to feed us real data to
 * operate on, as we open /dev/tty ourselves for user interaction.
 *
 * In a codepath that never uses the standard input for real data,
 * consider using git_read_line_from_standard_input() instead, as it
 * is easier to write tests for (our test framework currently does not
 * make it easy to simulate end-user input coming from /dev/tty).
 */
Previous: Junio C HamanoNext: Jeff King
Message 4 of 7 in “Refactor some prompts”
  1. 0/2 Refactor some promptsFirmin Martin, May 13, 2021
  2. 1/2 prompt.h: clarify the non-use of git_promptFirmin Martin, May 13, 2021
  3. Junio C HamanoMay 13, 2021
  4. Junio C HamanoMay 13, 2021
  5. Jeff KingMay 15, 2021
  6. 2/2 builtin: use git_read_line_interactively to promptFirmin Martin, May 13, 2021
  7. Junio C HamanoMay 13, 2021

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.