From patchwork Sun May 19 07:10:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13667784 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 882D4EAC7 for ; Sun, 19 May 2024 07:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102624; cv=none; b=EbBgicoehpje2W/Nd11Mfguw1avMgDlkFeugyqtRwBlx/XG1d13hEZ8bhfRqeWncOx6cL9RK3LDj/cPqztVu+vwGZv4AqRiUaaUl5VJ5D/lbjcbFXp55YY9Vfn0ZYVP++26E/GsI2vmF5OVD6MXg5kby7wetUG7vXhnE5xN8+jI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102624; c=relaxed/simple; bh=LEuX1adZnCKgieBrx27KhCNr96hqkf7UITJBXOBALlI=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=MItJknC7uQtdu/I0G/IusxRiqxQ1ZV1sfePKjzVYi0+qpd1uIjzi4KLOljW1VCYHHaiekxyZcBMN/uTXtaiaEldTvcwCeP+5HRlfzGAN2oCK4jTvz40AqKusyaSIGX3ewQplk58O/RVXdMoDrSlvV7wxYsL/nwYeN+SA6hTunXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Gx93k9kA; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gx93k9kA" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-41fd5dc0439so12116505e9.0 for ; Sun, 19 May 2024 00:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716102621; x=1716707421; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=rGrLDrMzJZkxdvn4MPKimjHXx4wtUjAqflv7xuqgZPY=; b=Gx93k9kAGkChpZJoAK3j8i+iR9pxUUKhCeqcl0jazkBE8bZcNBKCbycaaLL6AIqGRh WQE2Lsad4XGNolzM7zLAzPQAdhAxdLZzmXZ6TV3JA9kOY026X0aWvCQt5jK64mhoLScx UtvO0nJB7IlEiiJIr/wlNaSdytv2UaluruURNKhzIYg/j/UNc/Bixb8KJWpDNfm1mC2s dJGHGozhr0l8hMvHoRwRv1vNRtMZCx4kRFXHMiLYG784q/H/Wn0DGO4LfjEWYyrRn8VQ taUSqTHfBUPSwSugFiaC3n2AjazgGL00+lfttj5YHZ+1NkDcCNmJ2pMuNNl2vDJTC1b7 I7GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716102621; x=1716707421; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rGrLDrMzJZkxdvn4MPKimjHXx4wtUjAqflv7xuqgZPY=; b=pA/IoWiKBSvhX9GPTnL3YvgQ/GtS0zjGN904fJ/br3iGSpAWn0Svp+tvCZAC4J+BUw aQ58FGjr86BoRENaUJVXH57e9XLjU73H86qdTJBfeu6zo4kzyEZFGRzmQ8wGvJ15kGmu HX5Nqgnu2uybT3xk9VIKcX9cRuyxOxjMGSiC5L2Tt/FoWBmItiAz3jdRtYeQBg/GV374 KPlqFSE/a1lTu/7EI1vogf+iDYDQ1cUNwOO88j38+L+6tgQEblNVz3+OVAZbAYSfQgXB kaN84QIYaXsCnKvuVq8LUqJU0shYa8LlR+Au55lyoKr50AGoCiWNpkxmiGZf327sYqYB q7HA== X-Gm-Message-State: AOJu0YxgAuGgV9zB/wcXDuLxZbQWHiqFqxsP5LgfGmdaOxkoXldh7iiQ HnpAU2vU9QltZ4OldHsgQyA+UvgusM4wnxurLFaIBHoPHzlEi+cck/3ZCQ== X-Google-Smtp-Source: AGHT+IEauhbTKDuJbWGYjt8U9pP9qNoEkdo/BtijJyd1WKCNybeLpy60lNHDIXrnR/20DkrOE93YEQ== X-Received: by 2002:a05:600c:1913:b0:420:141d:994f with SMTP id 5b1f17b1804b1-420141d9a56mr160827525e9.18.1716102620703; Sun, 19 May 2024 00:10:20 -0700 (PDT) Received: from gmail.com (173.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.173]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42010b1076dsm289258095e9.41.2024.05.19.00.10.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 May 2024 00:10:19 -0700 (PDT) Message-ID: Date: Sun, 19 May 2024 09:10:16 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/5] add-patch: test for 'p' command From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> Content-Language: en-US In-Reply-To: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> Add a test for the 'p' command, which was introduced in 66c14ab592 (add-patch: introduce 'p' in interactive-patch, 2024-03-29). Signed-off-by: Rubén Justo --- t/t3701-add-interactive.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 28a95a775d..52d7830de2 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -542,6 +542,22 @@ test_expect_success 'goto hunk' ' test_cmp expect actual.trimmed ' +test_expect_success 'print again the hunk' ' + test_when_finished "git reset" && + tr _ " " >expect <<-EOF && + +15 + 20 + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? @@ -1,2 +1,3 @@ + 10 + +15 + 20 + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_ + EOF + test_write_lines s y g 1 p | git add -p >actual && + tail -n 7 actual.trimmed && + test_cmp expect actual.trimmed +' + test_expect_success 'navigate to hunk via regex' ' test_when_finished "git reset" && tr _ " " >expect <<-EOF && From patchwork Sun May 19 07:12:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13667785 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 090DE10A3E for ; Sun, 19 May 2024 07:12:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102758; cv=none; b=Vx9TjuYuRNMFWpr+xQSk4aoVIWArf4Ai2go9YB4dtN7UsrJmB9UK2Ra7yqqCCHqpSuYW+IbO6daKTdEVtGFKdeMSZFH8TMbhmBo0k7tL5raIj1LLRhnZxls1YTg0w//v9zJcjzuhxHJxFqNipeqMTj+uyB6Lam5W6Uig69ROHto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102758; c=relaxed/simple; bh=MThN82jGPvVBcMbCdAeC0pnrXPLIq90/5d9qXG5ROak=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=HRxAqH1nz3U7xTim8BXBif15W7DQuA4PAI2AxOzxc3+NuxThG77nSgz/Kbtc8gbJbjvAWBzErPehtz5Uy1CPgxQVHoyqM4fxgIv+pmt+85rIwVmbfJ8HdRhaAGOlh7Hq5kmHrDXFCuCUYs4lugZK6rnZO36wgT+N/SuPRiW4wMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XwiDc6hN; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XwiDc6hN" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2e6f2534e41so18221421fa.0 for ; Sun, 19 May 2024 00:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716102755; x=1716707555; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=jLh0Fn5AMsWBbc6wowRLpxqUz0egA0e0qnfAPxFQup8=; b=XwiDc6hNRIPZWeFE7dgpxWiJcrUeDuTx1MpBxYHnBXece99bOrbY1Eo02PaA3Nvn8n kQWMxik8SM2lozHs8xU98tE7THYWpmD5p/ewLED50abt9+xaRTFOVHh6fafF8j3Qb4Wj XIL/ly86WG3535RIyAyz4/JceU7227Y6z0Kpbbb/+DyotFaaRpL3rh4ZDFyGRO357M8X Pfi3qsHo7P8BTO0LVImqOdnCMRBEIWfEg6+MlozBoOer/rQFC4mMJWyyIO/B4OXnj70v 6YkUdoZNtrM6qDLuc10ytFb90hjAGBeEv/MBpMIVqUP4swfYw44kC0V90Lkbe9B0V0iA I8fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716102755; x=1716707555; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jLh0Fn5AMsWBbc6wowRLpxqUz0egA0e0qnfAPxFQup8=; b=u0jrR8LIsol7tqdxUfwOZqnbb0KbrvXB7TUgjXesTDzchF6VN/1VXrjfilM06qQsXP +WEExDO6WQ1tNe0SOYnLiUfkodp/y9gwDkc2NZ+dFJpHATDGd2aLIUUVA0qav+bYloLl WLVIa5k1MNunfeWJiDzRS590CNd1znyrLsWb8eEx9NOWNxd8AGoA2qF5tVQnkJHX7oQu aHGOfzJcy5sWtSGVIHcMN+6hj7MbUTLoJ9Jj2vExz8uHM3d42mggdFyh/WyHN1ww7pmD I+WncNZvc1UETpHbDQAkkIwmShd6uu3W9Wl7zt1/+krjLf94tThG0d8ZEqWiDCFgpZgX Q0sg== X-Gm-Message-State: AOJu0YzLH/WwTo5vjA/KcUXzQZNC/f7jOw40vJsWVZu1Gmv7i8MTG/E4 XXHlXSy84MsH0GBfTllq0YPaTNh0galkuODx2UixDW8L9AgTQyug0ADzeA== X-Google-Smtp-Source: AGHT+IHFzqM9rmgsPX2A4HLeN8FbiXQZ8jFK/r4b7ng5R+Z6HSpR3jDyUkXTDWW3BJmhWQ5F7PAXpg== X-Received: by 2002:a2e:8255:0:b0:2db:4f3f:55a7 with SMTP id 38308e7fff4ca-2e5204cc8d2mr155694091fa.45.1716102754978; Sun, 19 May 2024 00:12:34 -0700 (PDT) Received: from gmail.com (173.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.173]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4201c3f8032sm223886475e9.28.2024.05.19.00.12.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 May 2024 00:12:34 -0700 (PDT) Message-ID: <80f15223-246e-4cfb-a139-e47af829c938@gmail.com> Date: Sun, 19 May 2024 09:12:31 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/5] pager: do not close fd 2 unnecessarily From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> Content-Language: en-US In-Reply-To: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> We send errors to the pager since 61b80509e3 (sending errors to stdout under $PAGER, 2008-02-16). In a8335024c2 (pager: do not dup2 stderr if it is already redirected, 2008-12-15) an exception was introduced to avoid redirecting stderr if it is not connected to a terminal. In such exceptional cases, the close(STDERR_FILENO) we're doing in close_pager_fds, is unnecessary. Furthermore, in a subsequent commit we're going to introduce changes that might call close_pager_fds multiple times. With this in mind, unconditionally closing stderr will become undesirable. Let's close(STDERR_FILENO) only when necessary, and pave the way for the coming changes. Signed-off-by: Rubén Justo --- pager.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pager.c b/pager.c index b8822a9381..3ef6798f7e 100644 --- a/pager.c +++ b/pager.c @@ -14,6 +14,7 @@ int pager_use_color = 1; static struct child_process pager_process; static const char *pager_program; +static int old_fd2 = -1; /* Is the value coming back from term_columns() just a guess? */ static int term_columns_guessed; @@ -23,7 +24,8 @@ static void close_pager_fds(void) { /* signal EOF to pager */ close(1); - close(2); + if (old_fd2 != -1) + close(2); } static void wait_for_pager_atexit(void) @@ -141,8 +143,10 @@ void setup_pager(void) /* original process continues, but writes to the pipe */ dup2(pager_process.in, 1); - if (isatty(2)) + if (isatty(2)) { + old_fd2 = 1; dup2(pager_process.in, 2); + } close(pager_process.in); /* this makes sure that the parent terminates after the pager */ From patchwork Sun May 19 07:13:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13667786 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21B1817582 for ; Sun, 19 May 2024 07:13:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102796; cv=none; b=Szg6n1W7trNTMV3xENAocFATSmLv6LMPbg9pl2yX1Zgm3XJQmnrLC+mN2GqIF7ERL2CMgPv9/I/hsImrPA0TxFTROSmaRGIW8AaRI9TXShSmT8FZQdHM/T8D4IhdFKbcic581FNgxK2HCYpo8mVZ7vHzTeEs7U2OjGWXQb5OtvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102796; c=relaxed/simple; bh=Im3qcJ8j4sCLVn7NozYQF/NavaRE8dCDuMUz5NiiyP4=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=fMTctFWzop0e8yN68xP65G7WsSzzHFCUN54/946P58gsWUtECz3iG3oQM6anwp9Q9sb1Ijo7LOGPwK0XSLeeSr9Bd9qfBqFUZoNsHIGR9iiFMILhTkajDW53O52dhPhazUHSDqqV6WTVmjJF2B0DYzPijfmkdNKzd2tm78pkgy0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PtTb7GeX; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PtTb7GeX" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4202cea9a2fso11932675e9.3 for ; Sun, 19 May 2024 00:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716102793; x=1716707593; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=yrZRZaQhxGK/FyvET0HebJXkPi59LaWzmKAigbaNaKo=; b=PtTb7GeXhKcpxP7yiS5Xnu6RBifCxmhmgtskn8i/yOVXRHww6KiXSO3NwndCmq9t9O zq8fS0ahI66EWsgUcK0rxH1WZMRVijYmUliop4vjUbwAO7HBbh8un5aqGM7UotqSoM9f FMUkehMUb5Ft7TODn7ROuf8i1XFqp5jGvO9iySsxfsxJmEEznCXEyOeOlC5y2oqAT3F1 fHKUBxQiesoTZ9samBpdJZhj0BlX/tgOxSDAZJOXV2Jq6NsPEV8JFSbv23UIUEutvmzJ +Va+fmIP1YJf/FR70k91jvGL/VTJOoaCpv1/+WFvBYzHUNw/ll8Lts4dKdquGBl7qlDh D/cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716102793; x=1716707593; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yrZRZaQhxGK/FyvET0HebJXkPi59LaWzmKAigbaNaKo=; b=H0ckKGyeSssSzL4H9dzOCQYdjkCdwXVGFp0sWJf/RSbZ8gNYme5IjM62q19/NuS+az dnp02xQf9bFL5rJDWl620d24Extc/xsx8q1wznx5fyPyhudDrQbZugjRxXuuDO4EKgvR P4qDDtRorc/NuYIS3BKRr3Iyk9+k9WLgRxovldbcW6dsk+AhEt6/pmnzaf25tlulPwev m2pKNhwg10UgMmEYD1b8XWFgyWD4pysLRc+nHwQI4Yh/ThboC/sRXrnMVjSaLttZd2Qf S4EuTc1L2LfOSI44N50kY8ugl1bWgEmsdphUVdineQRk8JqdX93udclS7VFiGtIEt+kR ftlA== X-Gm-Message-State: AOJu0Yx4cG7E9Msz8t82GwpZKcdTeoCBffz3N1IOEgSx1SI8f8EIgYrN 3xPtfYVUnG9uVdR2bLoWrtfVNbTLCVYCDKIbqoBonGw24W7C58t0RWLpGA== X-Google-Smtp-Source: AGHT+IEppSnnGNuFMt4I3SixpxLnSPoUw4ApktetYBNGU2YxsVc46dB++MK9JkLQFSXYuKGxnNtb1A== X-Received: by 2002:a05:600c:a41:b0:41d:7d76:ffd4 with SMTP id 5b1f17b1804b1-41feaa2f3e4mr187144185e9.8.1716102793320; Sun, 19 May 2024 00:13:13 -0700 (PDT) Received: from gmail.com (173.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.173]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccce24c0sm373347105e9.17.2024.05.19.00.13.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 May 2024 00:13:12 -0700 (PDT) Message-ID: Date: Sun, 19 May 2024 09:13:09 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 3/5] pager: introduce wait_for_pager From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> Content-Language: en-US In-Reply-To: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> Since f67b45f862 (Introduce trivial new pager.c helper infrastructure, 2006-02-28) we have the machinery to send our output to a pager. That machinery, once set up, does not allow us to regain the original stdio streams. In the interactive commands (i.e.: add -p) we want to use the pager for some output, while maintaining the interaction with the user. Modify the pager machinery so that we can use setup_pager and, once we've finished sending the desired output for the pager, wait for the pager termination using a new function wait_for_pager. Make this function reset the pager machinery before returning. Signed-off-by: Rubén Justo --- pager.c | 37 +++++++++++++++++++++++++++++++------ pager.h | 1 + 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/pager.c b/pager.c index 3ef6798f7e..2fa06c43c4 100644 --- a/pager.c +++ b/pager.c @@ -14,12 +14,11 @@ int pager_use_color = 1; static struct child_process pager_process; static const char *pager_program; -static int old_fd2 = -1; +static int old_fd1 = -1, old_fd2 = -1; /* Is the value coming back from term_columns() just a guess? */ static int term_columns_guessed; - static void close_pager_fds(void) { /* signal EOF to pager */ @@ -30,14 +29,35 @@ static void close_pager_fds(void) static void wait_for_pager_atexit(void) { + if (old_fd1 == -1) + return; + fflush(stdout); fflush(stderr); close_pager_fds(); finish_command(&pager_process); } +void wait_for_pager(void) +{ + if (old_fd1 == -1) + return; + + wait_for_pager_atexit(); + unsetenv("GIT_PAGER_IN_USE"); + dup2(old_fd1, 1); + old_fd1 = -1; + if (old_fd2 != -1) { + dup2(old_fd2, 2); + old_fd2 = -1; + } +} + static void wait_for_pager_signal(int signo) { + if (old_fd1 == -1) + return; + close_pager_fds(); finish_command_in_signal(&pager_process); sigchain_pop(signo); @@ -113,11 +133,14 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager) void setup_pager(void) { + static int once = 0; const char *pager = git_pager(isatty(1)); if (!pager) return; + assert(old_fd1 == -1); + /* * After we redirect standard output, we won't be able to use an ioctl * to get the terminal size. Let's grab it now, and then set $COLUMNS @@ -142,16 +165,18 @@ void setup_pager(void) return; /* original process continues, but writes to the pipe */ + old_fd1 = dup(1); dup2(pager_process.in, 1); if (isatty(2)) { - old_fd2 = 1; + old_fd2 = dup(2); dup2(pager_process.in, 2); } close(pager_process.in); - /* this makes sure that the parent terminates after the pager */ - sigchain_push_common(wait_for_pager_signal); - atexit(wait_for_pager_atexit); + if (!once++) { + sigchain_push_common(wait_for_pager_signal); + atexit(wait_for_pager_atexit); + } } int pager_in_use(void) diff --git a/pager.h b/pager.h index b77433026d..103ecac476 100644 --- a/pager.h +++ b/pager.h @@ -5,6 +5,7 @@ struct child_process; const char *git_pager(int stdout_is_tty); void setup_pager(void); +void wait_for_pager(void); int pager_in_use(void); int term_columns(void); void term_clear_line(void); From patchwork Sun May 19 07:14:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13667787 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33CBD17579 for ; Sun, 19 May 2024 07:14:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102879; cv=none; b=ZtQHhHfU/WzFRlRtv9UX2SqAaguawZ90EIUzh3eRLSd/LdhaCQTub/YBWz+Em4dT5t/0gywDL3myC1wZbvTOx5HyVLI+Qe/kWRBQuFZEfTwEF0Zm4mktGHxk+94gX2KvZdwAIKjhTmnHmyh3uLvAouRpQDRLGx4sPnkAX95gGtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102879; c=relaxed/simple; bh=XjCvqbVFJJyoffLZK6Gwv09tDuhSyxir40gJPdNmTPw=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=j9u7keV7B42+N2/7JnB8QUUyuo75KcExDEWe1XwTYXuMayFsNUCCawbUSEIUUGrVrVhsB3eAaMkuAZDxpcuZnlp4RR+Kh4H9Ueit9E/OYpBzbsw8XHqA2gCY5T0XGXQ6End15TkDmqvGge3lZ4nbNCVb3hIuSqLLY4hLyHmUHmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OmN5KNlD; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OmN5KNlD" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42017f8de7aso11994495e9.1 for ; Sun, 19 May 2024 00:14:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716102876; x=1716707676; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=ixDigAgEZwnqusAuv6Ehz7QVQIr3XgQmz2zgyxO8XGg=; b=OmN5KNlDruZWXZlnT0kkE/uohjfGfLOWxo0YnQaXkus3Yipk+V+y+SZrMSMCREhTNI +0vlzsqC2yZIWUKDJTpLFRUf1y2S6rXj161SwoRNtNV4Vt8nZnkkLB/D29k2hwGuX32G mSVIH990PhS4LeYe0rZQeeinjMmgZ+EqKkF7E432xoAXpFSte5T3jsGNag4VjkEEiuVE pdRXWttbcQVSkBMw3sGQu+GTFfaOB8Qh4+a7elgmOP2AAkoa6SG7bL9YvLqt4eehA3uh phZku6M6IAC5dQWQEjqnd++/s/Ksg9RTN05hoej4GfdPT2WhIZIZjh1HSQHOxdE9exTI wMBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716102876; x=1716707676; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ixDigAgEZwnqusAuv6Ehz7QVQIr3XgQmz2zgyxO8XGg=; b=XE+F+MQaEIV0CBFfsEdMJgHIys0Oj1SvYs1E6RpGbKdONe1vYtdguJRfBDF+C01z0n UAcmRAf98qvQl0ZRbtZFMq9J/kMw5U3XQxnkkTy0MyigqTZDKLgvwmRXwHJ4sKAwbJkd cK8+gPHv5ONCIdopESMEiUvuKUvP4XSdXH2R0EsTay/IqWbpbxQlIyZZqUBjl5qLckZI 9gRS4R/xs9Wh/pZ8RdC6ZlEMfRV4SiWd67YqH4NmZu3XwMLTAhL0e8Kdd9s3gecmUybm SNQ1hzlZCpnE60V4n/VW63H7tnAgf0J/3tgWXWlb4G4IMFHoJ+NXjBa7QiGHtWUVlVyD 7fSg== X-Gm-Message-State: AOJu0Yzy0fSFKFzgE41KRvtwUJzB9GriY24Jp7RiRljb51Cl1pXAY92J FL2hpPfiExzwEA80P17P7IRoV9J7KJrpqeQbGKd/U9Crr4DqGOkJ6Qfvkw== X-Google-Smtp-Source: AGHT+IG0ukz/pJjcvIEoO5qX+LxoYybex6YzEkxbDeVsBf0XzgRfcHvd3g0xBazmMlghh7B0HpHEIw== X-Received: by 2002:a05:600c:548b:b0:420:e405:579d with SMTP id 5b1f17b1804b1-420e405595dmr16495455e9.21.1716102876368; Sun, 19 May 2024 00:14:36 -0700 (PDT) Received: from gmail.com (173.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.173]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f87c235b4sm405227265e9.11.2024.05.19.00.14.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 May 2024 00:14:35 -0700 (PDT) Message-ID: Date: Sun, 19 May 2024 09:14:31 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 4/5] test-terminal: introduce --no-stdin-pty From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> Content-Language: en-US In-Reply-To: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> In 18d8c26930 (test_terminal: redirect child process' stdin to a pty, 2015-08-04), t/test-terminal.perl learned to connect the child process' stdin to a pty. It works well for what was intended: satisfying an `isatty(STDIN_FILENO)` check. However, the fork introduced, that copies the stdin to the child process, does not always manage to send all the information. To illustrate this behavior, we can use a function like this: f () { dd if=/dev/zero bs=1 count=10000 status=none | t/test-terminal.perl cat - 2>/dev/null | wc -c; } We do not obtain the expected results when executing this function 100 times: $ for i in $(seq 100); do f; done | sort | uniq -c 36 0 4 1 53 4095 7 4159 If we do the same with a version that does not redirect stdin, a version prior to 18d8c26930, the expected result is obtained: $ git checkout 18d8c26930~1 $ for i in $(seq 100); do f; done | sort | uniq -c 100 10000 In a subsequent commit, a new test is going to rely on test-terminate, and it does not require stdin to be connected to a terminal, but all piped data needs to be successfully transmitted to the child process. To make this possible, add a new parameter "--no-stdin-pty" to allow disabling the stdin redirection though a pty. Signed-off-by: Rubén Justo --- t/test-terminal.perl | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/t/test-terminal.perl b/t/test-terminal.perl index 3810e9bb43..85edc9e8b9 100755 --- a/t/test-terminal.perl +++ b/t/test-terminal.perl @@ -12,10 +12,10 @@ sub start_child { if (not defined $pid) { die "fork failed: $!" } elsif ($pid == 0) { - open STDIN, "<&", $in; + open STDIN, "<&", $in if $in; open STDOUT, ">&", $out; open STDERR, ">&", $err; - close $in; + close $in if $in; close $out; exec(@$argv) or die "cannot exec '$argv->[0]': $!" } @@ -78,28 +78,32 @@ sub copy_stdio { } if ($#ARGV < 1) { - die "usage: test-terminal program args"; + die "usage: test-terminal [--no-stdin-pty] program args"; } +my $no_stdin_pty = $ARGV[0] eq '--no-stdin-pty'; +shift @ARGV if $no_stdin_pty; $ENV{TERM} = 'vt100'; -my $parent_in = new IO::Pty; +my $parent_in = $no_stdin_pty ? undef : IO::Pty->new; my $parent_out = new IO::Pty; my $parent_err = new IO::Pty; -$parent_in->set_raw(); +$parent_in->set_raw() if $parent_in; $parent_out->set_raw(); $parent_err->set_raw(); -$parent_in->slave->set_raw(); +$parent_in->slave->set_raw() if $parent_in; $parent_out->slave->set_raw(); $parent_err->slave->set_raw(); -my $pid = start_child(\@ARGV, $parent_in->slave, $parent_out->slave, $parent_err->slave); -close $parent_in->slave; +my $pid = start_child(\@ARGV,$parent_in ? $parent_in->slave : undef, $parent_out->slave, $parent_err->slave); +close $parent_in->slave if $parent_in; close $parent_out->slave; close $parent_err->slave; -my $in_pid = copy_stdin($parent_in); +my $in_pid = $no_stdin_pty ? 0 : copy_stdin($parent_in); copy_stdio($parent_out, $parent_err); my $ret = finish_child($pid); -# If the child process terminates before our copy_stdin() process is able to -# write all of its data to $parent_in, the copy_stdin() process could stall. -# Send SIGTERM to it to ensure it terminates. -kill 'TERM', $in_pid; -finish_child($in_pid); +if ($in_pid) { + # If the child process terminates before our copy_stdin() process is able to + # write all of its data to $parent_in, the copy_stdin() process could stall. + # Send SIGTERM to it to ensure it terminates. + kill 'TERM', $in_pid; + finish_child($in_pid); +} exit($ret); From patchwork Sun May 19 07:14:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13667788 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF71DB666 for ; Sun, 19 May 2024 07:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102905; cv=none; b=D/wLIWOWjcJY4na0fTRYTm71kUbxqju4rKZuJ4UjJvwP39cwqQ/K74yYpUprsbMAN/62qPpSpmQQ8NIpmzb8l6jxE2NR9gBrY4qmGkc2+Txz/bWU/LApDaWKvyFg95AV/rLyC1LpoiIqxR02TdMgOAiO9lRegzN9wAuNclKxwYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716102905; c=relaxed/simple; bh=MH0WvfnA2g14fdgPiE/dAj9kL1iUR5axRNzg47LqmHM=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=CbDxAghMrongjfXwGVI3SOM0pGXQAQ6hsB7TGCxMZ2Jc3JPDLkIgFfiMmgUUvEfsfWsJOkH0uuBTELxu3y2a9b8Q8M8fRLtDdifCNHF8p869CtDadJ2f6SS/mn6DCh6/3NlIPJKdVfWJ6J4LcJxqtZMxQFtcCjHUcoi5sSUHOwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g2srdoRy; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g2srdoRy" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4200ee78f33so11984975e9.3 for ; Sun, 19 May 2024 00:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716102902; x=1716707702; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=H90gQHGmZuShwEUE2pmjiGODQ2MWPxUcZ64pIH74gUE=; b=g2srdoRynzOHjOpsGXFR1mYVtliVyYTYLi0F+ThDscISt8GjW8cMMNnowYAB08UKDx NKAW/0Kf4ad6sVIPDGosTCvVsuP4soaEbrEwrE+xO+z28TdFzOA7Velb1crDwYxNsIx9 32CpPgoF8YNqr5U7TWr7U0tFcaZHM66KZCnvDrPw7qad7y9VEDrjv8XPXllfEUtM3Dpe N6eq2T1A73hX2xGBHeqVOUnWSWKEWjto/rBw6lsqfsaf95p8aaKZQBGAiaL8uHhV6mME bRB9OUu0qPC6OXIYxss31Vn09FrzL6TBpkAjm3WMSQAUSmPF2cVSLhX5cGiKalO1vSd8 rs6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716102902; x=1716707702; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H90gQHGmZuShwEUE2pmjiGODQ2MWPxUcZ64pIH74gUE=; b=Ad5+8pwHywNZ0cYujTMOYkk9FDp/BCq0p6Ix2z8ofYILFzSngwzAi19xtF6h3CcQDv UjzqYcOEKS4Bn5zDo+HPsCnftKKq8bRfHzpxvWUsr++a3PPYxnaLlKVUdpZ/XcFnfQbX 4F0MfGrn0X/gj4j7UiYmv3Btbr3jCvNx1XCj7ut3yZTlfi7thx87Y8YOW7+S1SAmySK6 n4O6PEUnWU9inBX134VZpeCqQ5+avD2lrkJxUu4Yshr2do48TSLCKWh6vwPq3UkUK/ND t5gpqNY1EmcD2EZrs++sTDJpYtLHgl9wIcDo7FuTGNq47VGK5tyQRvFUKb0EyvLAGYKF LN9Q== X-Gm-Message-State: AOJu0YwP/9T8upiZf73uJuWWgfkQgXCBHIsTNY/K9+w8yPLhAeV5H3xb ArLm29wa46YyYLX7g9jRfQqfwosfmMwVUumVR63bGUh8JQLmZrSxv3mjJA== X-Google-Smtp-Source: AGHT+IFYf3/wyNHCqM24XGPJOUspRvQYu9PFxOd03I6smn9CArlJvoM8a8AnxL+fUETQtaLJRStJcQ== X-Received: by 2002:a05:600c:198a:b0:41b:fc3a:f1ef with SMTP id 5b1f17b1804b1-41feac5a3damr185502885e9.33.1716102901970; Sun, 19 May 2024 00:15:01 -0700 (PDT) Received: from gmail.com (173.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.173]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccbe8f9bsm374570995e9.6.2024.05.19.00.15.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 May 2024 00:15:01 -0700 (PDT) Message-ID: Date: Sun, 19 May 2024 09:14:58 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 5/5] add-patch: render hunks through the pager From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> Content-Language: en-US In-Reply-To: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> Invoke the pager when displaying hunks during "add -p" sessions, to make it easier for the user to review hunks longer than one screen height. Signed-off-by: Rubén Justo --- add-patch.c | 3 +++ t/t3701-add-interactive.sh | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/add-patch.c b/add-patch.c index 2252895c28..cefa3941a3 100644 --- a/add-patch.c +++ b/add-patch.c @@ -5,6 +5,7 @@ #include "environment.h" #include "gettext.h" #include "object-name.h" +#include "pager.h" #include "read-cache-ll.h" #include "repository.h" #include "strbuf.h" @@ -1448,9 +1449,11 @@ static int patch_update_file(struct add_p_state *s, strbuf_reset(&s->buf); if (file_diff->hunk_nr) { if (rendered_hunk_index != hunk_index) { + setup_pager(); render_hunk(s, hunk, 0, colored, &s->buf); fputs(s->buf.buf, stdout); rendered_hunk_index = hunk_index; + wait_for_pager(); } strbuf_reset(&s->buf); diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 52d7830de2..6c4af8904e 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -558,6 +558,27 @@ test_expect_success 'print again the hunk' ' test_cmp expect actual.trimmed ' +test_expect_success TTY 'print again the hunk (PAGER)' ' + test_when_finished "git reset" && + cat >expect <<-EOF && + PAGER +15 + PAGER 20 + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? PAGER @@ -1,2 +1,3 @@ + PAGER 10 + PAGER +15 + PAGER 20 + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? + EOF + test_write_lines s y g 1 p | + ( + GIT_PAGER="sed s/^/PAGER\ /" && + export GIT_PAGER && + test_terminal --no-stdin-pty git add -p >actual + ) && + tail -n 7 actual.trimmed && + test_cmp expect actual.trimmed +' + test_expect_success 'navigate to hunk via regex' ' test_when_finished "git reset" && tr _ " " >expect <<-EOF &&