πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #2377

[Outreachy PATCH v4 1/3] parse-options: answer --git-completion-helper before command runs

#2377
From: Tanga Joris
Date: Thu, 05 Nov 2026 00:39
100 lines
14773 bytes
fast-import parses its options only after reading the "feature"
lines from its input, and it creates a temporary pack file before
that. So "git fast-import --git-completion-helper" waits for input,
and each run leaves a tmp_pack_* file behind.

bash completion runs the helper with the terminal as input. The next
commit removes the NO_PARSEOPT flag from fast-import, which would make
"git fast-import --<TAB>" freeze without this patch.

show_usage_with_options_if_asked() already answers -h and --help-all
before a command does any work. Teach it to answer the completion
helper too. Then fast-import, and the other commands that call it,
reply without reading input.

Reported-by: RenΓ© Scharfe <l.s.r@web.de>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Cynthia Uche <herroyalpriestess@gmail.com>
Signed-off-by: Tanga Joris <tangajoris@gmail.com>
---
Changes since v3:
 - Added a sentence to the log message saying that the next commit
   removes NO_PARSEOPT from fast-import, as Kaartic suggested.
 - Added a comment above show_usage_with_options_if_asked() in
   parse-options.h, as Kaartic suggested.
 - Added Cynthia's test for --git-completion-helper-all. I also added
   the tmp_pack_* check from the first test to it, because without
   it the test still passes when the fix is reverted.
 - 2/3 is unchanged.
 - 3/3 is new, it adds the test Kaartic suggested.

 parse-options.c        |  6 ++++++
 parse-options.h        |  6 ++++++
 t/t9300-fast-import.sh | 16 ++++++++++++++++
 3 files changed, 28 insertions(+)

diff --git a/parse-options.c b/parse-options.c
index 283a0f1dc2..f2a23b79a4 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1536,6 +1536,12 @@ void show_usage_with_options_if_asked(int ac, const char **av,
 			usage_with_options_internal(NULL, usagestr, opts,
 						    USAGE_FULL, USAGE_TO_STDOUT);
 			exit(0);
+		} else if (!strcmp(av[1], "--git-completion-helper")) {
+			show_gitcomp(opts, 0);
+			exit(0);
+		} else if (!strcmp(av[1], "--git-completion-helper-all")) {
+			show_gitcomp(opts, 1);
+			exit(0);
 		}
 	}
 }
diff --git a/parse-options.h b/parse-options.h
index f68b51ceca..7ad33801fe 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -427,6 +427,12 @@ int parse_options(int argc, const char **argv, const char *prefix,
 NORETURN void usage_with_options(const char * const *usagestr,
 				 const struct option *options);
 
+/*
+ * If the only argument is -h, --help-all, --git-completion-helper or
+ * --git-completion-helper-all, print the answer and exit. Call this
+ * before the command does any work. Then asking for help or for the
+ * completion list does not wait for input or leave files behind.
+ */
 void show_usage_with_options_if_asked(int ac, const char **av,
 				      const char * const *usage,
 				      const struct option *options);
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 73c6e3d448..1305614381 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -2914,6 +2914,22 @@ test_expect_success 'R: blob appears only once' '
 	test 1 = $n
 '
 
+test_expect_success 'R: --git-completion-helper does not read from stdin' '
+	find .git/objects/pack -name "tmp_pack_*" >before &&
+	echo garbage | git fast-import --git-completion-helper >out &&
+	test_grep -e "--date-format=" out &&
+	find .git/objects/pack -name "tmp_pack_*" >after &&
+	test_cmp before after
+'
+
+test_expect_success 'R: --git-completion-helper-all does not read from stdin' '
+	find .git/objects/pack -name "tmp_pack_*" >before &&
+	echo garbage | git fast-import --git-completion-helper-all >all &&
+	test_grep -e "--allow-unsafe-features" all &&
+	find .git/objects/pack -name "tmp_pack_*" >after &&
+	test_cmp before after
+'
+
 ###
 ### series S (mark and path parsing)
 ###
-- 
2.43.0
Technical Details
Message-ID: <20261105003914.708836-1-tangajoris@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74510-linux-kernel-git=dewy.ru
References: <20261029231621.48958-1-tangajoris@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-74510-linux-kernel-git=dewy.ru
From: tangajoris@gmail.com (Tanga Joris)
Newsgroups: linux.kernel.git
Subject: [Outreachy PATCH v4 1/3] parse-options: answer --git-completion-helper before command runs
Date: Thu,  5 Nov 2026 03:39:11 +0300
Organization: Usenet Network
Message-ID: <20261105003914.708836-1-tangajoris@gmail.com>
References: <20261029231621.48958-1-tangajoris@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3527668"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:fHfFmAEpL8SAZXewdg5e+SKUJ6U= sha256:7wS1t6WAv9pDkiotxCEZ1FalQCMDYG1sLSzD5AKOdgQ=
	sha1:UGqt1GbAkqZTfo14/LrRNqAXW+E= sha256:JE9bWBi3hSjnm7rk/9CcJwugO61wZzfJQ3+o/Vn7qOE=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 828D3112E2A; Thu,  5 Nov 2026 03:42:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.148
X-Spam-Status: No, score=-2.148 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id FwOGVuURb08u;
	Thu,  5 Nov 2026 03:42:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-74510-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id BC202112DCD; Thu,  5 Nov 2026 03:42:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id E334D601F75; Thu,  5 Nov 2026 00:39:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793839178;
	b=Xa0rtA6B1w9nMjyqshw3W7vhkPjS19NZLbCexvWorz66xu0nBgGUt+RfZPb6qUYqWD7r
	 aQGFjYNoUy+2cIfo/klDzpy4jRkJZxs6BkXkaQWeTX925DzisWf81m1D/ZyaSf6d2NaCl
	 4aRlKwnsC28FNKpimO8Nd+fLsEs5iqiTZEJrrRlHj4Bc3cnRUpZK/s0A/1S7Tw4PHWZC2
	 G6d5g7/27thwxIvkEKnRNG1eelGVR13NdGmLzjYsw9YdD4PUipDmNHuT2c+Q4COne3SL4
	 AdGOqfUCnxL9+QFE80t52t0+tuVesa4DWQt+x0PgUDvjwIaH9noTatl28WLlIjKn5pw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793839178;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=/4mpfEeVtAl3e4+MhWOzsCIhBg8/1QaN2eNz+CYSjSY=;
	b=AVMsmja5hk0ISXs+hkqom3RkT6bioUmmUFlR34Eb65K3y7sOog8abTzqAeiHYaYeY+oV
	 eegBxKpWej9R3xrQrRneTIuOAsCwuubtiJEef91ZDtqzBq8yQ9+DCiKXvTVoo+pW2wjWk
	 nVQ/BIuaLTiwTMjC+CpiZ7zEXC6mUlyK05/IKpHC40ZC9WRxVhbSmez27DRcuHRsrYl2u
	 qtuHQxkjOQBhqVVcYDY2tALQIDHhc7nlnVhpID956saXXwr4FYLfeHITU2DiG9IPpFe+Y
	 +26jemAjn1HYCEmhnVmE2RcCNAP78ivkZ0DOibplS5231f0ilYDq7peqGpW6XefbGAQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qHlCgaU2;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id DC7DC606A32F;
	Thu,  5 Nov 2026 00:39:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qHlCgaU2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.45
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793839177;
	b=5RB9bWvZeZYDw3MFWjpck9CGAmPjQirilgnh8KFHhdpajiku8+oyhwFBOM50SZRgp96n
	 QLSriLp2BfU4G9coLf2HBJ8QX6XYkJFt07VI7MeIFfhWA6316+2hRL0z/MOTzMAm84Q73
	 dP6PapZE49JLv68M7fQjXg5Z1IPazW9OsVhjf2+ZnznRQNmjGs7T/rcEX+B3OvnL5Psuv
	 SqydQKvz66bTbHqMvZP7IdsmIXMnJX5Xg7mDegko71Zmix29qpYYveG7avhjDMOnwthMO
	 8gREKykdyCRpjUXU42G0d+UK0Z2gsyHBenRgQgb8DLRVlVS7OGpoyuB4XppBkWxShaA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793839177;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Type:Content-Transfer-Encoding;
	bh=/4mpfEeVtAl3e4+MhWOzsCIhBg8/1QaN2eNz+CYSjSY=;
	b=GHl2UakKV3GP14hFYcbzVJr+RRyOtt/w4Qc5thBCK+A9aqdjsO35uNWqRXM2rH8KflvZ
	 X/CC+5YwEy7k3F0QGlV4XIKk8jarj6a1ZjYj0xo0i7FPVetxu4FOvaphsr7dERIQw30wB
	 q0PMNSDP0aiVCJvpTOZCvpDXUp4Q6d2smwPBhbmw0kYVPRp0n9D5q9/7lV+g6LczvfT68
	 l1je3W+rHlwdVEDPSOnfXEb/uArqcO8KtE0hl1qUF2B637LXmagY+VYUdC/vIZvBZDBwr
	 kI4k16hOJ90TBwqvb2w5siqQ33c0aAI0Dn4Nhybi5Am7sV8zchT4Sn9wesJcHrd3Q1Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=qHlCgaU2;
	arc=none smtp.remote-ip=209.85.208.45
X-Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A15AD606A31B
	for <git@vger.kernel.org>; Thu,  5 Nov 2026 00:39:36 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A15AD606A31B
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-6af9a9451daso2133742a12.0
        for <git@vger.kernel.org>; Wed, 04 Nov 2026 16:39:36 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1793839175; x=1794443975; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:mime-version:references
         :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject
         :date:message-id:reply-to:content-type;
        bh=/4mpfEeVtAl3e4+MhWOzsCIhBg8/1QaN2eNz+CYSjSY=;
        b=qHlCgaU2LPNLGzlirEm6DyzgDn5aHkjCyDnHs10joyjFXQ42S7rI8ttB+lDLe+syNy
         xCNWFjVVnoylizldMF3hXNQEb/7VrTM7uRmTFcgMQ8J5eMLDGjxGXHneLEg9KPih1DLh
         JSRU1PLbsQqy6+9iPw8wBxA9QQH/KDx7c032zO7IOgdTxtVrNom3T0aKmllGjtk8DiSk
         i+Rk62gESN6afgOfUpW8IB0HQUO4yvBTPcCfENQrEGCCt//Yv3tI4NbuSTsjYJTefam5
         DBn4KKEHgnpHHhAha9ubKAW/4gheiRJpSPGCMxxgc8oxyRJsvfJ8BURfPmprjYaQM5bm
         en2w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1793839175; x=1794443975;
        h=content-transfer-encoding:content-type:mime-version:references
         :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=/4mpfEeVtAl3e4+MhWOzsCIhBg8/1QaN2eNz+CYSjSY=;
        b=tMEHhXFYLrs7wt2AwB2OPJiHix6XOVp2k3Hvz76/wWeRhpMKOSbnYgiL6kFgvHn++k
         IZUennsAicnmhWgPxot95VU9RP+MLocdGgwXKZLtp/A0EjX9X72j07Abmk6RtWP4IlDT
         lIfOdbZGFYLdM4cDhnRJMryNJS0CunGU1p6K3w/obR+7NhLSWRaSAQHz3JEg25aDjr/N
         Y/XIIHAId1Jq67QCAc7ORxicqL8n2SBvBYWxGi3ZQTMErnxEQ9C3mSi5tTGJrHIbeweQ
         6Y01SJddyk2TJyxv7hqV9NER1YMSa8ddv9RoW+dmD3GMe8c6+n/ea3dbsD32tq/huel+
         Nn+g==
X-Gm-Message-State: APuU4Z9Kq0QXsZKCIHj4niuOMCOjJTg3V1HvF3T43cWQDOzeLEhrtjn9
	9R7Ap3ZMS1sJJbrR6CjRpod25Bon/JpvK2DQWVXMIjdqKws1DhO6mRXXoQDkpXr5
X-Gm-Gg: AYBFou12JK+2moUSgAiPgIIwEOz4byzmDk47RSAYN655LYvRfhIXIxTnp5beOqHS1V1
	wt0JwgrvoNz/OfOFn1htDxfoz9p5IwmN5XGwdYuxY8xzFv4kOQgwkBjCtD7R89muVwnqYMCO40A
	gdK6JRWKF+1VFCCXSF1w2oekdUs71uOWtj7coqdRoR/24GixDnibNPdxyyIj6DG3ZZ9qQuHKjW7
	Qhrs9b1PpKhcRhidnq/wX5r69HG7qNdiuUkFboUlzGkmjcyuPpZ5Vsf0p3ekPv7o5q/8+k7s15X
	YZSMEAKTdFl3DyYBCZorTCGGsbeO655Zb8IqWfr7QeQ2Qp07+N99YTJLh7jW1bJvNfIi6wih9Wa
	P8TJYCLjyj1i24L+EmgXAM41navR6SDXFsa2ONlWkKGPyQ7jSSn2f1AYT9T8N3OMIZ1oyAbinfk
	xWg3EmjVCLOo66SsA2KjwTepHkQypzcnEX8fcqyejUUhMbxt5+FVM/5c2k6pnMlag5CoXyKLs//
	+UJfJUmKgCil/GhR4BS9MIqcpUK13ynOBmtAgW55XTaz96v5czBOwJfvzcLFSp8gA9VrTmfoKB8
	Bmdal3yGZJSUuzmdYvnD6yai7cal70hClwwNoANjlZ8+Z8UbRsKcwt3B3s2CCstMjTCEgWSIM5Y
	EBma3Z7smMicuLYvvGugVeXTCmEoQ7gCYNqYQ
X-Received: by 2002:aa7:c395:0:b0:6b3:cbe9:7231 with SMTP id 4fb4d7f45d1cf-6b4d33c68f8mr8881886a12.5.1793839174705;
        Wed, 04 Nov 2026 16:39:34 -0800 (PST)
X-Received: from HP ([105.163.158.144])
        by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6b55ac7fa76sm1236883a12.28.2026.11.04.16.39.30
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Wed, 04 Nov 2026 16:39:33 -0800 (PST)
X-Cc: l.s.r@web.de,
	gitster@pobox.com,
	christian.couder@gmail.com,
	siddharthasthana31@gmail.com,
	kaartic.sivaraam@gmail.com,
	usmanakinyemi202@gmail.com,
	herroyalpriestess@gmail.com,
	Tanga Joris <tangajoris@gmail.com>
X-Mailer: git-send-email 2.56.0.299.g39a9a95557
X-In-Reply-To: <20261029231621.48958-1-tangajoris@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list