From patchwork Tue May 21 20:51:57 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: 13669729 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 D36BE763F1 for ; Tue, 21 May 2024 20:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324722; cv=none; b=XL94rVFKiR9teM5Ue2Gkf9qyVIfc343+joIgXjQCwPgSih51NKY+hnyXkptXlihHiwSShTaL2JijHJij1JAzvGpIoXyEB1CKD7Hb76xroXePssdFW1NFkCZ+9w1hb+UPPH7Nb4hQAPO7PKJI0FXhU4oie2zylECL6fCInynpUGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324722; c=relaxed/simple; bh=9JXe4OF6h3NUBcKa5WGvNjG44DdH1oRSnt5Wp8XYDks=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=bMAHy5bzg08KJT9GnMrqxVcrnr29GH4VvJBM/TObY9KJLQkMl7nPOkt5nnSAedKVM1TWrJvxGunQY6/8u0DaQR7ByleIqNLvCXxES1VHFucq2VSNgjCCMWtvfvXtsQHQX7XllzI0AcPt/E7L0TUpfqs+MK8bIplLYKhcbXRrJzk= 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=DNXhQcOO; arc=none smtp.client-ip=209.85.221.44 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="DNXhQcOO" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-350513d2c6aso3236357f8f.2 for ; Tue, 21 May 2024 13:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716324719; x=1716929519; 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=ykT/gjqQXOzOatYggcHpFMqqS0nyStJOdNbom3DUM8A=; b=DNXhQcOOA+RSKz9WrBH6Dwm9Cz/llCbGl0Zdw9bP2IDXLcmnQrHajp0ZeSjrRqBiig sacyK0RmOrr5r+pTz9EcbXB8jQ3pNYAQGWiVVCzN7uR17NFmaCw9OV9UEwmoqBlFUPJw lhMwMS191D/YpNB0npMDQo67wb5P/UFLX7mDh9YxAsnTJqaOJLtinuS+mJ45o8OjhD6V NqDg+7J6WF/R4tOGKqDKmjbqyVT/ocZqQu1OxkvilgLoAuHx7SduJ994Eq6eqmVH8l2L OrlSPU4DHWyBrz+Z4aaUaXEDKz/aJgcYvJZn6Ry4DqDsVD4StQNuo6SD+ouOb//y95fN MhMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716324719; x=1716929519; 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=ykT/gjqQXOzOatYggcHpFMqqS0nyStJOdNbom3DUM8A=; b=EpGp7FnPGfnbkYoyr4riCrycLaYrTa5SlgPyjH6eTtx6Q7cPowaWfbzqaWywmYJ+fX wy1rM6bydNlG2Gn8L7s0Eg/De0byooYpH5MBIndHtbvA9PgnztZhjdUooaL5IevJ1I37 l1YbJLqKWtA3tOLKNqJJdSO1VF8XsVaqzkvCYP6KK9PKCEqE949sGeYnvVC1vH3ZMQoj GzA7NTKEZ9PlsQrLU82+wbDkwgVerxtNQEDduOD3GD0RvoZmp5MxWa0jDdrMhON/zx7z 6qRsoJ/TBJuCfDDxVC1/i77vUPOnJYXazZx7vLWCkcd1bUOZYp3N7Im1Bkirl8foqzlJ mImA== X-Gm-Message-State: AOJu0YyjsLEt9Yi0VK0Cnp4kxwyzgJg+mWwW70mlJ509b8pCEIFv7C6n Pp0dAt0y2fU7Yx/uma+8NOGk59oy1gSrfk9N7pq6ycVW6Hexgdq4MjOWpQ== X-Google-Smtp-Source: AGHT+IH81ILjfktYhu5w7Sie2eVX1snz9MCqBre6Fg4uTCkPO0ByZjF/PqBYZkJmmScDuHwfO2MzMg== X-Received: by 2002:a5d:4537:0:b0:343:efb7:8748 with SMTP id ffacd0b85a97d-354d8dafc70mr30759f8f.66.1716324719057; Tue, 21 May 2024 13:51:59 -0700 (PDT) Received: from gmail.com (96.red-88-14-210.dynamicip.rima-tde.net. [88.14.210.96]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502b8a791esm32712389f8f.64.2024.05.21.13.51.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 May 2024 13:51:58 -0700 (PDT) Message-ID: <89511733-fe62-44ec-bb27-106c3d8b798a@gmail.com> Date: Tue, 21 May 2024 22:51:57 +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 v2 1/5] 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: <199072a9-a3fb-4c8d-b867-b0717a10bacc@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 Tue May 21 20:52:07 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: 13669730 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 7719A763F1 for ; Tue, 21 May 2024 20:52:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324732; cv=none; b=j0VtSdzbdHmmYAN8YQInR+ZWvfNxzrTbTz22EmGWAxq1iVejj+lkGy4SF6h08V9sHi+rT9KJwC/a6CbnGvSBJwqZjos2KHaBI/k6jV4RfZWX8BiIBzqpxpE6E/CbKQl+XqZv+TP3Gu2BpsdrRICZBwhVuMnQaGXqGluj/jCQZMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324732; c=relaxed/simple; bh=BNJ5T1JZd4+3KdiVVs+HIbFcw+mS1zdQIi4pe6WfMUY=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=gRh+IrlyTTKhtSL+AcvOWJkQRxb/QPtsUE3f+Rnw+1KKXwQpCrxifIYRtpL5CTdAULJG/cW1S+8kP4HNxH/f4ch2PIm35CUSBoROEizRk+j+QdO8Hz9hTd5H/TuMb0nWsSa3SNFgd5AHZ9u5HyE8oeRlhyijbd0/MDlnCcOSfro= 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=Up8SrkXk; arc=none smtp.client-ip=209.85.221.44 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="Up8SrkXk" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-34d7a32bdd3so95327f8f.0 for ; Tue, 21 May 2024 13:52:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716324729; x=1716929529; 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=Ln8cyu6a9BQrRItELhEb+T5yR/EqMX5oV9d9Tsbom+4=; b=Up8SrkXkegLb9Dq2wzvLNRBOJymlAw4169Lzvph28jjK0JIpML+vLCIbyYIiPvplW3 9gyvnkpyYgt/dydOij6iRapOtnmd5xoVYwBHkNxI3vsqYCcsFvhwQ+Myhh9Pi5vQeSlN YW/7HKkKICCaueuTm0bMwbnX2AiVxttxuy8LejV1RuNTu3ul4iv+1FZZdNEeQUQcR/8u k1yh9zpmQDuliK94HN0mZbLPDg3ICeZm9Ysl5+Mo+CQ5L+AG2mCm9YIDTsyY8HM/81Q1 ofkYY/VJqjTByTaEm+awM5EGRtOYjvrx0jBS4ftDQD2pyAUEO82zLhD2FHySnS3a7M+E u+xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716324729; x=1716929529; 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=Ln8cyu6a9BQrRItELhEb+T5yR/EqMX5oV9d9Tsbom+4=; b=KMIcs9o+e7HsDoEMbljlAxUpd0n69lm0InJNJtkAnOyeVvMykSQOy16MPkQp2E+qHM IfhVfwrdlFB9RDCqZIjiNAJTzPXCoARNUlkt5UfK9EARAiGQ2HJQAS6LukEV6X3AFxoO GdOh4qjKq/zH8Dmh59//B/hbOETz2np/9nbnFdfZew5X6udyhGSPPC8yZqb7mVxqgJu3 QA6iDXXz7Y3/ht8nV7V86y799Z3xENNYp8t15zXrsI9QRHP5rkNDIKpW6/lHJ9s8z4Wl av9KYgMVmUoq7PScKuJIMRw2ekAKJy0ShD0GFxn56jRTxO8gPGsugm1d2LmrgOz9lzK4 KvzQ== X-Gm-Message-State: AOJu0YzsftOtyXGjG3vj0U1MU/chn6mASYaPk+7pBPYRXsJi/B5+7xeM 86cUHuuJ2IyYe22NQeKTkZRdGikahxk+Wnq/Xc1/IIagA41FrNhwhiCIdA== X-Google-Smtp-Source: AGHT+IE9uKPee5aFXnBdMMXwy/KsXWR6XxWbf7VmtYiVc/7XwV8kaN8m1gAK7LVz4Kv3b50iV1H/Lw== X-Received: by 2002:a5d:4bc1:0:b0:354:4eb4:576 with SMTP id ffacd0b85a97d-354d8db4269mr30698f8f.70.1716324729000; Tue, 21 May 2024 13:52:09 -0700 (PDT) Received: from gmail.com (96.red-88-14-210.dynamicip.rima-tde.net. [88.14.210.96]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-351da4ad444sm15155276f8f.107.2024.05.21.13.52.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 May 2024 13:52:08 -0700 (PDT) Message-ID: <0a6c38fe-8feb-47c3-804c-44d8535a278d@gmail.com> Date: Tue, 21 May 2024 22:52:07 +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 v2 2/5] 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: <199072a9-a3fb-4c8d-b867-b0717a10bacc@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 comming 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 Tue May 21 20:52:18 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: 13669731 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 32620763F1 for ; Tue, 21 May 2024 20:52:20 +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=1716324742; cv=none; b=gRbd8RwhoT04hZ9r6436yeOl/Oe51dt+1DofL/JyxS9Gk8bddP5NwegQB5tUGEu6kqy1O1x5oTAuBuXfOcagbK/3Rz21/JRVuauQ9+1SNSrdyZtU6MkPOCeTx+aTamZ5TkvPvHSEp+7AtJHnlgrMOqZC94LIujr1iq7rg7Hsekw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324742; c=relaxed/simple; bh=iqBOs8DT9GaSkaqy3g+vIiVlfwVXtXCSUyAmyEaDm+Q=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=NTOe7t3qr9oXs1T8LWK0TU7ALYBWaX7+epa/i2dUYAWltM1vt9y2LZHM3601VLQ4WPooE5nke+EOdbgh3q8VqpjivZIqug4yQwW+aJkwd0K6lXbE4rlYmUrST/57VmNt8woo6YdEl6xF9j0Z+joZi4ifzt89EQGuGsSLKlzZ7do= 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=d/Iu9i8F; 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="d/Iu9i8F" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4202959b060so35482985e9.2 for ; Tue, 21 May 2024 13:52:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716324739; x=1716929539; 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=gjnudgJGmP4oQDQgLZzorRp/oTK/o7tt7fjnhkD2yds=; b=d/Iu9i8F6m9CH+jJZtr8Y3MshfRZh2UJFoHkLgpfZ8ItbqfROUp/LoHdHyAlyuDh4r ueQe3DcOFmSRCBt18HfC51z964N7zgVTF2FCLVn14luorh9fKn+nLYewCj9Ovxn/CsM9 oWqpavxsh5wg/GrfNdI6EKMzDdPvqmNiwYVUurLYDKBu8W7gndZsYZUZem7ISGjo7+Wn Uiee27m5Ps58qcV5FKpBqv3Cji4Xr9wGDLe5JUJ4D628JF9HrSidNWg6UWG//gd7QmHu 3GZvX5GLOdh8VHe+LBMhulIZ11FWYXrOh/qFlum3/8KjypqxBYGN24w5alByX7Zg/JBT S4YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716324739; x=1716929539; 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=gjnudgJGmP4oQDQgLZzorRp/oTK/o7tt7fjnhkD2yds=; b=HY/x2qNVFOK/yYisIRPAg0cIY2GH2zn4/iiG+rtOcawYZIhRqgXVWqc+pZxHkQ3x/V 1Skq7LcI+TfW0LgDoGRxB1uMS9oXSWbLpP1fpdMwAu3ipbMVDcdCzNhizgq5P7GgPBQb A8UTkwumdmoyO7QTe3IRzSafjmYch4u6ksfVCgkb+w02gpCQ+VHu4kJpezKRr2jgfcK9 pFN80WY52q168q10PLHlfWU6RV4lHVxjLTsdbcuNUXn56Sc4Ggu+mTjMixTImIWSQhab 6UN86O/YigNNYksxXy0MoOcL8m9NdNt+AMRtxpGk1maQp5pn37sXrCDMyZsCFMEwEivr Wf7g== X-Gm-Message-State: AOJu0YwZlHI2LeNSW1bhQBMlMB5WgMltA7PyvyOMToYOVjTlhTl5BasN zH+WrrlT5MvaMH9qoTGlAu5yh+hqvtIG1WCpVZohqtRAw9HcSoAZ1qNKRw== X-Google-Smtp-Source: AGHT+IGYBHZhvNU8y7PY0cI/7jigHzPLNPkdxrZF+f8n0lDruNZ3rc82a+mW47qIVio/3UdCouI8cw== X-Received: by 2002:a05:600c:35c1:b0:41f:3ee0:a302 with SMTP id 5b1f17b1804b1-420fd33ab20mr210975e9.30.1716324739517; Tue, 21 May 2024 13:52:19 -0700 (PDT) Received: from gmail.com (96.red-88-14-210.dynamicip.rima-tde.net. [88.14.210.96]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccfe15b6sm461738895e9.47.2024.05.21.13.52.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 May 2024 13:52:19 -0700 (PDT) Message-ID: <217c246b-2c28-4acf-8614-ce66ad345437@gmail.com> Date: Tue, 21 May 2024 22:52:18 +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 v2 3/5] 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: <199072a9-a3fb-4c8d-b867-b0717a10bacc@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 Tue May 21 20:52:26 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: 13669732 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 61F27763F1 for ; Tue, 21 May 2024 20:52:29 +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=1716324751; cv=none; b=cBVeic2y5AFDfanAEqeXimVnTmdha+x2DF2mLX2hU7bvRILZlfMJomMeBioYKfPH99UjqI1gKNAbKBB8JxNE8A2D1raz/KdxA1synYq/5fFKFf22haUdMrkxCISpOzItFlZKDR056nATXSQ5llqaXdIfFg/+y1nZYLC8AuApOmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324751; c=relaxed/simple; bh=gb+/IHrX+nEItntARH0D8QGG/1suD+WGB15Ml94S01E=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=qcRqcU0qqEoqhaqmzqLpfqzvoW95iliNdNI92KL1YlG/vTUEIj+mHpbKS3proM8KN9zCUiLrY2j75cBYgIff3x7etM5Q+5P/Lq/LwI717k1f2BocNAPNMt3eEZGHx+1feYm1E2U/TNFXDwDfjCa4nqR/YE9XC9TERqsc4FL6PwU= 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=gM2oFiht; 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="gM2oFiht" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-420180b58c5so1300065e9.3 for ; Tue, 21 May 2024 13:52:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716324748; x=1716929548; 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=BXKIuawax3P08yQl5Ba5LeEQdV70DNxfE80xfI7olmc=; b=gM2oFihtUIknYdPHbTO8rwtsTk5ozKpUFRqS6mGCEF04NhDglWUvq1z4mL0+ZuWlJC IDhL16njxn9xdlgkUkXPqaUqAnQqYyChxtlrJLmSj4tOArOwAduzR59onogf7iddhdrd Uaph+sMdG77uKblY0olUqNfgAE5nl5pHOKYLrUWkw57pYfy600X2gBz2P1ttaLJ2ztly 53DRxaUdI0gnSUOHQhbSQCl5GZt4Iz93YV9L7kUttwTjq8lnouA+V14Wxijbo5IHtB+V 4X8rLA06kwgJwA8p4LaLZGosNw9OV8k0OUYI145DR12ay9RVh0Du0wXPIH5krMiuH3Ot TD5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716324748; x=1716929548; 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=BXKIuawax3P08yQl5Ba5LeEQdV70DNxfE80xfI7olmc=; b=RW1J7N5a1HKPL+yBZ8sTYMsG4IVKJJXi8wkRNVfOTQZQLj7Jxbap5bF82edMP1LVeq KE5hFkp1uXm412kJtrNOjOTKm2humIVvPy8PM7/5ZZZejB7uPneAggQq1ufME34t3mcu PvWSUrd2gOcIDZq6JWuN4r5jP4TIys+e8pZvddmvkxapPljkawUNGONNV7NDkZejNyVR uIgjot98/T8cgDgyVqej+MYEgFpPhLCgzUnPSCVTD9TNSEKkC3Bo8s9RDVtYsIwj95xe 6KyXBgiwrIcuj7JIl8nUgOueP7YysawdNwsg0N0Gd7HlG/Cy27YkPQ/T0xRCbVrX3Rzf O8bQ== X-Gm-Message-State: AOJu0Yxv0bznCLAXiLD/5YW0At5CG69jv4N0Oi5rUd47Ls7pN7FZdmPp mEk4Ru1RkBl1yBp9fR34ckzxeh+KIQlo1LcWHqUfP2bfMMV9Tag8PnXzpg== X-Google-Smtp-Source: AGHT+IGrWVS7kVitd/Ezn+WN4KJja+m5W5cwB7jLn96p48E9WSb48gArDhDL9xLzZKdOn8SpZ/TsEQ== X-Received: by 2002:a05:600c:4f92:b0:420:fff:f4c9 with SMTP id 5b1f17b1804b1-420fd303360mr345685e9.13.1716324747782; Tue, 21 May 2024 13:52:27 -0700 (PDT) Received: from gmail.com (96.red-88-14-210.dynamicip.rima-tde.net. [88.14.210.96]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41ff7a840d2sm437479885e9.39.2024.05.21.13.52.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 May 2024 13:52:27 -0700 (PDT) Message-ID: Date: Tue, 21 May 2024 22:52:26 +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 v2 4/5] 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: <199072a9-a3fb-4c8d-b867-b0717a10bacc@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 behaviour, 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 Tue May 21 20:52:37 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: 13669733 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 61360763F1 for ; Tue, 21 May 2024 20:52:40 +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=1716324762; cv=none; b=nPlnfOXquKI98ciIkDA89TouuUaUDwi3F1TqDkp10gs0hn+NulXOc+/mTEGddLxynyhmxZ5VsTEwp/ko5GESfpWSpteAcYtSF4RGgBgmK0fPNF50U97rve7bWtTfOOSwZfCVyQRff13uf8ZriPf8wu2bhg43gSGHA+4rbp8qpeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716324762; c=relaxed/simple; bh=di+k1fBZdIpNofT0fGdJOTSFrmsio9qOLn9mGrQ2p0U=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=hcLTaNUZcGyDv6Gk/WfIIJTOF2aXqXYgjfb1KAXG2OCEpI5vYTKmTtFC99QghQdxIhZYnJBzBtOoM1oyHgdjMvY3jMZRr5O2TxCBHENn4UFYeCI7Alz3uI7vFUYTbrjBdMddjXE3d2vDJFn5qRFLSISuPhPym7Pi+64Q+bZ8dNM= 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=aLsqoSFR; 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="aLsqoSFR" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42011507a4eso1524225e9.0 for ; Tue, 21 May 2024 13:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716324759; x=1716929559; 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=lxuXLkqcksihuYPzwMC1S248HdLCp6a2jA8cJbjxLJw=; b=aLsqoSFRJMCo4DOYUQ8dUaVXcSFP71ZJ1vbQhKcPnp34YbJdVlWe904kUWJA1Qq5EJ 0K3IL9mjcPvJO9kNMJjMyMKySCSGeZhUcl6WV8HAknbwGyXRwZCAs2mtqNKR6YYRye9y 7COy5XKir2VgRWkOpuDh7FH3D7zL5siMoTVKmnxQk6dcOPykgzo6G7R9XIM2Osu7PcRd 4VTEDghMXAJIsSJeYThh0W1yVGI1fL6bMKYwsTxH1DPaTQ65JqdkPwty0B/OK0DtkxhI WUe99YpTX90GB79gYy4QaBQ2x8dIwxRwis5YFkuS2eaH/+IhdfiduA9ClsJddDGZIgMG +G3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716324759; x=1716929559; 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=lxuXLkqcksihuYPzwMC1S248HdLCp6a2jA8cJbjxLJw=; b=jjANqg2AtjDw6jeuV5fO+wq8c/zS0qK3wr0MCZeQ1QVb2NP8sS+KSyRTlw2XAV4N2G 5Rn/NmJ9FLegz4dkbj2dSpxWqtOl4LchfyQc4xOc3FDtJyUGeFI4rorxHr2me8iHccyC yfRwI7u+lsuQlUMBlfuaJAgnZsIYTZPA5fn0v7KEjidJMD00gkNwTV8gB187kLTQxO7N L2u8uYjx2FUacrRGRmI5KMeoMMdmBrvkFztcxetEeIXVy3+Nq0K9cnLVSTy1yXO1AI4V rx09XlvJO4O/Hyt0h3tySMO4syCxY0vFZ/S7T67OCfX/j8+soxK33eP4OnKXZNARPXHO fyQg== X-Gm-Message-State: AOJu0YwqlK0bA8BkfjOsYiu6FcwcgI6E5USXvfVJ+XtNY7ezm+PdRYoU H0OyZzzZLzz2yBntENPZYuxypCSn/whYroREONSAg3OOaHjn0Etk9i9G/A== X-Google-Smtp-Source: AGHT+IHvwO2VUwaq9ts8cOHwAl1Xl65SMh9YcDW0cYqvfWaJ5a/4IHv+rRiosKt2LQcjH1xqCOcSRg== X-Received: by 2002:a7b:c7c5:0:b0:41b:a301:f2f9 with SMTP id 5b1f17b1804b1-420fd34562emr193165e9.39.1716324758561; Tue, 21 May 2024 13:52:38 -0700 (PDT) Received: from gmail.com (96.red-88-14-210.dynamicip.rima-tde.net. [88.14.210.96]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccce73f5sm480482415e9.21.2024.05.21.13.52.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 May 2024 13:52:38 -0700 (PDT) Message-ID: <310a2904-681a-4bee-96b9-90a2dc107975@gmail.com> Date: Tue, 21 May 2024 22:52:37 +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 v2 5/5] add-patch: render hunks through the 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: <199072a9-a3fb-4c8d-b867-b0717a10bacc@gmail.com> Make the print command to trigger the pager when invoked using a capital 'P', to make it easier for the user to review long hunks. Signed-off-by: Rubén Justo --- add-patch.c | 14 +++++++++++--- t/t3701-add-interactive.sh | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/add-patch.c b/add-patch.c index 2252895c28..d614536cb2 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" @@ -1387,7 +1388,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, @@ -1398,7 +1399,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, @@ -1448,9 +1449,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 (use_pager) + setup_pager(); render_hunk(s, hunk, 0, colored, &s->buf); fputs(s->buf.buf, stdout); rendered_hunk_index = hunk_index; + if (use_pager) { + wait_for_pager(); + use_pager = 0; + } } strbuf_reset(&s->buf); @@ -1665,8 +1672,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 52d7830de2..4be7a14419 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 && + +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 --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 &&