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

[PATCH 3/3] add -p: disable stdin buffering when interactive.singlekey is set

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 16, 2022, 10:54 UTC
Message-ID
<6d8423b6e1e969ffed02b148546b88d118affd09.1645008873.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1146.git.1645008873.gitgitgadget@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

The builtin "add -p" reads the key "F2" as three separate keys "^[", "O" and "Q". The "Q" causes it to quit which is probably not what the user was expecting. This is because it uses poll() to check for pending input when reading escape sequences but reads the input with getchar() which is buffered by default and so hoovers up all the pending input leading poll() think there isn't anything pending. Fix this by calling setbuf() to disable input buffering if interactive.singlekey is set.

Looking at the comment above mingw_getchar() in terminal.c I wonder if that function is papering over this bug and could be removed. Unfortunately I don't have access to windows to test that.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 add-interactive.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/add-interactive.c b/add-interactive.c
index 6498ae196f1..ad78774ca26 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -70,6 +70,8 @@ void init_add_i_state(struct add_i_state *s, struct repository *r)
 			      &s->interactive_diff_algorithm);
 
 	git_config_get_bool("interactive.singlekey", &s->use_single_key);
+	if (s->use_single_key)
+		setbuf(stdin, NULL);
 }
 
 void clear_add_i_state(struct add_i_state *s)
-- 
gitgitgadget
Previous: Phillip WoodNext: Junio C Hamano
Message 6 of 18 in “a couple of read_key_without_echo() fixes”
  1. 0/3 a couple of read_key_without_echo() fixesPhillip Wood via GitGitGadget, Feb 16, 2022
  2. 1/3 terminal: pop signal handler when terminal is restoredPhillip Wood via GitGitGadget, Feb 16, 2022
  3. 2/3 terminal: set VMIN and VTIME in non-canonical modePhillip Wood via GitGitGadget, Feb 16, 2022
  4. Junio C HamanoFeb 16, 2022
  5. Phillip WoodFeb 17, 2022
  6. 3/3 add -p: disable stdin buffering when interactive.singlekey is setPhillip Wood via GitGitGadget, Feb 16, 2022
  7. Junio C HamanoFeb 16, 2022
  8. 0/4 a couple of read_key_without_echo() fixesPhillip Wood via GitGitGadget, Feb 22, 2022
  9. 1/4 terminal: always reset terminal when reading without echoPhillip Wood via GitGitGadget, Feb 22, 2022
  10. 2/4 terminal: pop signal handler when terminal is restoredPhillip Wood via GitGitGadget, Feb 22, 2022
  11. 3/4 terminal: set VMIN and VTIME in non-canonical modePhillip Wood via GitGitGadget, Feb 22, 2022
  12. 4/4 add -p: disable stdin buffering when interactive.singlekey is setPhillip Wood via GitGitGadget, Feb 22, 2022
  13. Junio C HamanoFeb 23, 2022
  14. Phillip WoodFeb 24, 2022
  15. Carlo ArenasMar 22, 2022
  16. Junio C HamanoMar 23, 2022
  17. Johannes SchindelinMar 24, 2022
  18. Phillip WoodMar 28, 2022

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.