From patchwork Tue Feb 22 18:53:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12755828 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94C1AC433F5 for ; Tue, 22 Feb 2022 18:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235099AbiBVSyG (ORCPT ); Tue, 22 Feb 2022 13:54:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233008AbiBVSyE (ORCPT ); Tue, 22 Feb 2022 13:54:04 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB5EF11477A for ; Tue, 22 Feb 2022 10:53:38 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id l123-20020a1c2581000000b0037b9d960079so2706899wml.0 for ; Tue, 22 Feb 2022 10:53:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qHuemM/PFisCj8yqpuSjuckS/yudqWVqBqBZ+hi0ISM=; b=QFSJyLFaQjaRaxbPubax7K528SKUF+tQFiOzSm5j2VtNBC0C7Nu4CZS6WfjbAA0Sno fLnqNpKu4C0wTyDzPu1OsgpL4dXHt2pePFUOqPjpz6c5X8rimVPWnvzSuQvxRh0Qxtqy DTdDtqZO6YhAolVnDeemqDaxb2MtqzFDeRVAELpdYmn9+8r/o3LqP61cZPfBsVq4YkLm Dd6iP6nnFvgFux1lua0xJFpKkFViLiaPJPChr2/VU0zSBdq7QLE6c7U4+Y1s9Isdkwho ajnRe0S1NS6fykqhyRk4mko8Ch5Dz5a1V2iEze1naZBiUZ/Ztdo+WWybGW25uTymqJ6q kuZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qHuemM/PFisCj8yqpuSjuckS/yudqWVqBqBZ+hi0ISM=; b=qvQTwhc2Fan8hOEM9yFB16PzTGrygVLa4U1dJZrlC5gW0/gaKtNo6RMqUbn/N2T6B0 bmRDeCOwBeeV/8ii624vHUI65WxGeJ7nbGPO0ou1kMmr3VlHpC/HK0TCCKpdimEiInMQ jGey3YKMoGduEr9oxijYUf2ghMY5l2QBd5xhaw18YJFdbWirN9CWiaQPspfD6WF7OYbd Ygp8sxE15I5U2jB+Um+m6YVTk2Bc0YS9x3kXZPlPkmTb1v7UxfSXtXcpxb7H4l9+EF7U sV7xE6Lt5VDCd+G0TolDkhdxDPfZNfd0o5kVS5Duzr9d3IL32knjTknr3OgbwwybLKbD n76A== X-Gm-Message-State: AOAM532fXd2teJWmsiYa6auh0fzRG3ccixUpiHT8mqoYi5YKiScXR4/P eaSdRGD7ENEvjkjj8FOcs0GeU0PAwbU= X-Google-Smtp-Source: ABdhPJxokXC8JAmhRaHfaqYBslWc9CHyA0HweVXnIUKGAOZF5ajr48Q7Ba7+w6TE+VL1ZYjwZ7hOAQ== X-Received: by 2002:a05:600c:25a:b0:380:55e:fa39 with SMTP id 26-20020a05600c025a00b00380055efa39mr4483683wmj.40.1645556017138; Tue, 22 Feb 2022 10:53:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v3sm1815274wrv.114.2022.02.22.10.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 10:53:36 -0800 (PST) Message-Id: <45609d61afc647de3afafc4203d904676837ffe3.1645556015.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 22 Feb 2022 18:53:32 +0000 Subject: [PATCH v2 1/4] terminal: always reset terminal when reading without echo Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Carlo Marcelo Arenas =?utf-8?b?QmVsw7Nu?= , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Break out of the loop to ensure restore_term() is called before returning. Signed-off-by: Phillip Wood --- compat/terminal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/terminal.c b/compat/terminal.c index 5b903e7c7e3..fb8c70a6251 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -385,7 +385,7 @@ int read_key_without_echo(struct strbuf *buf) ch = getchar(); if (ch == EOF) - return 0; + break; strbuf_addch(buf, ch); } } From patchwork Tue Feb 22 18:53:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12755829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 690B4C433FE for ; Tue, 22 Feb 2022 18:53:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235104AbiBVSyI (ORCPT ); Tue, 22 Feb 2022 13:54:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiBVSyF (ORCPT ); Tue, 22 Feb 2022 13:54:05 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75DAD114FC9 for ; Tue, 22 Feb 2022 10:53:39 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id d28so7448978wra.4 for ; Tue, 22 Feb 2022 10:53:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=6c5ZkTaOY71A45Zr8zmD1XsOpyurqbzl+JMQ1ZJgy6s=; b=Qu5MH3Co4jZCcdYD0bTwLKqYCFLW8zCuxmm+GnGVC0Oo6MpXzv/v2AFcSmfkzhkTOj PS2s9zP+r+I4aBff7TqYRSVnNfSYr534VrYBZ6QVry5yGqIr//5Qvf3M+4g/CMksfStG RuSj4v2JcAtj5UL/7zjleUpYVPSo30CWg+oVK/bN4XFbVSj5cgPunZGWOCjYcuFXUTaK qS3FoK2O0ImVQQzKGay2lYwZRFnCSmkdNxwkiYBsntZ0v40JTd6Fn+++PrHj24LK2HoR i2q4XvXVIqbpEQX6+XEdY4AvqukinGJExR3wKvE3mzyPG6/yAg1lsimPEHE1Puw7M7m7 IP+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=6c5ZkTaOY71A45Zr8zmD1XsOpyurqbzl+JMQ1ZJgy6s=; b=6F3nmiP5lA1eNMa3lBMfR76RVLsTeRXBcI1MT0vGzilnDqsyn2yXHBLk/cp0LLpqzi vlzm+ekFc46G21V47e1bt5+jDscFG9MnoN9CIZxn2j6QG2s9rBsxPngfVbCFEWb6HXOh duYSFnNTe00o/BYStb1adBmg8G9VH0ub+IdUjKlvVPgZISF1VmOAK0gCF0xY0L62PLSK MhQ3/YdAdQqpmitoSkLpHsD0UqX09ItpyjBhwOzOyENcduifwqUh5c9XyHSnvOQpZ+ld xmm+wHm87IXhcS4CjnIGMA+rUmH2QwvfFZJnyTcY0tizo2vv2O6oVLK+WywlPpwdXQBk hcCw== X-Gm-Message-State: AOAM533bJbzp9A+VhtRrNelibhY1wRyVq2sGRRWk6UDgedg9AXiokGR2 a1BbHACDQsL/7L6U//Yiw9x/MMMp63g= X-Google-Smtp-Source: ABdhPJwzl9ObA1WRzakx7YoPtRbJUEKMUlCu/aIvDYzd8ACBSzb94qDgJhtxCBawYkuPQwIKCQNSBQ== X-Received: by 2002:adf:ea4f:0:b0:1e7:447d:2111 with SMTP id j15-20020adfea4f000000b001e7447d2111mr20749323wrn.66.1645556017913; Tue, 22 Feb 2022 10:53:37 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w18sm36580859wrl.62.2022.02.22.10.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 10:53:37 -0800 (PST) Message-Id: <0020953f1cf901e66883853392915ba8ce07ca61.1645556015.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 22 Feb 2022 18:53:33 +0000 Subject: [PATCH v2 2/4] terminal: pop signal handler when terminal is restored Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Carlo Marcelo Arenas =?utf-8?b?QmVsw7Nu?= , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood When disable_bits() changes the terminal attributes it uses sigchain_push_common() to restore the terminal if a signal is received before restore_term() is called. However there is no corresponding call to sigchain_pop_common() when the settings are restored so the signal handler is left on the sigchain stack. This leaves the stack unbalanced so code such as sigchain_push_common(my_handler); ... read_key_without_echo(...); ... sigchain_pop_common(); pops the handler pushed by disable_bits() rather than the one it intended to. Additionally "git add -p" changes the terminal settings every time it reads a key press so the stack can grow significantly. In order to fix this save_term() now sets up the signal handler so restore_term() can unconditionally call sigchain_pop_common(). There are no callers of save_term() outside of terminal.c as the only external caller was removed by e3f7e01b50 ("Revert "editor: save and reset terminal after calling EDITOR"", 2021-11-22). Any future callers of save_term() should benefit from having the signal handler set up for them. Signed-off-by: Phillip Wood --- compat/terminal.c | 17 +++++++++++++---- compat/terminal.h | 8 ++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/compat/terminal.c b/compat/terminal.c index fb8c70a6251..11288cfe5c9 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -11,7 +11,7 @@ static void restore_term_on_signal(int sig) { restore_term(); - sigchain_pop(sig); + /* restore_term calls sigchain_pop_common */ raise(sig); } @@ -31,14 +31,20 @@ void restore_term(void) tcsetattr(term_fd, TCSAFLUSH, &old_term); close(term_fd); term_fd = -1; + sigchain_pop_common(); } int save_term(int full_duplex) { if (term_fd < 0) term_fd = open("/dev/tty", O_RDWR); + if (term_fd < 0) + return -1; + if (tcgetattr(term_fd, &old_term) < 0) + return -1; + sigchain_push_common(restore_term_on_signal); - return (term_fd < 0) ? -1 : tcgetattr(term_fd, &old_term); + return 0; } static int disable_bits(tcflag_t bits) @@ -49,12 +55,12 @@ static int disable_bits(tcflag_t bits) goto error; t = old_term; - sigchain_push_common(restore_term_on_signal); t.c_lflag &= ~bits; if (!tcsetattr(term_fd, TCSAFLUSH, &t)) return 0; + sigchain_pop_common(); error: close(term_fd); term_fd = -1; @@ -100,6 +106,8 @@ void restore_term(void) return; } + sigchain_pop_common(); + if (hconin == INVALID_HANDLE_VALUE) return; @@ -134,6 +142,7 @@ int save_term(int full_duplex) GetConsoleMode(hconin, &cmode_in); use_stty = 0; + sigchain_push_common(restore_term_on_signal); return 0; error: CloseHandle(hconin); @@ -177,10 +186,10 @@ static int disable_bits(DWORD bits) if (save_term(0) < 0) return -1; - sigchain_push_common(restore_term_on_signal); if (!SetConsoleMode(hconin, cmode_in & ~bits)) { CloseHandle(hconin); hconin = INVALID_HANDLE_VALUE; + sigchain_pop_common(); return -1; } diff --git a/compat/terminal.h b/compat/terminal.h index e1770c575b2..0fb9fa147c4 100644 --- a/compat/terminal.h +++ b/compat/terminal.h @@ -1,7 +1,15 @@ #ifndef COMPAT_TERMINAL_H #define COMPAT_TERMINAL_H +/* + * Save the terminal attributes so they can be restored later by a + * call to restore_term(). Note that every successful call to + * save_term() must be matched by a call to restore_term() even if the + * attributes have not been changed. Returns 0 on success, -1 on + * failure. + */ int save_term(int full_duplex); +/* Restore the terminal attributes that were saved with save_term() */ void restore_term(void); char *git_terminal_prompt(const char *prompt, int echo); From patchwork Tue Feb 22 18:53:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12755830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9329CC433EF for ; Tue, 22 Feb 2022 18:53:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229747AbiBVSyM (ORCPT ); Tue, 22 Feb 2022 13:54:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233999AbiBVSyF (ORCPT ); Tue, 22 Feb 2022 13:54:05 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27D3611475E for ; Tue, 22 Feb 2022 10:53:40 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id x3-20020a05600c21c300b0037c01ad715bso2567253wmj.2 for ; Tue, 22 Feb 2022 10:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=RWt+ewUhKb4KlpjppHFVMNRVqK33c9kyxe9170BIAvI=; b=exNVIkL99Ee1DCK8v8GQ4V6GufBQsFG4xwcW3sdiV1huLe3IXRPe1NwBA0kfe2p5Lx uay9PD32LbUXPlhfGBRtCTICKZg5QFZ+iut82Bza1PBgMQqg+p62wat8h5tYW1A3jmK2 II1l9BQADTDWdjLbK13PgrigmxFXTkDQ/M9Rd/2oGR1vMUx8ZDkOcZV9R9zsqFPNyyGt KFBcVkv5b/9bgEjzpbaSIrBpRwLa2LgIuTG5xU9izym2YSdZXVgRWsFa5wcC31KM/b9c BHVxRhPvgnpnJz43L7wuaUHIhRkVn0U6iHMCyZasVbxAG05QjnXhoLlI2pT+oaVhpdT6 62wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=RWt+ewUhKb4KlpjppHFVMNRVqK33c9kyxe9170BIAvI=; b=0tp+rZt3N1SXEfWcN85rFEK9LA3SuLPzJc1wVtJRjjgFxb1+Z0U28n6LBYfJhqdHL3 o1Wgj1zWXq0S3aBL7z6j/YrURjDZ2kEOjVTuD04SxGrCJCeON1eF+JRteTInRnUfX7D4 PaM4xLi+kdJqKFbyafIolHfhgikPmfgPlV1B6BdhSQ32gynSgNimgvp2wgu5QOPrTA4I CPc5y0tsXs6Y9VH1+6xr4QHVLupJ4g5YByAulb0vn6W+S/pzEaIxaN6zCD3NCm0rz83z 9XpkJrT4SxnJ8cHg0zvh322il5aKBN5Nx7EiVvKE+wucFE54GtkBUH5mAkeVpyn5kldF eVMg== X-Gm-Message-State: AOAM533nV833cv99TS8AmFRpQeccrTq8lTe3PtOiYa2V9YWBTB60Mc2l qGjh/mrU+yfe+Hdh2yOephg7nJ1vKcg= X-Google-Smtp-Source: ABdhPJwcFvv4X+CmRjMTn3RIf0nJnoZdhNnTIBw67A9FDBIcjJTc4XHbybWVqDsArvznbpxqml4Y6A== X-Received: by 2002:a7b:c5d0:0:b0:355:482a:6f44 with SMTP id n16-20020a7bc5d0000000b00355482a6f44mr4380198wmk.58.1645556018632; Tue, 22 Feb 2022 10:53:38 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ba14sm32110268wrb.56.2022.02.22.10.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 10:53:38 -0800 (PST) Message-Id: <7ae9b2365542b68d7d75f39b126d2acec3e223ff.1645556015.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 22 Feb 2022 18:53:34 +0000 Subject: [PATCH v2 3/4] terminal: set VMIN and VTIME in non-canonical mode Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Carlo Marcelo Arenas =?utf-8?b?QmVsw7Nu?= , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood If VMIN and VTIME are both set to zero then the terminal performs non-blocking reads which means that read_key_without_echo() returns EOF if there is no key press pending. This results in the user being unable to select anything when running "git add -p". Fix this by explicitly setting VMIN and VTIME when enabling non-canonical mode. Signed-off-by: Phillip Wood --- compat/terminal.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compat/terminal.c b/compat/terminal.c index 11288cfe5c9..3620184e790 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -57,6 +57,10 @@ static int disable_bits(tcflag_t bits) t = old_term; t.c_lflag &= ~bits; + if (bits & ICANON) { + t.c_cc[VMIN] = 1; + t.c_cc[VTIME] = 0; + } if (!tcsetattr(term_fd, TCSAFLUSH, &t)) return 0; @@ -159,7 +163,11 @@ static int disable_bits(DWORD bits) if (bits & ENABLE_LINE_INPUT) { string_list_append(&stty_restore, "icanon"); - strvec_push(&cp.args, "-icanon"); + /* + * POSIX allows VMIN and VTIME to overlap with VEOF and + * VEOL - let's hope that is not the case on windows. + */ + strvec_pushl(&cp.args, "-icanon", "min", "1", "time", "0", NULL); } if (bits & ENABLE_ECHO_INPUT) { From patchwork Tue Feb 22 18:53:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12755831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2610FC433F5 for ; Tue, 22 Feb 2022 18:53:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235105AbiBVSyN (ORCPT ); Tue, 22 Feb 2022 13:54:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235100AbiBVSyH (ORCPT ); Tue, 22 Feb 2022 13:54:07 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF5F611477A for ; Tue, 22 Feb 2022 10:53:40 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id d17so345957wrc.9 for ; Tue, 22 Feb 2022 10:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=WixbW0OSoA7IdMQhhP0xT088HPSMGgfKzB5SsBiwsjs=; b=hk2Px5HhkjKnsP4pyoTbIMCzx4A8UPHWrfaepZKxo1eaBLE54DaueWLKVAZs+rMiBb 5Sn4MBNOLp5FjuWVkVkY5xgG0VVN2sPx7Rz+MezfayP5kUEB7s/O1sYdVctMVHn44EVX S5m09c1pSNlNp9WmFQUALRJCdzZiQGSqE2XWw9Zc5rnc5mSyKpuae5Zjp4Mx114oZc/c +zzu0qEgf5as6Z8+HI7FljQy4PNVyiGv7se23+jAuZ2IIJe5hYMu8DpNUVbhQnok4Nn9 V3P5i3MLlqr2PDmZftnhfCcLYJ6f1QXpdwbEWcXMrE4SRRKn4CPu+UXv1nnBJz5iWidx jLjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=WixbW0OSoA7IdMQhhP0xT088HPSMGgfKzB5SsBiwsjs=; b=5R9VASS0UYAYv4Z3yybLHfB5u9ZjeR3isLKRtOzJSfa95jDpKcKi0NJBWEAQve5tp0 4ugTmZ11VtU7DLmXx7U+PuWq5//+YIqMrFBOoBbnYdhPVRQq++GzvXkCe78nkDrZxBUP lclSd/BSwZ0UWSDMbfTfjU4QSJzFzHMptDAiqa/q60XiGzJBPv0IkLImI2YPfADfZyfT BnpMonw+54cmQ5OK+9ZnP2oK4wTicAw7AqxvGQAZR6hgM5c/2oQ18yqV2zHHIXR5kKhw gGIcqs9zNGZJc5m9XOtkAMSRca4tyX0tvHZVv7B0QcWMBCH531ZYsTROWl0ZnRr/YhQ9 FSsg== X-Gm-Message-State: AOAM532FBh7yMTxTJ0ZHoKooS1mIg/ZL5oc2HfgoE1WV13zuYwGoZOmz koASMT95XIGTtLINHgzr1tW2FyCJ228= X-Google-Smtp-Source: ABdhPJxcjHtZ2P2hZYbePFzBuIUJ22gObW/aYi42/Yv7CXsGNg9Q6DcXgfvbieNgBaJJxozVdX/eOQ== X-Received: by 2002:adf:ef44:0:b0:1e4:99e8:a65e with SMTP id c4-20020adfef44000000b001e499e8a65emr21519819wrp.365.1645556019398; Tue, 22 Feb 2022 10:53:39 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d12sm45306173wrx.47.2022.02.22.10.53.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 10:53:38 -0800 (PST) Message-Id: <39b061a471bb6e5306f94b3a6d7e19be6ed6a92f.1645556015.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 22 Feb 2022 18:53:35 +0000 Subject: [PATCH v2 4/4] add -p: disable stdin buffering when interactive.singlekey is set Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Carlo Marcelo Arenas =?utf-8?b?QmVsw7Nu?= , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood 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 --- 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)