Article View: linux.kernel.git
Article #2477[Outreachy PATCH v5 1/3] parse-options: answer --git-completion-helper before command runs
From: Tanga Joris
Date: Thu, 05 Nov 2026 22:34
Date: Thu, 05 Nov 2026 22:34
94 lines
14353 bytes
14353 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 v4:
- Reworded the comment above show_usage_with_options_if_asked()
in parse-options.h, as Junio suggested.
- 2/3 and 3/3 are unchanged.
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..775a028f10 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);
+/*
+ * Programs that call parse_options() early do not need this function.
+ * If your program has to answer help requests (-h and --help-all) or
+ * the completion helper before parse_options() runs, call this
+ * function to answer them.
+ */
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:
<20261105223458.1534785-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-74618-linux-kernel-git=dewy.ruReferences:
<20261105003914.708836-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-74618-linux-kernel-git=dewy.ru
From: tangajoris@gmail.com (Tanga Joris)
Newsgroups: linux.kernel.git
Subject: [Outreachy PATCH v5 1/3] parse-options: answer --git-completion-helper before command runs
Date: Fri, 6 Nov 2026 01:34:56 +0300
Organization: Usenet Network
Message-ID: <20261105223458.1534785-1-tangajoris@gmail.com>
References: <20261105003914.708836-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="3746695"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:w3k7uWS6VJluQ9uYn37KOMsW7NY= sha256:7halodSUgx2G/vAK/p4NevTIf2Q6h09Ofm3almEbsak=
sha1:fGyfCd2UF0xM1oWLANn6Wj6hE7A= sha256:lwjEBZ5WXC42zTXpIyOvf2Sxz+a9mPm0LS9WsXobmGQ=
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 ABE251130E8; Fri, 6 Nov 2026 01:36:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.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] 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 eFTMldCv_hln;
Fri, 6 Nov 2026 01:36:52 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-74618-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id DB5411130D9; Fri, 6 Nov 2026 01:36:43 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 6513927690; Thu, 5 Nov 2026 22:35:33 +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=1793918132;
b=ot9c+N0hN8VedD3oM9PupAiOFp1H72flo9DPxe58ds5UGQVW17LPMUYv/oH4gHJJraav
4qL9iS3uI+zzG5aA3aeyc5tfa1IZl12igoS47k38nO7kzcrT5nACUiXSxH2fogaBA5Xp2
wrNyKs4F85ZdEVEAwFA1idRY4Gg8+p7PUeAulUrVFtu1WSWEzYSs3JB3gzpFUTHwrb0qz
oE6/IiPPRSS/h8PNfzBcvjWyCrVfi66uNzn/sSU/BZEpc0Tpt67/PQS1obJa4NsbZ33AV
7tHDSyKzDCgWeBgtjglrZL7oUqez03pzfAto6Fif+pmcp/0a7MUTr/WJe5hOXdHaQIw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793918132;
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=rC9BbVpEcPxmUYJ/AzgYmPVa6ALH99Gq+D/3SDB+5dI=;
b=XfPEktx8G0gY6dJEraLMmGXUO//A/M/9qLQyQ/L4Yf/6RrMQk6KDKvIjsaNzyXTHP5GI
4YoJFV1LH0SEy9TDpGh/8f2WcgneG1vRxOZ1udqq1/Uf7E4n3I/hbwBsyExP+XmJTzFFw
VT8KMUaSYvqhcyCTPlvFby1WcWeY732sMjT/4CEtpeCDV83GMqz4qxB15NNOm30XP5Yqu
bhJodEZESVQ4D8t6w2UhJgYf8OQAQCyxyoVyoTiHtqVXp5ysiXLFPR60reDhy9gUwFXgF
5UDqxIlYChG8eS20ryHotAsnQk1h0+fI1hEEoQEGtsIZKteI3+IgD2RW+1IPWO/v2pw==
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="NW50Hx/R";
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 C1925606A32F;
Thu, 5 Nov 2026 22:35:32 +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=NW50Hx/R
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793918131;
b=KVkwwJAc8mwZwiEhw9DUVxFn0lPY5nJA/u/GfnM7yOa+D7JUJdVnZsrHNUvq1v6Z36LM
+I/17K4jWQdc5JRLlSwPlKaAlw9tMYxm21sajwXnACUEz4RyeOtqBKVd9I14FHsKdN8f+
alV0nsB3h6SXPOvl83AWe1GLNJp/+MZc7qztzpj7hp6/HCpf9H3mygRT8sQnNf2rFCuxZ
nwK0KZsDab/kci4PO2Uc8fvy/T348rWGrM4P7Kel5CxiguNKoG0xLXzMv1uRDt7IBjgY0
0cHzVjqmp9V5mBhbHHxjfnw+x35vKVRo3+VN+3xDxMVHzwguj8WsTiwSva7/nJ+txbA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793918131;
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=rC9BbVpEcPxmUYJ/AzgYmPVa6ALH99Gq+D/3SDB+5dI=;
b=xvjVUBDy2C8ID5mR53YCRmz8KK1m+2O94UwypuRixMKcvZ7NknP3HgSbX9fmup9p2Hz4
z5YswoXS4QsnclIzDYWoDYnWTh8ijdRZegbj4Wdfje69C3Ks9Kj9hGBdGPHli3dvRbCSn
tPnik5z/7v4LWE0oA8BdLycd01UXKTjrzeH9lCnw/NTJaFi95p07QnQEACru69daG3T/N
J3DdNGGd0fhqXhbwwBPJKDmOaRWUWRcmwaFNAZtMCUtcePe+mvtlCXYZMreeoIRR/bHmN
e5RBfeZ2UzE1ETe/z+zuqd4MeIMVn8d1cjQecfaJ+OjEfl32gK6bq3vTU5M1UUm2xwg==
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="NW50Hx/R";
arc=none smtp.remote-ip=209.85.208.47
X-Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47])
(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 86BF5606A31B
for <git@vger.kernel.org>; Thu, 5 Nov 2026 22:35:31 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 86BF5606A31B
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-f47.google.com with SMTP id 4fb4d7f45d1cf-6b561b60b78so1704198a12.1
for <git@vger.kernel.org>; Thu, 05 Nov 2026 14:35:31 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1793918130; x=1794522930; 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=rC9BbVpEcPxmUYJ/AzgYmPVa6ALH99Gq+D/3SDB+5dI=;
b=NW50Hx/R0dGdQPgDCk9sD54HPaqlNLim3spk3bgSg8lPZI1MHMBkVNSwbq2Ot8JHZl
0hX/xwAKJ8YHxOgoepj6TWJYEn9btBipofFuk1/B7ccFm0MJYn9uQzNqYqoS+axGyhBr
1n5sNoV4JwBNUFeTbsVNtQhdX5SVvq3Qo97I8ZlzLzMpHQTv6PROZ1IGkkBIcpi+aq9M
BbkbiFUql1I5l3+Yp5c/DpmImZULiR0RpAV/dmvntTVgXPfMXbiychHSej8/AuRWqZFP
qKD3khjUp9b6XDcoiqhpifxZhJ5M4KOaf7AKBPwAhk3Nis/1gHcQqrm4pal+dJb4m27E
PyDA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793918130; x=1794522930;
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=rC9BbVpEcPxmUYJ/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d4jx5BnWJK8jd/hXhPlyaTYX6GZomo920l6Fqb0obEzhHkT
TlEZvROgG6dsdEqKqQy0lg12bsF0Xemd8xJ7QfnaJVGJDNjtqgHVRA11fUciHyiyA/eIO2+lDmT
/uWN2NKr8ngoqDWHzDtvmuGWjXSpvfjA5zYQ=
X-Received: by 2002:a17:907:d40a:b0:c3e:d0ca:d30a with SMTP id a640c23a62f3a-c4d35447db5mr69028166b.4.1793918129633;
Thu, 05 Nov 2026 14:35:29 -0800 (PST)
X-Received: from HP ([105.163.158.39])
by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c4d3569e638sm23826666b.48.2026.11.05.14.35.25
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 05 Nov 2026 14:35:28 -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.388.g09a996e1ff
X-In-Reply-To: <20261105003914.708836-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