From patchwork Thu Jul 25 13:44: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: 13741953 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 30A691990BB for ; Thu, 25 Jul 2024 13:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721915061; cv=none; b=gwHMzYTbY0JAtt/Rx0wmdpmyEKazvDoEjcR8wgGklbPQBGgx6jIStoXOHtzGqeaNJy8XGVj6Db9KHH9Ihitf+fxCKhxxExQUILVtWSCJMyTWyT+4Yo6Vt2EpVWPf5/y/APboe4Sn1coahJS+xp9uo5adOG1sznsdC+SKOaOHV1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721915061; c=relaxed/simple; bh=ekjA+5nfr5BnZDcwU4iYsUAetNlUUOFC9Q6qOpKcfQ8=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=V3/w/brfxbVihmlVFZVQYpuCazNd88W+dcSURx2APFq5jo/bVZ+rIp46IAy8qHCZvpTazlEpFNRuxKyDiOw7u9E6XQS/QvkVCC4w76d1VfJkS3nggYv6Ngnb/S5xEHfmCGNq4HaHxmpLfIHtxe/cz2j1nstDkCGCU9l9i89w0JA= 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=cAOY48//; arc=none smtp.client-ip=209.85.128.54 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="cAOY48//" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-42808071810so3936105e9.1 for ; Thu, 25 Jul 2024 06:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721915058; x=1722519858; 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=s/HXjMl+rhCQ/YfNOxW8zJoKTIGb+SOaFy0lDgLRpp8=; b=cAOY48//SGFXnJZfxlj1FzFav9768rfK54/aLMV+/AVH0VNrgkhB/C5bvqvfi7bult u0A93ajpB5l8IFXjB17ULDLWV2K3pA6lR66kqiPaUk5jF1CGVl6PPBarcoUFNxWYQ5Bp E7xC3T97EAxMboPL3QeYM9pQqd3Ql4+bRQVHXK+9FdDA6KFyT8O/hgnq6Dpx3wZ2oy0Q l7K22qKIRurFK/eUDCYzH6g+edeEPCZ4OLhKO2FtqAIqx0KG5Qu2esh5UhpiECCDG4ue ESBaJR8b1ufIEtmkhA0p6qhp+OCljH70c2YNbxlt+fsOKndW2vicASsWQkNHEUI6gr8I 1imw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721915058; x=1722519858; 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=s/HXjMl+rhCQ/YfNOxW8zJoKTIGb+SOaFy0lDgLRpp8=; b=fa68P3E7/9QNfqJX3BJoIPf7OC17KHEFXvzW6kUeGh1nvVIogQkpA6fJ7q5lJDpt0H pX15lh3qIWlR+7RFYJ93ND6gbgtRyOJPou0e7wMmwSeZflPREdJpEQR37qHvUFUoEQ/0 u6S6f23ZC3FvcGnKEDCN4kNVSsEGsvcbXCJ9rgavaZwfJOFw4nbI/yynr24hbEh/WW3X 4TBFporOmsufrGwYwAhP57eTxJhkLnzbmXw0zHW51ibdBbF8N05rMRSlrh2C1JpcTXZS zsN3x/WOJxAZ0saUAWYoSlsMQ6lHUGGJAa2EKsB90OfeBeL5JaCEbygmA47mWXIP0DH3 Aizw== X-Gm-Message-State: AOJu0YzyFqiAuogwoLr8D6bNmAbNIYDQjAlDR22ecetq4HFe2ZajFM1y Xz+V53Rvy1BtOTU2J4xiqj4nuWhAC3QPHpeGbWGcH/kqTYT3zbOykpoA5A== X-Google-Smtp-Source: AGHT+IHHkEwFSbvBQT7dlYHy5LsEL2DecYhSSX4Bfi4OTKZYEJ67VBOKNFpRR2JrM4ERT6GQSFYwQg== X-Received: by 2002:a05:600c:4f54:b0:426:554a:e0bf with SMTP id 5b1f17b1804b1-42806b8e4c8mr14057515e9.16.1721915058130; Thu, 25 Jul 2024 06:44:18 -0700 (PDT) Received: from gmail.com (155.red-88-14-47.dynamicip.rima-tde.net. [88.14.47.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-428057a69c4sm36418555e9.33.2024.07.25.06.44.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jul 2024 06:44:17 -0700 (PDT) Message-ID: <57073ffc-65ab-48eb-9517-964a6f5141fd@gmail.com> Date: Thu, 25 Jul 2024 15:44: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/4] add-patch: test for 'p' command From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Phillip Wood References: <7c9ec43d-f52f-49b7-b1f3-fe3c85554006@gmail.com> <62af789f-ca19-4f11-9339-a97400f7e70c@gmail.com> <2333cb14-f020-451c-ad14-3f30edd152ec@gmail.com> <5735bee3-0532-4894-b717-12a0bdcb9e84@gmail.com> <97902c27-63c9-4537-8ebe-853ef0cb1d3b@gmail.com> <88286ad9-eab7-4461-a407-898737faa6a1@gmail.com> <76936fb1-446d-455f-b4e7-6e24dda3c17d@gmail.com> Content-Language: en-US In-Reply-To: <76936fb1-446d-455f-b4e7-6e24dda3c17d@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 Signed-off-by: Junio C Hamano --- 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 5d78868ac1..6daf3a6be0 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -575,6 +575,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 Thu Jul 25 13:44:27 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: 13741954 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 7A96B19B3CA for ; Thu, 25 Jul 2024 13:44:30 +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=1721915072; cv=none; b=ZNr52R5mQSI3SO1S1VD1Q5ckKE0/xqI6JCK6elxTZIS0OwAIE0OXaZ8h5z8tBlPNIpxzcXhY6mtIxlvCj0j0aQuAwaGLlcInKmnWHgTeW4MkutlOrGmizKavg8lN6DI3tFtO8ooHELAuDrMlbInYP6xmiTRcbDwCZfPbFN/TjWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721915072; c=relaxed/simple; bh=qO0zp2sajpSo7snyeg5+wqxrL7sLpkRojyksEyYz7B4=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=K1OQve5u1rWpCTHomcZo9cW/pdt8fovm8pLMdSj8vWY+Cj+Ws7TRCJh9jX21bhdsczY7Tne/po+ZE4hlWgkSw3rOuiR47q3Cq97wQsID+V+rkVlxAzMiC0bbH0pusz+o63AAX9Tb6Bo2bFHZR+jR+IylRV3uuHWfpNS9d4Q+EkM= 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=BintvxIQ; 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="BintvxIQ" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-427db004e36so7132565e9.3 for ; Thu, 25 Jul 2024 06:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721915069; x=1722519869; 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=b5EsJ/8liA9vP6t8q9qXTgn2RsycUOxh9cPdMz/fToE=; b=BintvxIQPYtQ+YV7drcNyglNEACy8CZo4UIkH9I3OeAe2WUl4Q+AY/asrYP+4oGpH7 2y2k0zm6RB8Y1CRyOX2p1bFRHxgbse0D2mTTbZwVtkTbLnHWXw+TZzhjADw2/4MdbhQY mxrsgj4jcFH1XVBvs7iqPkuCpU70KGY9Y+7FHL6i9W1sLeG+XuJIAv+jPcO193zlgHGP 5eTHEfVUilX0E8IT5YOF7JUvlsKp066l3wWVKlfGhjqHdjYrhAdRsGn6PAdOT9BUzJPV BouuqAGlCJ1+zP6dbQX8TdavOe7wD/jbnq7SG1FQKwkg/KY+v5ZaJEOu3DORokHeOewM MEqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721915069; x=1722519869; 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=b5EsJ/8liA9vP6t8q9qXTgn2RsycUOxh9cPdMz/fToE=; b=dl9swh6z8wmo6Vni+rJjgLfIA6LVAHiK5D97CF8KpgasIM6atPMrGEPsIZoynofcos j/xodNG1nWfqCKPdi/IZbOHBs02UKcqWwAeX2pUz2MpXPizDi8c+itOKQTOOizDertLK oK3HQoGPlokcfpuLaKI3YYN25UfKFu6C0rEH5tUpWzIeRZl7wtrloipKq4UvP8DQ4D9l rjMK0RS3dTOGDPc98vAGv6lTH0kg8qO/Bh1znGmeDfORd7itf3l24gjzMt9bUYI2biiN WW+hqdc3kdbG6sMUuNAwBC8+HulhcqYomImmjlzfuYUByhIIa+yNSaj042r952edlxap AmmA== X-Gm-Message-State: AOJu0Yz1cWJT4GO5L6NEPGa5URO9nA5i/paA2dLrfsB6P8DCZcRUjjTc UAPCkbryDi+HrGBcNLghSSkNjk+oObOHKlMeaylZDYROCoA0AOfJdBkUpA== X-Google-Smtp-Source: AGHT+IFJqGzR8QTWsjbl6DG+kB4ua0qwFS1tS0b5MxJ+NQFva2UpwG5wVluHzYNiXk9lHc5buwmM+w== X-Received: by 2002:a05:600c:1c99:b0:426:5cdf:2674 with SMTP id 5b1f17b1804b1-4280546deb8mr18963025e9.4.1721915068734; Thu, 25 Jul 2024 06:44:28 -0700 (PDT) Received: from gmail.com (155.red-88-14-47.dynamicip.rima-tde.net. [88.14.47.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427f93594b6sm78901695e9.5.2024.07.25.06.44.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jul 2024 06:44:28 -0700 (PDT) Message-ID: <3fcb30a2-8a97-4b34-aa3d-b19ee54dc97e@gmail.com> Date: Thu, 25 Jul 2024 15:44:27 +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/4] pager: do not close fd 2 unnecessarily From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Phillip Wood References: <7c9ec43d-f52f-49b7-b1f3-fe3c85554006@gmail.com> <62af789f-ca19-4f11-9339-a97400f7e70c@gmail.com> <2333cb14-f020-451c-ad14-3f30edd152ec@gmail.com> <5735bee3-0532-4894-b717-12a0bdcb9e84@gmail.com> <97902c27-63c9-4537-8ebe-853ef0cb1d3b@gmail.com> <88286ad9-eab7-4461-a407-898737faa6a1@gmail.com> <76936fb1-446d-455f-b4e7-6e24dda3c17d@gmail.com> Content-Language: en-US In-Reply-To: <76936fb1-446d-455f-b4e7-6e24dda3c17d@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 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 Signed-off-by: Junio C Hamano --- pager.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pager.c b/pager.c index be6f4ee59f..251adfc2ad 100644 --- a/pager.c +++ b/pager.c @@ -14,6 +14,7 @@ int pager_use_color = 1; static struct child_process pager_process; static 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 Thu Jul 25 13:44:39 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: 13741955 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 66712199386 for ; Thu, 25 Jul 2024 13:44:42 +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=1721915084; cv=none; b=FwMyBwR4rGs0J5UclYoXSJNVwNZ8sWXrBrEv/k1i7yQaGfL/aoKDmf7xLyWaVeTXl7+HzJfwGd0fUrVJzn6IBeDHVnt52PABDMyF81XS/QrHAO3C6f3cIgifPqW+Gp6f9JnAuZEfsNdPF5/ZOWxzER5XDv6P8kA3QzFpvPgbIgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721915084; c=relaxed/simple; bh=Omf/eaV5LL5iuQcAXAPsgxBSSP9sAiaZ8oHmHevmAL8=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=A8hISVztMS/CegyqrfBWbEy7b8GqPp0Lwg3Vbcs8MOnSFeCGBykkBec87w3XtvOGmZv+/Cgj5098kWUq0YSDSdXTajqODp2euxUFJlZTqyqQRttbocCxCIFfzrwulcOD0uVZSR0+BEy5ww61NqJB7fd9fYHsGpX58JUHE1njI/4= 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=QdcYxAJO; 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="QdcYxAJO" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-427b9dcbb09so7153705e9.3 for ; Thu, 25 Jul 2024 06:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721915081; x=1722519881; 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=2OT0opVs5PMG17etEgNDPC4DiGev5Ba7/9NVk+bnF54=; b=QdcYxAJOCvWukwC1ZhwNkw0EoRRnkbGaA1MYkU4vmolx6XrlfrQNuF9g56PEkefaYT fXQmITkOYJVyqvafbNID6qEJIrlxSMIUQ0ZLzotMacJqptaZpIu4z7+wTi8DtCoYa+jG oCd3QHXmwMmDBSVkZ+dWYL7UaOff25bZ31yGqAB2p6mjgRCDZ2jFc76HJNi0fFiI7LXY 93oF47NTN7VMI05ooaBxB+Hnjmsqqttqd9Jk73Y4BwYWeNqCBw9dWAcD0/RVc50rMY5w ZbtfP5O1vUidcS3IutLPXv6xmoi4iruFyENIMFNS4pCMsFtJobEikRGJSXuZg3HpIUdr TIQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721915081; x=1722519881; 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=2OT0opVs5PMG17etEgNDPC4DiGev5Ba7/9NVk+bnF54=; b=BM4Cq+A+3dkhLqYE3zTAdMOSJ6d8XWAmiOBGCn414MoXCX08IPiQtUjlLSXUWkwN2G QjQimTiuwoPJJ2vzUO0sxMbco2ESAx3RAaChjRku10Nt/z1g/fOQIQ1E7EgAYphE2Nfi Qagwyx0N/7jXgmbeB3v1TYrntRHRGQ3y8Q1Y7Wsv68dJ1qPTpdEl7xkhlibHOIrFO72l 8qmnKnk48wN2d88oIQ5qd4k6aoG4wjIYmJnWR8bYzO40i/kSLST8f/OaBV9EA1tQlf1l EME0sf7JbMwgNJek39FF8xl1VW8znQ6zrD7lFYFtLtCPJBuw2kG/fsWPOsxLyMz1B8l9 v6bQ== X-Gm-Message-State: AOJu0Yy0mvv5PH8L2KdS9baAzJbjGV5A90yqad5YAEe6OAytUxHRpKLg 6FM+rjdt3AVP3igGld9qT/naqVnWBQQTxPf/3pHHmGmIqlFUe2hemnsIOg== X-Google-Smtp-Source: AGHT+IFlb9dN2Y9c9J+snS4g9S6uNjAVd/kYtVLuKC4AxVufQEa63WwVwpLYuzWrsnnfIVNiDwouyQ== X-Received: by 2002:adf:e810:0:b0:367:434f:caa2 with SMTP id ffacd0b85a97d-36b35ff1e21mr1373824f8f.0.1721915080731; Thu, 25 Jul 2024 06:44:40 -0700 (PDT) Received: from gmail.com (155.red-88-14-47.dynamicip.rima-tde.net. [88.14.47.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b36857dcesm2251332f8f.85.2024.07.25.06.44.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jul 2024 06:44:40 -0700 (PDT) Message-ID: <934b8247-a5e7-4919-8ccb-08ceb23c03ff@gmail.com> Date: Thu, 25 Jul 2024 15:44:39 +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/4] pager: introduce wait_for_pager From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Phillip Wood References: <7c9ec43d-f52f-49b7-b1f3-fe3c85554006@gmail.com> <62af789f-ca19-4f11-9339-a97400f7e70c@gmail.com> <2333cb14-f020-451c-ad14-3f30edd152ec@gmail.com> <5735bee3-0532-4894-b717-12a0bdcb9e84@gmail.com> <97902c27-63c9-4537-8ebe-853ef0cb1d3b@gmail.com> <88286ad9-eab7-4461-a407-898737faa6a1@gmail.com> <76936fb1-446d-455f-b4e7-6e24dda3c17d@gmail.com> Content-Language: en-US In-Reply-To: <76936fb1-446d-455f-b4e7-6e24dda3c17d@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. One specific point to note is that we avoid forking the pager in `setup_pager()` if the configured pager is an empty string [*1*] or simply "cat" [*2*]. In these cases, `setup_pager()` does nothing and therefore `wait_for_pager()` should not be called. We could modify `setup_pager()` to return an indication of these situations, so we could avoid calling `wait_for_pager()`. However, let's avoid transferring that responsibility to the caller and instead treat the call to `wait_for_pager()` as a no-op when we know we haven't forked the pager. 1.- 402461aab1 (pager: do not fork a pager if PAGER is set to empty., 2006-04-16) 2.- caef71a535 (Do not fork PAGER=cat, 2006-04-16) Signed-off-by: Rubén Justo --- pager.c | 46 ++++++++++++++++++++++++++++++++++++++++------ pager.h | 1 + 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/pager.c b/pager.c index 251adfc2ad..896f40fcd2 100644 --- a/pager.c +++ b/pager.c @@ -14,7 +14,7 @@ int pager_use_color = 1; static struct child_process pager_process; static 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,11 +24,11 @@ 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) +static void finish_pager(void) { fflush(stdout); fflush(stderr); @@ -36,8 +36,37 @@ static void wait_for_pager_atexit(void) finish_command(&pager_process); } +static void wait_for_pager_atexit(void) +{ + if (old_fd1 == -1) + return; + + finish_pager(); +} + +void wait_for_pager(void) +{ + if (old_fd1 == -1) + return; + + finish_pager(); + sigchain_pop_common(); + unsetenv("GIT_PAGER_IN_USE"); + dup2(old_fd1, 1); + close(old_fd1); + old_fd1 = -1; + if (old_fd2 != -1) { + dup2(old_fd2, 2); + close(old_fd2); + 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 +142,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 +172,20 @@ void setup_pager(void) die("unable to execute pager '%s'", pager); /* 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) { + once++; + 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 Thu Jul 25 13:44: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: 13741956 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 695401990BB for ; Thu, 25 Jul 2024 13:44:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721915097; cv=none; b=fPPoGEWncnx2IdFs9n7vRwNZpRv5CYL4pmH2nWdjqjc6ZVfZ/uYEjkMHx7Z1+ep7PMp7Q2ltgQJFlOxqxGnSvlEG3BOyIkViwkj0ufVYuMiPo/SAnV3DYySm1JwioKhlAL+i3Pv2a2ZzJQ1Mnz2bDZjEECgp4lnW7acML9gG4eE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721915097; c=relaxed/simple; bh=GV734m9V7QNKWSGbLv1Vx8MnN+Z1vTqWLwb9IuSOTUw=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=V5NNctcSYVqS0Gu4r+goH4/V1Zoeh0O9nVKRGh9dIXrNj0Fqa16sRHh2MX4tK/MRML0pqT3vtsGdgqle5OksXKJdq9S8Ba8AulM57+WCZPUtNcQwtj+QjpSsIRs7a9ZvLF1ftGM0YfdR0Bq92tDTigqBA5Y8DUw/wXae5dAqt8s= 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=RuFeFXXM; arc=none smtp.client-ip=209.85.128.46 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="RuFeFXXM" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-42802de6f59so6775325e9.3 for ; Thu, 25 Jul 2024 06:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721915094; x=1722519894; 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=8Qc5AaGdblyDK7RC33GVsdYZ4Ocdj86kv+dUg9bCWmw=; b=RuFeFXXMJKzdC5Ru96Al8wFs6akJnCE8s0TXW2AMPjbPgdWhFf1gqJ2k5uHWqajdg2 rxsjdJq1E5C568xYTV9d3upnjWt+MGEWWC0ri9BT2yXuPqCfLoOVdgQcX2+40nSF/1GF ckPsjzU5P4QVprde9jqGBavejB+cO5U372kwaAudT6n4iwOIIPryVEtfuk6gj3IWf0lZ cnru58wxBxnK4V3vDzERWeksugzqOjWNFCY0HYyVlxXqUdEn/KIMkcCSbQkNljlIA3Yj rWX066J1mEGCkQSeUKQ4vw8o05JYT3SlAFtar6H9F80qznunNMJnuoRR5jL5Fn14Kmjm Ll6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721915094; x=1722519894; 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=8Qc5AaGdblyDK7RC33GVsdYZ4Ocdj86kv+dUg9bCWmw=; b=Ls6yiUSCTO1DSU/730haTn/1TUxSbli6R+dnCJ+5LQn7rltmIC6PRczSn1DokZibiU R5VoiMFiVJA8fI/+YFH/PECpY9YviCneAVlbdTviwhU9ffE6l4EWqGVaV2LnXeN+W5Xw DbcwlyEGIE8oIWJGRHLVvkIhhQBzjDgYjmOF+WrPFtzMbJpEdo7w/JlD4AuzjA4HQPdn XwFdwECWJzlVzGNK1UHq47ZuBUSHGxlzcJy6jJiSP3bdJy+MgHgP/g2u/is1srva+Wgg ADSywcj+mxd+1/wCcVGQyty10auwcdHgag9Swx/NaJ4YywQcHiXlROb2Y1V3zq3iVMjG ik7Q== X-Gm-Message-State: AOJu0YyVjM0q9KnT957Og0HjgOkCD8iBqduXj0QoECic3gu2Di0dI/Zx d4o2bm72jZulU4Rt20C8atgCCrfUX+Y0KBDWpomaUvD0zzKpg/coMTIvGQ== X-Google-Smtp-Source: AGHT+IH85M59zSyYQWduRo8/Fk+sf6H/5RhH4PZQyntQ5Xvby9mZcKPfj7yYhm65b+H7bQrxDQKmuw== X-Received: by 2002:a05:6000:1567:b0:369:b838:9155 with SMTP id ffacd0b85a97d-36b31b4cff9mr2564303f8f.40.1721915093607; Thu, 25 Jul 2024 06:44:53 -0700 (PDT) Received: from gmail.com (155.red-88-14-47.dynamicip.rima-tde.net. [88.14.47.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42805730d5bsm38459685e9.8.2024.07.25.06.44.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jul 2024 06:44:53 -0700 (PDT) Message-ID: <0c0cff56-d44b-4a95-809e-afdd219539aa@gmail.com> Date: Thu, 25 Jul 2024 15:44: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 4/4] add-patch: render hunks through the pager From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Phillip Wood References: <7c9ec43d-f52f-49b7-b1f3-fe3c85554006@gmail.com> <62af789f-ca19-4f11-9339-a97400f7e70c@gmail.com> <2333cb14-f020-451c-ad14-3f30edd152ec@gmail.com> <5735bee3-0532-4894-b717-12a0bdcb9e84@gmail.com> <97902c27-63c9-4537-8ebe-853ef0cb1d3b@gmail.com> <88286ad9-eab7-4461-a407-898737faa6a1@gmail.com> <76936fb1-446d-455f-b4e7-6e24dda3c17d@gmail.com> Content-Language: en-US In-Reply-To: <76936fb1-446d-455f-b4e7-6e24dda3c17d@gmail.com> Make the print command trigger the pager when invoked using a capital 'P', to make it easier for the user to review long hunks. Note that if the PAGER ends unexpectedly before we've been able to send the payload, perhaps because the user is not interested in the whole thing, we might receive a SIGPIPE, which would abruptly and unexpectedly terminate the interactive session for the user. Therefore, we need to ignore a possible SIGPIPE signal. Add a test for this, in addition to the test for normal operation. For the SIGPIPE test, we need to make sure that we completely fill the operating system's buffer, otherwise we might not trigger the SIGPIPE signal. The normal size of this buffer in different OSs varies from a few KBs to 1MB. Use a payload large enough to guarantee that we exceed this limit. Signed-off-by: Rubén Justo --- add-patch.c | 18 +++++++++++++++--- t/t3701-add-interactive.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/add-patch.c b/add-patch.c index 6e176cd21a..f2c76b7d83 100644 --- a/add-patch.c +++ b/add-patch.c @@ -7,9 +7,11 @@ #include "environment.h" #include "gettext.h" #include "object-name.h" +#include "pager.h" #include "read-cache-ll.h" #include "repository.h" #include "strbuf.h" +#include "sigchain.h" #include "run-command.h" #include "strvec.h" #include "pathspec.h" @@ -1391,7 +1393,7 @@ N_("j - leave this hunk undecided, see next undecided hunk\n" "/ - search for a hunk matching the given regex\n" "s - split the current hunk into smaller hunks\n" "e - manually edit the current hunk\n" - "p - print the current hunk\n" + "p - print the current hunk, 'P' to use the pager\n" "? - print help\n"); static int patch_update_file(struct add_p_state *s, @@ -1402,7 +1404,7 @@ static int patch_update_file(struct add_p_state *s, struct hunk *hunk; char ch; struct child_process cp = CHILD_PROCESS_INIT; - int colored = !!s->colored.len, quit = 0; + int colored = !!s->colored.len, quit = 0, use_pager = 0; enum prompt_mode_type prompt_mode_type; enum { ALLOW_GOTO_PREVIOUS_HUNK = 1 << 0, @@ -1452,9 +1454,18 @@ 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 (use_pager) { + setup_pager(); + sigchain_push(SIGPIPE, SIG_IGN); + } render_hunk(s, hunk, 0, colored, &s->buf); fputs(s->buf.buf, stdout); rendered_hunk_index = hunk_index; + if (use_pager) { + sigchain_pop(SIGPIPE); + wait_for_pager(); + use_pager = 0; + } } strbuf_reset(&s->buf); @@ -1675,8 +1686,9 @@ static int patch_update_file(struct add_p_state *s, hunk->use = USE_HUNK; goto soft_increment; } - } else if (s->answer.buf[0] == 'p') { + } else if (ch == 'p') { rendered_hunk_index = -1; + use_pager = (s->answer.buf[0] == 'P') ? 1 : 0; } 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 6daf3a6be0..1b8617e0c1 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -591,6 +591,38 @@ 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 && + +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 P | + ( + GIT_PAGER="sed s/^/PAGER\ /" && + export GIT_PAGER && + test_terminal git add -p >actual + ) && + tail -n 7 actual.trimmed && + test_cmp expect actual.trimmed +' + +test_expect_success TTY 'P handles SIGPIPE when writing to pager' ' + test_when_finished "rm -f huge_file; git reset" && + printf "\n%2500000s" Y >huge_file && + git add -N huge_file && + test_write_lines P q | ( + GIT_PAGER="head -n 1" && + export GIT_PAGER && + test_terminal git add -p + ) +' + test_expect_success 'split hunk "add -p (edit)"' ' # Split, say Edit and do nothing. Then: #