From patchwork Sat Jul 13 16:29:00 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: 13732444 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 3527413959D for ; Sat, 13 Jul 2024 16:29:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720888145; cv=none; b=EXaBoftyT9dW+/MadrCIaReiZeJNGiUjbAT6MBdNmnNDjRaScarSvvKS3RsL4eqlet91WQANvRQCxxjkJNDMxRu60mz5k2uIJ9cqnDXuJuz6xetkn4QhWYZ8K4M/g11cDVfvah7MvaMVZR40c+Awr4GE2rX8WgJuYOa/WvI0w2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720888145; c=relaxed/simple; bh=u/mUbXoWse80an1cUQRtEGq3Am/K5ByZ+4HyhCEAyy8=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=pMV+zTY1PPl6FJ6X80sRQw+KhgINMpgLI4gjWs7u2Qn9+BmqL4pqxleyCosfN7zHZQy6I13yOU+J/HwRj0Ut5E4EmIv/TCO6on801il+Paj6BwrVCZ0elfWVwgkcuZZAwp61GHZt75XvKpYScQb5qp2iAQz/Y5w0PgI60l3r4/A= 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=ZKHIOYjs; arc=none smtp.client-ip=209.85.210.171 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="ZKHIOYjs" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-70b0e7f6f8bso2637719b3a.3 for ; Sat, 13 Jul 2024 09:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720888143; x=1721492943; 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=VJkjHzI21PObLvGWahoz1IagNeod6Y4+R9kwSZb2IIQ=; b=ZKHIOYjsaCXMYQkabLRhF6L/2+zl05WTrBABcIcFm19Nm2TQXZKLLDgZIOIRlg4ar6 rZDonr4w5cS1YN4PJ8jDX1SE/M6obTp6O8gWSsT3dzHNYY0j99M9CjwkQGOsx4b4LnML zz4iwj5KYrbhv0jC2jHyZy3LU6ed9ouvCjtypHXqta3c24+LoGsSQKxgL8AetJAiLRoP juUnvnhCyMWx93kxHGi/c7D8gaixjggOuK9h2XKKJSGhoAgLrxqhhXpYGPRgS55MXKNt u3fi17QI8A9w/LpSAYN8Dul7nAiFOrx97TsBHMaG1picTtHwQxUD6sBnEnnvr1H2jmr9 8l9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720888143; x=1721492943; 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=VJkjHzI21PObLvGWahoz1IagNeod6Y4+R9kwSZb2IIQ=; b=PTAMOXJfVIzTdv5uNOjnoeymy8IijMJCLczMVct7u4bUDfKw3ygV7S1+No5RLPeo2v 0T3HHNS9ncDKQqNli6D/E6penPxdH6/9Dy5/GEY5GViz/5VIBnw5wucuCfcC89l5mIRT LyE/qHGpj8fwmS0GL2gMhnlWelRyVCvAmeUIRvuUZqZEoEr56s5VBAmPehMz51pmxEOC JMnOCHiixisgb3OczQljpwLT9uRYDDCDYJMEvvHfHu2C729VuWBW4iZz9J3ogq5OCNKd M7C0hBGt5Mn0hqLsXjfEwAb7EkqtoIWa8LoQUBKXF7dKwPs9yXN4gjxorr4vS283LOwP nyUQ== X-Gm-Message-State: AOJu0YxgjowVg7g4DPxM3xyGlk/kte7Aq3d+OUtiUzlr+Sxuz+4KvOr7 PaInTQcnJC39iCCcRG1hQHGJZvgK699KpffXPd7Auc5DWBu9pofeG+xAMA== X-Google-Smtp-Source: AGHT+IFMNoqsj2lWj6z2RlHvQ4YcK96rwD4t3lqN1c8bfgeW5KQCM9K7mMa3vOMmdf6XBWL3xqGB4Q== X-Received: by 2002:a05:6a00:2daa:b0:706:6b0b:9573 with SMTP id d2e1a72fcca58-70b4356fc81mr18048561b3a.19.1720888143278; Sat, 13 Jul 2024 09:29:03 -0700 (PDT) Received: from gmail.com (p4357013-ipoe.ipoe.ocn.ne.jp. [123.222.98.12]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-78e32b6bafcsm1065089a12.5.2024.07.13.09.29.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 09:29:02 -0700 (PDT) Message-ID: <429f8fda-8f6b-4cef-ab79-27e5d7b56fac@gmail.com> Date: Sun, 14 Jul 2024 01:29:00 +0900 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/4] 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 , Phillip Wood References: <2653fb37-c8a8-49b1-a804-4be6654a2cad@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 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 Sat Jul 13 16:29: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: 13732445 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.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 EE50F13959D for ; Sat, 13 Jul 2024 16:29:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720888162; cv=none; b=Y1oY4ur1GZpoWAWYiXUBjADCPMCMsA21Nqp1jcG0h7w4OKquwB3Lxh55lkT1KACVrmM2Y1As7UgzQUHcVO0AlWikRSe2Jj93xeGhSPvYbtVF4+u8S+qLXqBZchZUbBheipC5GSWMaqY5rt5XrAymCtpe3W6cv4qvc8dUZi6AiOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720888162; c=relaxed/simple; bh=hP5AVS+rEogwKOgBQ8zbffM4EfqB6jKArtNqC+qQwCI=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=WJqgBAkLRRGCqSshZmFIg8RAojtHhNLaL8/8l2G5L+TGhrCl4Aa/W6GKXZxKmV2WJE76iME/I/pkI2V/fNuvE9v1U2/D5K8CPaF+Ui+6dKrDgTKsMmxPn64f/YvrTl+EQBOzQmSZQ+ysIWlqsl4rOX9av6WAv7ckvP1B+RpovRU= 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=YUSEICec; arc=none smtp.client-ip=209.85.161.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="YUSEICec" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5b9794dad09so1481398eaf.3 for ; Sat, 13 Jul 2024 09:29:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720888160; x=1721492960; 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=LLJiIilMBNIySC07erlxqGooGvO6aEpdC+rZF+zGv/k=; b=YUSEICecC/0+Dg5t0TcavBxK9d+KcNgBj5afQgYfh4Gk8WtZ5nZcQ31yQANoF1r91X 6jQQJDLsquWvT9vgJOZOubmLtk0GtFgDROlaNZA4n2QibmYu932L/gpt8qXRsn5VaouD cS8VjyetzHH2xAHVPmuOCvmVGOf47bw/X7pKt4rH/ySh7vU1VclJhqRwcVePycLoo8t9 wxJQtOW9PI0UGP1X8Z3dEyqjcqh+J+uDmaY2Q36APSiZ4TF6eAi+pbRHD2igb0L4jCi3 dZtsFqxtOJm02TNDGR6/ZuTenW5MdotaNSnHMb1kgE0zyjyuXSTgkHY43LYrKYuYtKas h1Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720888160; x=1721492960; 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=LLJiIilMBNIySC07erlxqGooGvO6aEpdC+rZF+zGv/k=; b=B5eg70v2urldI4iLLT0kitMaTmgK1wMR/C+RUjN2LL11yher1q+LY9s+fF2agKVphE rQvMo2X3IX8A2JFOgS95ZxC7qwhOC5obdlak46roslfgPGBC2qt1Yz9eC8i8QLwNqdv2 fs0G/RlN0e3Ef13X94e0NATwtB5vyhNZ7B2IaaM7zS0RrIHODE/ua3Cy3qtAo3MJ+kZn 4QCRtdDQMEFW/w8UvA2Zt/lQ0oJL1+a9bWgopM+cllG/4cQXWcmu560kV33HVn1QnvLZ GKEStexaMFcRC4P/yYAtuyF0FkrCc0pnPEQm90Jdgl+uSYhCu0mMh7LkdfxtBki1Ywzr 6Kog== X-Gm-Message-State: AOJu0YxHEPi4a6P4yDtMGYhvHi/favAtg0mBt05T5sS6t2unVn4Oc9Gx O+qn/1VeoOzHK67IF/rHNFlSaHFbhgDKaOszAsl40xvUmhDEG+SJj6K+gA== X-Google-Smtp-Source: AGHT+IGEphNm9Lb8goOs4RA+MohrF/2qe8dQvbciNW8kNT/7wGXekwkHm8cpFxCml6kbgMtJHIDU+w== X-Received: by 2002:a05:6359:4c9b:b0:1aa:d4a3:3d58 with SMTP id e5c5f4694b2df-1aade33d6ecmr1549294555d.29.1720888159958; Sat, 13 Jul 2024 09:29:19 -0700 (PDT) Received: from gmail.com (p4357013-ipoe.ipoe.ocn.ne.jp. [123.222.98.12]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cacd7046cbsm3393034a91.55.2024.07.13.09.29.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 09:29:19 -0700 (PDT) Message-ID: Date: Sun, 14 Jul 2024 01:29:16 +0900 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/4] pager: do not close fd 2 unnecessarily From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Dragan Simic , Jeff King , Phillip Wood References: <2653fb37-c8a8-49b1-a804-4be6654a2cad@gmail.com> Content-Language: en-US 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 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 Sat Jul 13 16:29:41 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: 13732446 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 17A1813959D for ; Sat, 13 Jul 2024 16:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720888186; cv=none; b=IenauaG1zcW/TZQsNBIRI9g805s2PK1PeszdNpNUMtBEgk/YGrJ1uEeJllWp60DNrGXIxoPCvWXIN5ps4WoNFwLtajlcIQ9BfBbSUcKdiWm1k4DmyZfjVUT/iRQZ4L0e/Xg4mZbk3SHn+r79pmtiFuPO9/lm+G9srafM6zxmwJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720888186; c=relaxed/simple; bh=KEW587wBor73RCDzF+PYRSDfC22OmsaxLQ+CIpeBPxU=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=A9AVN+xTSdQc/waaCkXLtfp3cnkikwRVBjiK1Yu6LtiVhE5N7kCoDBQ3UkOzsZbuIv7VZfQkIAlLSszN7dJ/oimpY5YTryohvPi3HP5DW+1szhyMh+z7IN4hMOKfcFw1b3sxLQBQfbdoBcqVGt/MQnyogzWyOcbPRLZMArV3CoA= 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=RcZcEeW9; arc=none smtp.client-ip=209.85.214.176 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="RcZcEeW9" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fb3b7d0d3aso18709275ad.2 for ; Sat, 13 Jul 2024 09:29:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720888184; x=1721492984; 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=+wvX/YC8p4IqHeNgNTcojCB8AT7x7NGKf0b7lGRYQZ0=; b=RcZcEeW9AlJetAdoRZQFIVx7eCg4IweFhQltCGnY4XUMGznmAct775/AaU619l71RT vyf192M+aclog7vNn3ej9wg+VWrtPAlS7LJHv4R8qBWtmE1cGsP0Qvkru/Ipu0WriLu/ qh5fo+fPX1zz0BxvJXKGFcGRFBgocnNZYJZsSCg0avpDzahZipjxEgqk+jQh6N5hsFqm zUmLgJlGNEUZDyHCaaHvAyyEK13gj8MEApXdH4a8PZcipAfgT2BfbHOyO0v6Q5ReVMf0 VEAo5L7dp+o6zZ7twSGKNDVUx8KwMrPsvqgAg9dSXx/XKHsWGAvwC/JYiyxlYdHXP7nz yg+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720888184; x=1721492984; 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=+wvX/YC8p4IqHeNgNTcojCB8AT7x7NGKf0b7lGRYQZ0=; b=PTgC7IH/RmG1+3o1qcWa2ZwjV9YcbY5xIMGI31aTwzfoy0iGgwLuGQ2qk2uW85LCwU QKd6RDVdFnnqGu01yzhIPveiLXYeSf99jj0h+wm8fEzCDDhjzjkWSI5fLcVx90B+O1za VSc890QCITLXAQcJ9Ir2chnFMc4eW0yHq+M+yOjK20LMBcML80zgTQTdCvYiMXQMPnv0 QE2INLs6/qbrv1cPiVIU1PQqRaO2YAjnU8Ev/qjRhiz2orL8jglCVhTk3If/oZN17L/h h6Ee410qhgjI2tLHYTt9xa8lsY6bjXtVi9xJufFfO+E/53VoJnBXWWa1nE6BBstd7kr5 wQeg== X-Gm-Message-State: AOJu0YzJ14bnNhbvuZl2xg7F1R4npMJ/HI7Zy5OVNx+Suzyvtfl52K1h mGT06cMFx2MaUq0OE3Fjz7bgSaolpXg+PlFCWOwJ9xBLZ6T7/+EsU9OFlg== X-Google-Smtp-Source: AGHT+IG4QOttbU9rg0Lgdw2XYe4ul53Kp2bYgZ6qshG5tf/cezlNH8m2Mu0NdLrLwc4NB4gMdhUTtg== X-Received: by 2002:a17:902:d50e:b0:1f7:167d:e291 with SMTP id d9443c01a7336-1fbb6d5ff5emr133721735ad.47.1720888184217; Sat, 13 Jul 2024 09:29:44 -0700 (PDT) Received: from gmail.com (p4357013-ipoe.ipoe.ocn.ne.jp. [123.222.98.12]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0bc2b92csm12135145ad.179.2024.07.13.09.29.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 09:29:43 -0700 (PDT) Message-ID: <205b0e27-7507-4a95-b239-818bd018c846@gmail.com> Date: Sun, 14 Jul 2024 01:29:41 +0900 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/4] pager: introduce wait_for_pager From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano , Dragan Simic , Jeff King , Phillip Wood References: <2653fb37-c8a8-49b1-a804-4be6654a2cad@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 | 43 +++++++++++++++++++++++++++++++++++++------ pager.h | 1 + 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/pager.c b/pager.c index 251adfc2ad..bea4345f6f 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,34 @@ 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) +{ + 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 +139,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 +169,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 Sat Jul 13 16:30:03 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: 13732447 Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169]) (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 07EAE13B58A for ; Sat, 13 Jul 2024 16:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720888209; cv=none; b=JWKxGY0cDkwso0TjntLTbtTt+CyzzDoDxTCLsw9+xMlkYynBjiroWLK09ZYl3eCX9moI3NukgzaZxm/3IScxabVblUiL3msYNzJwDr/wRy0pzKrNySWScPWq8fzTWJ3DpJmizrKBa8poZ4/cdyo15eLnXyN5ij4iuHEGKxj4yCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720888209; c=relaxed/simple; bh=UUTzpEW57fHTaj7kIu4iWsYO0CW3qIf+luKlgLU2JeE=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=lGPrHMAvlWiMLJySsyODNu2QLm1nNFc0T74CLaSxLgVvSYhZJTBZ8WCaEQs33mspLa/Z7MrHXViH2SBpZbqDH8yXfzibRw+O2Fgn90E7il2F+DRwIcT5Ukir6DjpAIvDfipPTFoRtqIx1JuXVkfzLk06YRhL9MmxG3pCuWQX2rA= 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=S6p0FOeD; arc=none smtp.client-ip=209.85.166.169 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="S6p0FOeD" Received: by mail-il1-f169.google.com with SMTP id e9e14a558f8ab-380eb36f5ceso12143855ab.0 for ; Sat, 13 Jul 2024 09:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720888207; x=1721493007; 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=dTOJOlXw8WcA8RcsYNBiryqYbVnDNdRw+4jeTorZl4o=; b=S6p0FOeDiBGt3NebpKhS+Fx8rUQIh9bgEaZ4YqtGrPdNcjJDRtZRI3lbnZECEZ07oY 8imAsvyrzYfNufYX+ZMGXlJh4w4zpQd5xczXx0jAtf1gHsTaZbsI18zVI7iJ2LTqeEZj +yU8+0nc9IgH0MOwMoj3qWVmvTyYKxQkaz6Opu8xiAe/65v59KzH8v2sozB5gFO23i+c Z7PWg5kw5i/KqSegeL/icH06Rah9lei//1sXKRkj1HaGNvo8or678vrp1mohg9/FEzgm gBOHpmJ/DPa/GLNNjnhWQ5NW99rgxWsukhBLWyDT5nVhLzfF0fsDf2vtrPexJXHZSZOY j7Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720888207; x=1721493007; 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=dTOJOlXw8WcA8RcsYNBiryqYbVnDNdRw+4jeTorZl4o=; b=Kj4n45b4ylzR7BUIu8dlytU/E9OQb0xihQs1sUyiRzkgmb0pTMuHShoKIdjfFlycU4 0O/ucPBkv1jGK7GiiwsmFD98xD/6fb6BGMwFFe3eRrmSxkhFM4VKlg2nGf7KDDtCwibb KoHazpPYgsZ04b8kcKs1mte8jWMUQpnR2kxNKy5G1zO8s4jlvfcfHkO7c6If5nLF4zvS FWDpJA58OEVmP8mL8oLTW81RTC3cYDI+5UZLIH/DmK6Ef8ivMgTs3Jc5jyw9GDfgNFu5 0CdzlYEFgR6Esui0QvlI3oT0SsLar9Ayuzh5fFeA8aWd8CbHp7jq7x1upwZFtgUNDKIY jVKw== X-Gm-Message-State: AOJu0YxdVimh1JA/st9vNN9RJ0Fkk4pKcoAzUGNxpg40H7Yy3X6IP+SA HsUC59bwNfSOq5YkTHh6DBAa1Pbqf47Cd9J567Wgg5tKR8u7+Rb9PwgEfw== X-Google-Smtp-Source: AGHT+IFZ6MbCMTGTJ6p0hE1BGT8lvSYevZm1s8tvdu0C+ctRNLyoqfPKR4DQXNfvEKNapbp37oJ5FA== X-Received: by 2002:a05:6e02:1c8d:b0:383:6af0:eb08 with SMTP id e9e14a558f8ab-38a56f09dfdmr168995885ab.1.1720888206987; Sat, 13 Jul 2024 09:30:06 -0700 (PDT) Received: from gmail.com (p4357013-ipoe.ipoe.ocn.ne.jp. [123.222.98.12]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70b7eb9e232sm1409029b3a.34.2024.07.13.09.30.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 09:30:06 -0700 (PDT) Message-ID: <4556095f-47d7-4849-b6d7-a08cd00ad865@gmail.com> Date: Sun, 14 Jul 2024 01:30:03 +0900 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/4] 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 , Phillip Wood References: <2653fb37-c8a8-49b1-a804-4be6654a2cad@gmail.com> Content-Language: en-US In-Reply-To: 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 | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 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..c89b984751 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -591,6 +591,34 @@ 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 does not break if pager ends unexpectedly' ' + test_when_finished "rm -f huge_file; git reset" && + printf "%2500000s" Y >huge_file && + git add -N huge_file && + test_write_lines P q | GIT_PAGER="head -c 1" test_terminal git add -p >actual +' + test_expect_success 'split hunk "add -p (edit)"' ' # Split, say Edit and do nothing. Then: #