Article View: linux.kernel.git
Article #2689[Outreachy PATCH] parse-options: convert check-ref-format
From: bonheurngezayo4
Date: Mon, 09 Nov 2026 08:44
Date: Mon, 09 Nov 2026 08:44
91 lines
13523 bytes
13523 bytes
From: Ngezayo Bonheur <bonheurngezayo4@gmail.com>
Signed-off-by: Ngezayo Bonheur <bonheurngezayo4@gmail.com>
---
builtin/check-ref-format.c | 45 ++++++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 16 deletions(-)
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index fd1c9c0e0c..a7ad3c8257 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -8,11 +8,18 @@
#include "refs.h"
#include "setup.h"
#include "strbuf.h"
+#include "parse-options.h"
static const char builtin_check_ref_format_usage[] =
"git check-ref-format [--normalize] [<options>] <refname>\n"
" or: git check-ref-format --branch <branchname-shorthand>";
+static const char * const builtin_check_ref_format_usage_options[] = {
+ "git check-ref-format [--normalize] [<options>] <refname>",
+ "git check-ref-format --branch <branchname-shorthand>",
+ NULL
+};
+
/*
* Return a copy of refname but with leading slashes removed and runs
* of adjacent slashes replaced with single slashes.
@@ -58,12 +65,24 @@ int cmd_check_ref_format(int argc,
const char *prefix,
struct repository *repo UNUSED)
{
- int i;
int normalize = 0;
int flags = 0;
const char *refname;
char *to_free = NULL;
int ret = 1;
+ struct option options[] = {
+ OPT_BOOL_F(0, "normalize", &normalize,
+ N_("normalize refname"), PARSE_OPT_NONEG),
+ OPT_BOOL_F(0, "print", &normalize,
+ N_("synonym for --normalize"), PARSE_OPT_NONEG),
+ OPT_BIT(0, "allow-onelevel", &flags,
+ N_("allow a one-level refname"),
+ REFNAME_ALLOW_ONELEVEL),
+ OPT_BIT_F(0, "refspec-pattern", &flags,
+ N_("allow a refspec pattern"),
+ REFNAME_REFSPEC_PATTERN, PARSE_OPT_NONEG),
+ OPT_END()
+ };
BUG_ON_NON_EMPTY_PREFIX(prefix);
@@ -73,22 +92,16 @@ int cmd_check_ref_format(int argc,
if (argc == 3 && !strcmp(argv[1], "--branch"))
return check_ref_format_branch(argv[2]);
- for (i = 1; i < argc && argv[i][0] == '-'; i++) {
- if (!strcmp(argv[i], "--normalize") || !strcmp(argv[i], "--print"))
- normalize = 1;
- else if (!strcmp(argv[i], "--allow-onelevel"))
- flags |= REFNAME_ALLOW_ONELEVEL;
- else if (!strcmp(argv[i], "--no-allow-onelevel"))
- flags &= ~REFNAME_ALLOW_ONELEVEL;
- else if (!strcmp(argv[i], "--refspec-pattern"))
- flags |= REFNAME_REFSPEC_PATTERN;
- else
- usage(builtin_check_ref_format_usage);
- }
- if (! (i == argc - 1))
- usage(builtin_check_ref_format_usage);
+ argc = parse_options(argc, argv, prefix, options,
+ builtin_check_ref_format_usage_options,
+ PARSE_OPT_STOP_AT_NON_OPTION |
+ PARSE_OPT_KEEP_DASHDASH);
+
+ if (argc != 1)
+ usage_with_options(builtin_check_ref_format_usage_options,
+ options);
- refname = argv[i];
+ refname = argv[0];
if (normalize)
refname = to_free = collapse_slashes(refname);
if (check_refname_format(refname, flags))
--
2.43.0
Technical Details
Message-ID:
<20261109084455.16915-1-bonheurngezayo4@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-74887-linux-kernel-git=dewy.ruReferences:
<20261109081244.16734-1-bonheurngezayo4@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-74887-linux-kernel-git=dewy.ru
From: bonheurngezayo4@gmail.com
Newsgroups: linux.kernel.git
Subject: [Outreachy PATCH] parse-options: convert check-ref-format
Date: Mon, 9 Nov 2026 10:44:55 +0200
Organization: Usenet Network
Message-ID: <20261109084455.16915-1-bonheurngezayo4@gmail.com>
References: <20261109081244.16734-1-bonheurngezayo4@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="312346"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:cF2ertlehd9nX9hrnMQ1FYws/KY= sha256:1iv1vseFRs2ZTrA1HRiuOLdTAJzRknr9STBOAYNFGF0=
sha1:muHfr+ZwjIImu1jO2tWn9cUOsNM= sha256:Yv9wkrtaaMCGB8hjj1pzLJphulYavaPAMBiOXvlelyg=
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 9E26511374E; Mon, 9 Nov 2026 11:57:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, 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 23IQSrarhmxg;
Mon, 9 Nov 2026 11:57:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-74887-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id F1916113389; Mon, 9 Nov 2026 11:57:27 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sin.lore.kernel.org (Postfix) with ESMTP id D91613FD61; Mon, 9 Nov 2026 08:46:01 +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=1794213916;
b=0CPF976/z2sR2Gz7G0lPJqyb0TeVZhhb9xIBnFB/sTcu0pQeSujx8p3pJsJnT1KM87LE
AYsh598rx+bq9c+sFAAPEtK81zas43qjKtTfXrPKzmmJFf4CWNimYPkDbQtL8sQw7r3yB
ldHawxvspw2cUNIJVKLG76tyZl+vflAf0PZ7srJSijBRi1B4Vwa9oGA7YeUdyuEOhm9Xc
0QxR3WgB6j8iljwzklGW34L7HWpf+uE2GqGCJsXPDlpOQaO5v6/TUFOQCnz3uxeY4Yfo6
Fsgir71M79HjPVaZD0Tda5hV4S4O5hQjxOXBav8Qz9QZhJDP/iLKCju3qCdKvMChflA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794213916;
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-Transfer-Encoding;
bh=eZRefbLEKwWVgCOzhOrkKX5EHcluRJM+5Z1BmZjEZgA=;
b=CPjpGy8Q1188pbyd87/rxfdeXOOmHoyi8H9lzu2MRzDnUGMgov0D8SGIDIou1RzHS0rI
XwQC6MkJlMAKAfKnHSHo4GoOb/L/2XmV1DB4lMjEICz14NoU8mwq9TzF1G6Qi08tb9oww
SUD63DDbjp8SmJc9dgF43J2rYdcf/oaVi6/Mag+O1oSszKPcAjVWyF0m4JO2fohY6rsN4
YCvbS2Ns2TbtXu4lmsBN2Mg7c6zKFbgMxjMq3avEoaxmEnAVsu0JBGmwDP2OjXGNJde3k
f6HPEuYdWjn8HHqmqE18rgl3/DgBucwC1bh5BPe8nIG6udzMUzXAgO7wMx8q6X1qsDQ==
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=MdmjVA5Z;
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 54682606D81E;
Mon, 9 Nov 2026 08:45:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=MdmjVA5Z
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.44
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794213915;
b=wAzKJip3akTspGmuSxlHKnAncBu25oOzdmdZn2Xs5ICx2o5NtpHrP3IXghc+rRZTpkl7
IcmrECg7dMuKF+QcZTPAQVLwTSI1/84rDOCG8lqbfRvl8lAnlAHj5midR2Oxkfg9i7FKO
Gl5FxM0XpYPt2tf8UrQnv3nsoODqPuGSoj8sclrTTOd2k/ddpE0Z3mLByyIUE60GxYaXJ
4cSoqU2neXNnpv4OZ7nR539zXUHiIsI+7n3riP8Eo8EQ6zvgZazUEvHyRcU7y7K+V4cbT
zNDdHrkRU09TTh5nRIIuQqdPXx6ddz93ep4IPMlj+M1sb/Jt3L3IbhDDmWhyQPKy19A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794213915;
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-Transfer-Encoding;
bh=eZRefbLEKwWVgCOzhOrkKX5EHcluRJM+5Z1BmZjEZgA=;
b=Vf0t76MTW12eTOTjqOQMFi9T1XSnTa9Wh+pm/rED5q6858azym59PDm+kpHPaormubIa
n2ob0VZAfzvA54ciEZkTWUjKGi+D82nghq6kMwFjJ3JqDh5wmTf0mjhStYB7XUVtmYTcm
fwbb2xjaVcDDfpjdFE+ZgWuMc3o+vGSJff+dYa55rSQNTpv1+SKE1ZgS9/aG6jMZDL+Qx
3h8XES6+RoKVZuK6HN5GR4qe+laJejNcSR0nQCLk2rku7zgmY+gVtaQrU60Tn8hkDZ8oh
08Iy9Fe8PIi7RnADsAk4HnTQi8GHBZXAKzw6UL98ahuDj4v0gUfzCqsYSAFmlvN7rzg==
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=MdmjVA5Z;
arc=none smtp.remote-ip=209.85.221.44
X-Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44])
(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 2740F606D813
for <git@vger.kernel.org>; Mon, 9 Nov 2026 08:45:15 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2740F606D813
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-wr1-f44.google.com with SMTP id ffacd0b85a97d-48dee593f18so305577f8f.3
for <git@vger.kernel.org>; Mon, 09 Nov 2026 00:45:14 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794213913; x=1794818713; darn=vger.kernel.org;
h=content-transfer-encoding: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=eZRefbLEKwWVgCOzhOrkKX5EHcluRJM+5Z1BmZjEZgA=;
b=MdmjVA5Z8OQaijJqGboHCQ6A9z/vaxrK1hcKdzoLfri0ernLTzUYykBsHIZeLIZ9Ux
pU20MZWYSlaVXANT5ogpnXmrdSnnfE8r/aNaTKwWSO8GZtIbmswWXjD7LQ3NrQHnKgOo
V6WehapIkr+NYDd+qYQeUNbxHC8CxuX8a3n6+ePHSl/FfSLV3wgEaZZ2kTZtcT5TPuGM
1klJ/3llFk3VV6ULF9z1doC6Il1+1b1PyHGAeQlwebpRvMjE4IDDO/eW8+Toiy3LhmCr
mWp9WkReBEOeFtnFwG3A0WLJQsb1gzTaO6WCfa4EOwr63MnNrRjxGe0sYGrPsXwFzOyg
4UOg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794213913; x=1794818713;
h=content-transfer-encoding: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=eZRefbLEKwWVgCOzhOrkKX5EHcluRJM+5Z1BmZjEZgA=;
b=C30G6JPPxbdDGhQ+cIbHJ82MIFRGtRvrXbW/nolQH/dmMTGcEnlGXbZZjk820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lJGJhyOrvDwEyJtaYDXtKZFTHyactZCZY
gzlZjHokTUeXbH6+ZaMiAuN6pXXC7xX7FLMOqrQk0qja8ACuk8BB/lRiNo+lSnaChoqhCU7ED
X-Received: by 2002:a05:6000:2c03:b0:48e:6419:ddf2 with SMTP id ffacd0b85a97d-4958a016007mr6935648f8f.17.1794213913528;
Mon, 09 Nov 2026 00:45:13 -0800 (PST)
X-Received: from DESKTOP-453HKQ1.localdomain ([102.22.168.79])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4959011c995sm8555853f8f.0.2026.11.09.00.45.11
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 09 Nov 2026 00:45:13 -0800 (PST)
X-Cc: Ngezayo Bonheur <bonheurngezayo4@gmail.com>
X-Mailer: git-send-email 2.43.0
X-In-Reply-To: <20261109081244.16734-1-bonheurngezayo4@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