From patchwork Sun Jun 2 15:42:38 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: 13682918 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 39F3417736 for ; Sun, 2 Jun 2024 15:42:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717342962; cv=none; b=F2pr0dtI5p+0HEGhmJKjRMdn7NBYy359l15MFkcCa1cLu5nTPfn8u1CfKmIyVYSqtfZUBNsxRRdJeKpNWSBf5PAgGDoBlrXxzE5yVBIImmle18vw147c/1N5tHx4VbIknx410WLbYebG5CDMY4EEt5xUaCBFGQU0k7q21TwpjuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717342962; c=relaxed/simple; bh=9buze0qX/HHkBRJA2x3k2wct50Sd5TTM45xW63hS89I=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=Qu14Db3H4CYUSWf628Fimyuww6V0AyQlUDMQO/l/PBN6YcSUviUmaxHfjT9jL0wESvedqR1wZMFrd4ERyebRFerrdljLhnrVLpw5kRBnkT7xPNVLeNacRKdyuGr3hMRoZqg8pnwaad34O1ZeDQMNlWlfgEz/Hc6itsawuWxe68A= 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=DJbaVt+k; arc=none smtp.client-ip=209.85.221.52 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="DJbaVt+k" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-35dcc681f70so1628304f8f.0 for ; Sun, 02 Jun 2024 08:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717342959; x=1717947759; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=Ogt71lu0MFbaoK6gslrbrwDHm7w5iJ2MfFkPK48AauM=; b=DJbaVt+kXpA3ToQFyMtOw8wQobSc30Ku+HrB3knPIyfuD5YWrq2GqJvqmKsuuoMDVL PnRmKjazuNBIy4NmwwPCpF27c4woMbQahedHrMkmnxA7JdW0pBHAK3aZ9n3jF03kgaso clZxq5ZzxteItqOgqT56RWoD1AIVceVj3+aGptXpaKC8kVEvA9CsycoYAO/9kN/rNGz3 9kkGTL46EBRood+0+FcdYGSkwE2PHeIqwWZQQ8FO9xSBDcKlKJhqzF4z9KFM98THODd4 WRE3ee7JycuIFdKQrfoLVKc6EVrMXR6DqnbyKu1SEk7f42oLwwjvubg+B2Xp5btnDzdH ZZiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717342959; x=1717947759; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ogt71lu0MFbaoK6gslrbrwDHm7w5iJ2MfFkPK48AauM=; b=Q/y0yM1cJ75a1oQAqMPdn7bmboP9PzXrjY+oSBsKy7n/DReAgM02Y5uUgrjZnbd+tz ImdoOfaTPzXUrdiJbInS3nPYl4IfM5fmrQoCyq7grnvZ0k6RQRJEDO6fK5R5yqD9rCYq 9Yj9QneRlugTa2sNHcccUuB8farjQAR7abkstha0atcd3CX2yLgticczh88EKdSXzADh 431k6+RoTja51OvCRlqX6Y0puDnzUlmDqgrPdxOfiQzxmtH7SVfvxeXbDo8SS1SZMJiz coTZliSeDj0xX5Oq5UIYoA1VKDto+mmjwGhwnk2WMlOJk353CI+LskREOmgo/TLqq/gL 1iWQ== X-Gm-Message-State: AOJu0YyTc4iaWwJCElLdMLNz3osxr6hhOAdo2yXbYisIKRiefEMof3OK 44MeGWCdsuq7raPmv0m544AtSseUPNA2NetrfLtV224TE6hr2uJwUkAdaQ== X-Google-Smtp-Source: AGHT+IGlWldJdQYHE5sbTJ9bFmW0gYoXRsjZQobspPjVVWB1TIagfTr4dXsA3wxbPA3dSgereBUn+A== X-Received: by 2002:a5d:5683:0:b0:351:c615:8165 with SMTP id ffacd0b85a97d-35e0f3414e8mr5268126f8f.66.1717342959308; Sun, 02 Jun 2024 08:42:39 -0700 (PDT) Received: from gmail.com (12.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.12]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd066ff17sm6392396f8f.116.2024.06.02.08.42.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 Jun 2024 08:42:38 -0700 (PDT) Message-ID: Date: Sun, 2 Jun 2024 17:42:38 +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 v3 1/6] add-patch: test for 'p' command From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Dragan Simic , Jeff King References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> <199072a9-a3fb-4c8d-b867-b0717a10bacc@gmail.com> Content-Language: en-US In-Reply-To: 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 6624a4f7c0..6f6d174687 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -590,6 +590,22 @@ test_expect_success 'navigate to hunk via regex / pattern' ' 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 'split hunk "add -p (edit)"' ' # Split, say Edit and do nothing. Then: # From patchwork Sun Jun 2 15:42:52 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: 13682919 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 BFE6A42A9E for ; Sun, 2 Jun 2024 15:42:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717342977; cv=none; b=sKgkGcfaL0ZOVVivKFwro9GrFZwt4Yd9szojz1UQlGYEEHx8R2qjKhgqSEFCHBppA7+KSZb+pm66dsPsde9pzP2uFVjCXtzdy35iiZUSm1NY9itDGQ1Vp9bE+dtqszwWSDiV/goEsLWiEI/3dVL+7KYCelp/ixIT1Cu5N/GXn0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717342977; c=relaxed/simple; bh=3b7LwQihlpQ+zRRGRbG4TlYa5Tk3O86RCHn22emgUm4=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=cr0XEGgzk6ef4ZpWGWoqGenyuNzf4aX7lAdw+4XgX2aemhLLo08kDO8ttZltBPrs6Q1pBB1YfjRZMRbBm5wpr96sBj3cXfGpUQCX2TczLvEVQcYJg1r81OExokDOb0OO2XmOqzC6FJMGfjSo7EDXu7g4kQMLCdV4ECA8uTzkdgI= 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=NGUrN/lP; arc=none smtp.client-ip=209.85.128.47 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="NGUrN/lP" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4213b94b8b5so1921775e9.0 for ; Sun, 02 Jun 2024 08:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717342974; x=1717947774; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4bXvkN8jWUutuqNXHryhLFWRZnY3qucFonzAOf2d3Pc=; b=NGUrN/lPqFwdgXajbpYyD92Mv6SIMX6E3U907Ptc5xTvEhl87GDZLKsUKQNOSOCOWw BCuk2lWvkOiiXr59zYepF66mxtKeuFW6HxSwaseFwILZf4X3j2g/TILEVNSDG7OGdUL8 u3jhakFEJ9e3CByVmgCNykB7lTI5zkX3LO9retgDsCGBYisVkXiy8B8E8xGH/CYwt26f Wb+6JkuDrx1VF+/e/+9DVEik3wJAzOPZcEcWW5oAqctXWtIa+8i59HyousS4st1Ybn2m ZzLPfboAh2fU4gC9N0yIUd4bYKfcNxUwSc6tDYaJBmlvC7xREOHBYtTtD2YY73GeSJQL wWRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717342974; x=1717947774; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4bXvkN8jWUutuqNXHryhLFWRZnY3qucFonzAOf2d3Pc=; b=ErGDDgiaHGr/NoLvixY+bbvpa4BNhKfqyX7FCE6JdbPizzdnqL11YTfP2Oda52dmwF kVgFdzR0VvPzhabrNC3VySCTFIfDbQqPoUtQ0EbZ/m1wsHvp7QFtEot4nBRlDmd40J8g zFB77lk9XR0H9yVkgXMBFPabuhsM0rZ+PjXTvkixoO6v4ZjYxwdt34tp88XvA1/vETWu YgsJbi4WX2/768N2z/u4qLZK+V42CkGDnuiRiMC4NT5EfbHoIbcj5IydW292oisD+vBH kknhzuNR4+3PqPniUOZrofdm4EAndcHEWnd1W8oTaGzKHzRI2vYY2VYVk73XLFglikVo JElw== X-Gm-Message-State: AOJu0Ywo765Yz/vagRAoiDwpeOzO8PiuAI2u6Xl890yaxVP+zEwEJoI9 coZIsFAWnuOjOW8XQOIkBkbQ7dCG0M992g0d10p0qAH6buRKS/+1H6/r3A== X-Google-Smtp-Source: AGHT+IEgQ5lfjwumzOFRbc1QdVbOKZLAcfRa54x75hthw/+fNTlt8Df5iyPVZLXDpe2nh+mn8Gy2QA== X-Received: by 2002:a05:600c:1554:b0:421:35d5:39bb with SMTP id 5b1f17b1804b1-42135d53c88mr25561845e9.40.1717342973883; Sun, 02 Jun 2024 08:42:53 -0700 (PDT) Received: from gmail.com (12.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.12]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4213411b25dsm63184975e9.40.2024.06.02.08.42.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 Jun 2024 08:42:53 -0700 (PDT) Message-ID: <5aca7ccd-d119-4a4f-8234-2c6ba3387435@gmail.com> Date: Sun, 2 Jun 2024 17:42:52 +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 v3 2/6] pager: do not close fd 2 unnecessarily Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Dragan Simic , Jeff King References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> <199072a9-a3fb-4c8d-b867-b0717a10bacc@gmail.com> In-Reply-To: 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 will involve using close_pager_fds multiple times. With this in mind, controlling when we want to close stderr, become sensible. Let's close(STDERR_FILENO) only when necessary, and pave the way for the upcoming 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..b786601074 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 close_fd2; /* 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 (close_fd2) + 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)) { + close_fd2 = 1; dup2(pager_process.in, 2); + } close(pager_process.in); /* this makes sure that the parent terminates after the pager */ From patchwork Sun Jun 2 15:43:13 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: 13682920 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 0F9C942A9E for ; Sun, 2 Jun 2024 15:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717342997; cv=none; b=hzScwh/9Aoe1McU/sRb1k9+p/H2YuGLSCYBiDkkJY/DRBnjGMafkrT1sPKoKtuAhfvxM6comdGp093a0eORGXx4wOjkzusYIjwfjrtyH8l/23JibNqbnsZDCIJHybkzHmWGRvhg3YBIk3OFa0sdJvBGXOK/egWRcrMvWoMruHA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717342997; c=relaxed/simple; bh=0tYWSD9R7BQez/k0e1abyPHU6KdOtWFM1PFtZm4OS8Q=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=VOHPh4vVbbyQnVi/U3TOJsomsbrYBSOxYDKlvxqS4Yboua55uNbyMiRDd4w9KflfXGAJYr9v1T5ttQGDoorFxUqz05mR7nHMcf4nBmMc6UM3+cDuiWtPWByBZEBHYtK3zGDCwuN4zqNXSDy81xY6jfQ2OpRq4k2NtHuc+irFQNs= 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=M7tMqG2z; arc=none smtp.client-ip=209.85.221.49 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="M7tMqG2z" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-35dc36b107fso2602961f8f.1 for ; Sun, 02 Jun 2024 08:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717342994; x=1717947794; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=hT2qPcKwiAeZCNLZ5PJuOrdUflulvofvVQeb0kISpxc=; b=M7tMqG2z6MLKGCiPfrzvnbI/9h+Yy3B9NsWeRQc4CAsmooAbWUzwHxeis+8yPLOO9/ z/DMg7+mTHim8ongOrhrpxEGP6/wSZKEJQ2nvV8URnb0nCZ03ZDEYDGvNZBBo7kTisYg u67Qo3LZmoIsuitfGygIR36yjO+J0pFfb82DnA3AWv7T5RfkHRfUQeSwp7RQsl9BrHiQ odt1di4wSb460rCBduUl9/lHYYEyX2mWYyKg8qtVSajf8hGAxAIkJpoA12SAto5IZbfu PBNRWZkW5RG4okVT0NhuNOdrLANv7Nw/CquRpW78uiGQhob1n+9ueqCT51LtIjy8GPA1 R7Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717342994; x=1717947794; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hT2qPcKwiAeZCNLZ5PJuOrdUflulvofvVQeb0kISpxc=; b=I/t8BH5HdpxMPkD9/9csi369oTD1Aepqba7VDZIbWN/GpvlomYJs5YqiIx06Um1oSo p425E148Sngt5+XRlz6b2hnEYr5FZj50uEHyCfOp22zSiwNYD37Ydoq4+LnIW0dZUJaB +z/N0JcXi6hyjIQ9UJcpvgPi/EzO3kbx3olspfVYpzrUiwGqMKnx5nC1rZOWhLowUFY7 L6ktSZbRkZ6CUdTSxI2/qDAuTKjqi+91xGV08XDzBKiKxqUY5ZyBgM4RFqWgvlxR065U ABTwq4Iut9yjz9JpYqiyu+C0XsANVflPlqkVD1YpbY/zyWCvBCUqVgN2f/SgCBQFDebg V5Fg== X-Gm-Message-State: AOJu0YyxAslxBTA46iixJTfP6pa95qKnRgdViolyUM6tcrXe9y0rm4M4 XQBKIcum3f1i0SzYsLj5iakJFHVc9OvV3YECwE/Y/LrrGrw0FPTtqLjV4w== X-Google-Smtp-Source: AGHT+IHFf0j87YvcrVZkpTjfNpa5Rn/C7RMKz1FNnkk1X59RDCrK6nFn19LGLAdqD4KT3NC1CxhDeQ== X-Received: by 2002:a05:6000:1754:b0:34d:7f9a:ecbd with SMTP id ffacd0b85a97d-35e0f25e11amr4313064f8f.1.1717342994339; Sun, 02 Jun 2024 08:43:14 -0700 (PDT) Received: from gmail.com (12.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.12]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd06499d8sm6502398f8f.90.2024.06.02.08.43.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 Jun 2024 08:43:13 -0700 (PDT) Message-ID: <6176a476-6afc-4513-abfb-280b0dee5be7@gmail.com> Date: Sun, 2 Jun 2024 17:43:13 +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 v3 3/6] pager: introduce wait_for_pager From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Dragan Simic , Jeff King References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> <199072a9-a3fb-4c8d-b867-b0717a10bacc@gmail.com> Content-Language: en-US In-Reply-To: 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 | 36 ++++++++++++++++++++++++++++++------ pager.h | 1 + 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/pager.c b/pager.c index b786601074..925f860335 100644 --- a/pager.c +++ b/pager.c @@ -14,7 +14,7 @@ int pager_use_color = 1; static struct child_process pager_process; static const char *pager_program; -static int close_fd2; +static int old_fd1 = -1, old_fd2 = -1; /* Is the value coming back from term_columns() just a guess? */ static int term_columns_guessed; @@ -24,20 +24,41 @@ static void close_pager_fds(void) { /* signal EOF to pager */ close(1); - if (close_fd2) + if (old_fd2 != -1) close(2); } 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,6 +134,7 @@ 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) @@ -142,16 +164,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)) { - close_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 Jun 2 15:43:30 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: 13682921 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 4BA9617736 for ; Sun, 2 Jun 2024 15:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717343014; cv=none; b=t2D/UvtsSyhQLd2a9DD+eCL8Mstxt+yFjehEMSHguE19VOdb7vq5LlLlEjFWkpeCvCeh8adJUCT855oj4xVD8xhWf+5Y5WKjgW7dWllmblgTfmvXcpqSg24kwa5yAaQqPCv2Jz113QOGVj/cnGjoBOUiET2D9RE9ecV+huyr/64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717343014; c=relaxed/simple; bh=Qh/J6ceza050EFKPEUHMmmP9KRuVpeK3e8GNA7HMvmk=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=Z9ekwJiFhcMFAyeHvk3EEBf14j2sLgyXw5l1qh4hTSRk25NWgzdtKb37vf/gV+jL/EPKvct8gknP+YWRnvEPwSHGE9AxkGy3crRkEq5m/7w/ZxgfB2nNvqHnmAQ0lDjX1J77nCd0Lt6NbLxm+x0j9hqGOcknyxXquYlPcI1QXV8= 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=PwHK0fyI; arc=none smtp.client-ip=209.85.128.42 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="PwHK0fyI" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-42136faf3aeso5109925e9.2 for ; Sun, 02 Jun 2024 08:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717343012; x=1717947812; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=hPjPtzf/M3cRFJj2bAlVeZ0gQRsY3cNyp+/4VykquP0=; b=PwHK0fyImEvAYDidTdtmyehwN5+7HtHV/0W9oayx+lVzq4aBayE0tV7aeb95AwYA2b AQYNr+SQayw44GweFsyvuWp5Yq8kRZjDVrdZN7pgdmOrmkCN/BF+2Ok5vGRoSufYpEHp 6b+r0fjaFMrIE1dqlQBl+iS3oKxAVg8iPjhjoK2x4UG8DPMhscvvzMHHPzsHgkTHWW31 OBR4my/T84mzxQQWSdHLwPPiqVnWC9Evv4O49hsWFjFTf+Lb2KQaSbxT4wydJ0gzz4TG Ge/YJYMMNGyIX1k9QVIeAD/OiJKEpq01Wkk9MQeymQT9lY6AD54HRRakPb3TEVpbhDLx 8fTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717343012; x=1717947812; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hPjPtzf/M3cRFJj2bAlVeZ0gQRsY3cNyp+/4VykquP0=; b=Bj192hZ4LXL/kgdgyWMhVlwvpnxwH77k3g5LDMiXLDbGW7kIWMyJB3f0UvDF1JoyJZ IZnCJNPvXrqvmTtINzMpIWWycUH460gNPLLJq5lw7sme/rjuHffYEhcXlFQEBvq1u6Zt 3PJg2lM3fPBwfk3d70VU0EgIRkfwqCpRnR+ZIYAMne807GOPpB+IoDRbYmUjPBX5ZhR2 Jas1FTLeGyIv6bU54+JFH6oEhd6yQ6kQa/ETvpn0jux8hcFdGs+VfBGGk0mDtBrXLKcF HP3LgRRvHcG1d0NyMpypIAAnJDe1ISHJk1sauv8cN0LRLdPTZvbkok44z8ivZKswix4l sqqA== X-Gm-Message-State: AOJu0YxlUWcwgaNQwNtet4Qq7JDHD/rzVo2ob82EzrKNDbfzX3NyLc1j vveMEbs15LPuFfb0KJQZGkT+csJRcsWZe/qgH5FhqmIwPCaVbZG96dLR2Q== X-Google-Smtp-Source: AGHT+IHBo8iKPqv/JEvfz5iB/MpGZjZdxzngP7zhJKt70L+kTwR3PVPLtmZSfzEPR93dKkufTtMesg== X-Received: by 2002:a05:600c:5117:b0:41c:2992:a3be with SMTP id 5b1f17b1804b1-4212e0adcf4mr55835825e9.29.1717343011589; Sun, 02 Jun 2024 08:43:31 -0700 (PDT) Received: from gmail.com (12.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.12]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4212b838b83sm87433795e9.10.2024.06.02.08.43.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 Jun 2024 08:43:31 -0700 (PDT) Message-ID: Date: Sun, 2 Jun 2024 17:43:30 +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 v3 4/6] pager: introduce setup_custom_pager From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Dragan Simic , Jeff King References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> <199072a9-a3fb-4c8d-b867-b0717a10bacc@gmail.com> Content-Language: en-US In-Reply-To: Introduce a new function setup_custom_pager() to allow setting up our pager mechanism using a custom pager. If the custom pager specified is NULL or an empty string, use the normal pager as setup_pager() currently does. Signed-off-by: Rubén Justo --- pager.c | 17 +++++++++++------ pager.h | 6 +++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pager.c b/pager.c index 925f860335..21a7d9cd60 100644 --- a/pager.c +++ b/pager.c @@ -74,14 +74,13 @@ static int core_pager_config(const char *var, const char *value, return 0; } -const char *git_pager(int stdout_is_tty) +static const char *git_pager_custom(int stdout_is_tty, const char* pager) { - const char *pager; - if (!stdout_is_tty) return NULL; - pager = getenv("GIT_PAGER"); + if (!pager || !*pager) + pager = getenv("GIT_PAGER"); if (!pager) { if (!pager_program) read_early_config(core_pager_config, NULL); @@ -97,6 +96,11 @@ const char *git_pager(int stdout_is_tty) return pager; } +const char *git_pager(int stdout_is_tty) +{ + return git_pager_custom(stdout_is_tty, NULL); +} + static void setup_pager_env(struct strvec *env) { const char **argv; @@ -132,10 +136,11 @@ void prepare_pager_args(struct child_process *pager_process, const char *pager) pager_process->trace2_child_class = "pager"; } -void setup_pager(void) +void setup_custom_pager(const char* pager) { static int once = 0; - const char *pager = git_pager(isatty(1)); + + pager = git_pager_custom(isatty(1), pager); if (!pager) return; diff --git a/pager.h b/pager.h index 103ecac476..2166662361 100644 --- a/pager.h +++ b/pager.h @@ -4,7 +4,11 @@ struct child_process; const char *git_pager(int stdout_is_tty); -void setup_pager(void); +void setup_custom_pager(const char*); +static inline void setup_pager(void) +{ + setup_custom_pager(NULL); +} void wait_for_pager(void); int pager_in_use(void); int term_columns(void); From patchwork Sun Jun 2 15:43:59 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: 13682922 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.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 F21B117736 for ; Sun, 2 Jun 2024 15:44:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717343045; cv=none; b=Z7XtBhii8trAaO0P23fnlOgfG+2mDWel9fDN8+/2wNxNZEVMurFEvQ/NiWLMqcKEXysjq/Mz60dutFQIs3QXPzLSjL+Zm5obMpcUb5EboCOI29TWaIjFaN9IrBMGe/EhRphAe4zsaZFH4MboSy+u/T2ND/pjWLRi8VgDILnHKe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717343045; c=relaxed/simple; bh=nty8/QcRJ7AJQOJCJZiwHTi7jFeXN24UVFGhAArKMmw=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=YIIu+Nh0G36/FWCDiutCaVugNXlv7L6nn8B9cQ8EdVjBBEGVkJGWxnEm3Sfwxl6BwfUrEYLiAK4WassSqJP1nVU5/TQnX9GK7qofKKB7BeLJe4wnbEseeMGQ4FtmDF6oGUDEKz8c/QGDGcxabx12fw3jVT36aaZIkRw7kOHWlvk= 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=XWWjbzDi; arc=none smtp.client-ip=209.85.219.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="XWWjbzDi" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6afbf5b88ecso860446d6.1 for ; Sun, 02 Jun 2024 08:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717343043; x=1717947843; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=ZwBGTiJPesWN/i1o69j2rKckXyAspOufdr1v3pOiZMk=; b=XWWjbzDi7Mvu03gK3h9N0F6PQWjFqgdB4GicbfniNPW+FMTlu4Cbwy9XG/v2OkzOJR 0f5MmUOUCe1l6SiIXH4kMTuOQIefP0vGuE1JF1UqR9tWlppdH1OB1OsZsnAMqIJdIgLv 8uowE8Lq6QzweKM13/poQAh0pIxljg0YtQJzMk6vfjzzluyHQ3IBzgTvlnX2DqbP7Wga +BGnVUywF3x+gYUwRI77pLsI8bXGL69ij6N5Yyomtf+rpfFILxcPT8r39urY51l4XbDu 1lXUslFhibfc7uz1zsZyt3AIoKLT32wFBy6f2p/r7WTz6qheG3gGVkLs7vLdOpmXN5r5 aweA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717343043; x=1717947843; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZwBGTiJPesWN/i1o69j2rKckXyAspOufdr1v3pOiZMk=; b=lIe/DQjwizkDGjaBAaTLCJ585Ppd4SPx9tMplEuz6DwfQvs/1weYr6ExZ6oFf8Nvsb yLbIsYDu13RSMqvvXRW/1dJcYS9tjFFKvlG7OezqMsDlDUOloSGTM6v4TwIa+NwOi4PU 0hMbERdIKlrrQh8OBLqDPikvUiK7r//focTE+fxEqjAhEd2ykfqnghrD0ZoJF7x9C/An i3Sozc+CVwqdiXFbPoCEnUtKmq+JjL9+RgrVuDnybKI95kjuWAK1131FdlzBqjjJm7Sa T8eEBGhgp6V3M6MEK4uffiTLHMi7YlUTYErGW1YPoBk0l2Ftyaw9Yuj0gTIHVq0IOoRZ xf7A== X-Gm-Message-State: AOJu0YwYuIXxyRl1BIKo7eMr9BzlANEkwzfdOef2UYUDHpl6oSYo6ZHS FiI7QoxdVdrRlR9XNTYJ+4F3wg6Wn3ej4y4C8gYPuVp58TArzWWXekVyIA== X-Google-Smtp-Source: AGHT+IHXjqqxhBycNPkXZc1CWsDJ9C/WvpVKem7MkenKgMtyo5bbupzuH0d7eUW57gMB5V6sktBKUA== X-Received: by 2002:a05:6214:4189:b0:6af:b99f:f2f4 with SMTP id 6a1803df08f44-6afb99ff6a0mr12297426d6.1.1717343042739; Sun, 02 Jun 2024 08:44:02 -0700 (PDT) Received: from gmail.com (12.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.12]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6afbf338bddsm2179056d6.25.2024.06.02.08.44.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 Jun 2024 08:44:02 -0700 (PDT) Message-ID: <4542d34a-8387-4c7e-aeda-52ef28f8ed8b@gmail.com> Date: Sun, 2 Jun 2024 17:43:59 +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 v3 5/6] test-terminal: introduce --no-stdin-pty From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Dragan Simic , Jeff King References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> <199072a9-a3fb-4c8d-b867-b0717a10bacc@gmail.com> Content-Language: en-US In-Reply-To: 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 in 18d8c26930, that copies the stdin to the child process, does not always manage to transmit all the input data. To illustrate this behavior, we can use a function like this: send_data () { 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 send_data; done | sort | uniq -c 36 0 4 1 53 4095 7 4159 None of the executions have successfully transmitted the full data. If we do the same with a version of t/test-terminal.perl 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 send_data; done | sort | uniq -c 100 10000 In a subsequent commit, we'll introduce a new test that depends on t/test-terminate.perl. This test does not require stdin to be connected to a terminal; however, all data piped into the process must 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 Jun 2 15:44:35 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: 13682923 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 0718D17736 for ; Sun, 2 Jun 2024 15:44:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717343079; cv=none; b=k7AsNz2jzpPU2HflpLPPayWxma7FYi0z/7yb62ePBEvwITvQYyHMoc+T4l1i/gM4efziLV4yzJA6vQmXh4YkfQ7Taw4QTWJpd/E4lO0MocRyKoqsj7kgs7In2VrchlA8y4wE0OxRz1LxMxE6HTABDZrTPFAGu0QGUyNVcqAGh98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717343079; c=relaxed/simple; bh=bSW15G3g+SVVHJ1OqiggnLfGMkln6BkL0AYO9jazQTo=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=drbCozaQ2MaBlQaqTgFCiJIZqie+P5v3AmKt+MARxcWtLrPPssM56GG/LETXQzAtzy7E8fjoFHK7PqO+PmG0YA//0dg5WN0OAVBRuArZV2UUf0MzAdUUw098WiCeaWeUs9qBQDCjh4rmgMM8StwjWLUxChQuiG0yKOC2AJrcgvo= 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=NWJymA/G; arc=none smtp.client-ip=209.85.128.53 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="NWJymA/G" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4213870aafdso5555685e9.2 for ; Sun, 02 Jun 2024 08:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717343076; x=1717947876; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=kuG14p4YsOmz2nPp1ARGD9Q25Fq/m9QJ8lN8+AvaEB8=; b=NWJymA/G0zD9ddZ5HHIHIlsmu9m9Nm5XdhXmdU7MnVpYeOboPnpOIH3TohrguSX5yR URAsxt4Bg7dACl+fvKJnpIXYARdwQq75mrr4x6G0yee6oxMpeSDyDB6+OB1jtvzGynfr uOv6mG/GS8vjQkoe0DSM/eXATQ18kznq6Z0RbWWvrJwMXfgAnRNGHYANq/ACQSHiVc8x A4ZJtfu/kgfIwp5ur3PgK4vjP+PB08mbnV4OFohEB09gxinHvwJ1ZIpjYxkOJB3CDuva jQhD0ZMFtBQRgLv3GaLAdhqyXK8qyQdO3BFn1XnwBkrX5dbWeb4FDockoyu9Rh30eqIj +NUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717343076; x=1717947876; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kuG14p4YsOmz2nPp1ARGD9Q25Fq/m9QJ8lN8+AvaEB8=; b=YYrWVvYKvo5awUBoyO6dY4p8eIlMPZj4I9P9UPpo4/Lp//QETVjVIn/pwTi6Wbv+Xa PeDTvi3M48r5pgXo94vqI2/LpRAPuovQY+UcrZvBp1bmYl7Uf085LP2bM1qi/A0Xejve rz0bARdeOz4dVM/AN9bb5pedLsPaIfZA5Wd2hkPTw6fAT8DvdVq2VTJWalu/riEldGSE /S823b6SrDt2xBLryIzhrcuGW5YujxgW4mdqMlgiRFcv3gvo4RxLKt0lvzOFs92IYxia aBFRw8tigEwCmPgAom0fD1cf0g2Xu6ULYrjGo4EWsbD8eRaH9oYZaC0LRsWtR8ZsXLCP v6ew== X-Gm-Message-State: AOJu0Yz+gEyRvYrTsvCIUx8YZYQSdh1zXDQgfY6HqaW3VkEcm7gvrcOP htFxlXVrKAqNEI8z3wgbU0Sgkqe/GAKR5gXlXDbvXR8qSKLKpLTICy/Cww== X-Google-Smtp-Source: AGHT+IGHAHpe85N5helGdkxomKXkpKeQyrAI1hsBioogm0PJHBX5ugzkJfqaCUUTjLq7dwWPgrR2+g== X-Received: by 2002:a05:600c:4e52:b0:420:2986:ccee with SMTP id 5b1f17b1804b1-4212e0a5363mr57263145e9.30.1717343076188; Sun, 02 Jun 2024 08:44:36 -0700 (PDT) Received: from gmail.com (12.red-88-14-51.dynamicip.rima-tde.net. [88.14.51.12]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4212b8a4c88sm87423205e9.31.2024.06.02.08.44.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 Jun 2024 08:44:35 -0700 (PDT) Message-ID: <8dbbfd1d-0e74-4423-9c8b-3a40df3b78c1@gmail.com> Date: Sun, 2 Jun 2024 17:44:35 +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 v3 6/6] add-patch: introduce the command '|' From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Dragan Simic , Jeff King References: <1d0cb55c-5f32-419a-b593-d5f0969a51fd@gmail.com> <199072a9-a3fb-4c8d-b867-b0717a10bacc@gmail.com> Content-Language: en-US In-Reply-To: Introduce a new command: '|', to send the current hunk to a program. If no program is specified, default to the pager. Signed-off-by: Rubén Justo --- add-patch.c | 17 ++++++++++-- t/t3701-add-interactive.sh | 55 ++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/add-patch.c b/add-patch.c index 814de57c4a..5a586d1b9b 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" @@ -1389,6 +1390,7 @@ N_("j - leave this hunk undecided, see next undecided hunk\n" "s - split the current hunk into smaller hunks\n" "e - manually edit the current hunk\n" "p - print the current hunk\n" + "| - pipe the current hunk to the pager, or | to use a program'\n" "? - print help\n"); static int patch_update_file(struct add_p_state *s, @@ -1401,6 +1403,7 @@ static int patch_update_file(struct add_p_state *s, struct child_process cp = CHILD_PROCESS_INIT; int colored = !!s->colored.len, quit = 0; enum prompt_mode_type prompt_mode_type; + const char* pager = NULL; enum { ALLOW_GOTO_PREVIOUS_HUNK = 1 << 0, ALLOW_GOTO_PREVIOUS_UNDECIDED_HUNK = 1 << 1, @@ -1449,9 +1452,15 @@ 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) { + if (pager) + setup_custom_pager(pager); render_hunk(s, hunk, 0, colored, &s->buf); fputs(s->buf.buf, stdout); rendered_hunk_index = hunk_index; + if (pager) { + wait_for_pager(); + pager = NULL; + } } strbuf_reset(&s->buf); @@ -1485,6 +1494,7 @@ static int patch_update_file(struct add_p_state *s, strbuf_addstr(&s->buf, ",e"); } strbuf_addstr(&s->buf, ",p"); + strbuf_addstr(&s->buf, ",|"); } if (file_diff->deleted) prompt_mode_type = PROMPT_DELETION; @@ -1512,8 +1522,8 @@ static int patch_update_file(struct add_p_state *s, continue; ch = tolower(s->answer.buf[0]); - /* 'g' takes a hunk number and '/' takes a regexp */ - if (s->answer.len != 1 && (ch != 'g' && ch != '/')) { + /* 'g' takes a hunk number, '/' takes a regexp and '|' takes a program */ + if (s->answer.len != 1 && (ch != 'g' && ch != '/' && ch != '|')) { err(s, _("Only one letter is expected, got '%s'"), s->answer.buf); continue; } @@ -1674,6 +1684,9 @@ static int patch_update_file(struct add_p_state *s, } } else if (s->answer.buf[0] == 'p') { rendered_hunk_index = -1; + } else if (ch == '|') { + rendered_hunk_index = -1; + pager = s->answer.buf + 1; } else if (s->answer.buf[0] == '?') { const char *p = _(help_patch_remainder), *eol = p; diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 6f6d174687..7b3ebb671d 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -64,8 +64,8 @@ test_expect_success 'unknown command' ' git add -N command && git diff command >expect && cat >>expect <<-EOF && - (1/1) Stage addition [y,n,q,a,d,e,p,?]? Unknown command ${SQ}W${SQ} (use ${SQ}?${SQ} for help) - (1/1) Stage addition [y,n,q,a,d,e,p,?]?$SP + (1/1) Stage addition [y,n,q,a,d,e,p,|,?]? Unknown command ${SQ}W${SQ} (use ${SQ}?${SQ} for help) + (1/1) Stage addition [y,n,q,a,d,e,p,|,?]?$SP EOF git add -p -- command actual 2>&1 && test_cmp expect actual @@ -348,9 +348,9 @@ test_expect_success 'different prompts for mode change/deleted' ' git -c core.filemode=true add -p >actual && sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered && cat >expect <<-\EOF && - (1/1) Stage deletion [y,n,q,a,d,p,?]? - (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,p,?]? - (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? + (1/1) Stage deletion [y,n,q,a,d,p,|,?]? + (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,p,|,?]? + (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,|,?]? EOF test_cmp expect actual.filtered ' @@ -537,13 +537,13 @@ test_expect_success 'split hunk setup' ' test_expect_success 'goto hunk 1 with "g 1"' ' test_when_finished "git reset" && tr _ " " >expect <<-EOF && - (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? + 1: -1,2 +1,3 +15 + (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,|,?]? + 1: -1,2 +1,3 +15 _ 2: -2,4 +3,8 +21 go to which hunk? @@ -1,2 +1,3 @@ _10 +15 _20 - (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_ + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,|,?]?_ EOF test_write_lines s y g 1 | git add -p >actual && tail -n 7 actual.trimmed && @@ -556,7 +556,7 @@ test_expect_success 'goto hunk 1 with "g1"' ' _10 +15 _20 - (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_ + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,|,?]?_ EOF test_write_lines s y g1 | git add -p >actual && tail -n 4 actual.trimmed && @@ -566,11 +566,11 @@ test_expect_success 'goto hunk 1 with "g1"' ' test_expect_success 'navigate to hunk via regex /pattern' ' test_when_finished "git reset" && tr _ " " >expect <<-EOF && - (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? @@ -1,2 +1,3 @@ + (2/2) Stage this hunk [y,n,q,a,d,K,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,?]?_ + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,|,?]?_ EOF test_write_lines s y /1,2 | git add -p >actual && tail -n 5 actual.trimmed && @@ -583,7 +583,7 @@ test_expect_success 'navigate to hunk via regex / pattern' ' _10 +15 _20 - (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]?_ + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,|,?]?_ EOF test_write_lines s y / 1,2 | git add -p >actual && tail -n 4 actual.trimmed && @@ -595,17 +595,38 @@ test_expect_success 'print again the hunk' ' tr _ " " >expect <<-EOF && +15 20 - (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? @@ -1,2 +1,3 @@ + (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,?]?_ + (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 TTY 'print again the hunk (PAGER)' ' + test_when_finished "git reset" && + cat >expect <<-EOF && + +15 + 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 \| | + ( + 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 'split hunk "add -p (edit)"' ' # Split, say Edit and do nothing. Then: # @@ -780,21 +801,21 @@ test_expect_success 'colors can be overridden' ' +new more-context +another-one - (1/1) Stage this hunk [y,n,q,a,d,s,e,p,?]? Split into 2 hunks. + (1/1) Stage this hunk [y,n,q,a,d,s,e,p,|,?]? Split into 2 hunks. @@ -1,3 +1,3 @@ context -old +new more-context - (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? @@ -3 +3,2 @@ + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,|,?]? @@ -3 +3,2 @@ more-context +another-one - (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,?]? @@ -1,3 +1,3 @@ + (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,p,|,?]? @@ -1,3 +1,3 @@ context -old +new more-context - (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,?]? + (1/2) Stage this hunk [y,n,q,a,d,j,J,g,/,e,p,|,?]? EOF test_cmp expect actual '