{"thread":{"id":"66809","subject":"[PATCH] parse-options: convert check-ref-format","startedAt":"2026-11-09T08:12:44Z","lastAt":"2026-11-09T08:44:55Z","messageCount":2,"participants":["bonheurngezayo4@gmail.com"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"557896","messageId":"20261109081244.16734-1-bonheurngezayo4@gmail.com","threadId":"66809","inReplyTo":null,"subject":"[PATCH] parse-options: convert check-ref-format","fromName":"","fromEmail":"bonheurngezayo4@gmail.com","sentAt":"2026-11-09T08:12:44Z","receivedAt":"2026-11-09T08:12:44Z","isPatch":true,"sender":{"key":"bonheurngezayo4@gmail.com","avatar":null},"body":"From: Ngezayo Bonheur <bonheurngezayo4@gmail.com>\n\nSigned-off-by: Ngezayo Bonheur <bonheurngezayo4@gmail.com>\n---\n builtin/check-ref-format.c | 45 ++++++++++++++++++++++++--------------\n 1 file changed, 29 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c\nindex fd1c9c0e0c..a7ad3c8257 100644\n--- a/builtin/check-ref-format.c\n+++ b/builtin/check-ref-format.c\n@@ -8,11 +8,18 @@\n #include \"refs.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n+#include \"parse-options.h\"\n \n static const char builtin_check_ref_format_usage[] =\n \"git check-ref-format [--normalize] [<options>] <refname>\\n\"\n \"   or: git check-ref-format --branch <branchname-shorthand>\";\n \n+static const char * const builtin_check_ref_format_usage_options[] = {\n+\t\"git check-ref-format [--normalize] [<options>] <refname>\",\n+\t\"git check-ref-format --branch <branchname-shorthand>\",\n+\tNULL\n+};\n+\n /*\n  * Return a copy of refname but with leading slashes removed and runs\n  * of adjacent slashes replaced with single slashes.\n@@ -58,12 +65,24 @@ int cmd_check_ref_format(int argc,\n \t\t\t const char *prefix,\n \t\t\t struct repository *repo UNUSED)\n {\n-\tint i;\n \tint normalize = 0;\n \tint flags = 0;\n \tconst char *refname;\n \tchar *to_free = NULL;\n \tint ret = 1;\n+\tstruct option options[] = {\n+\t\tOPT_BOOL_F(0, \"normalize\", &normalize,\n+\t\t\t   N_(\"normalize refname\"), PARSE_OPT_NONEG),\n+\t\tOPT_BOOL_F(0, \"print\", &normalize,\n+\t\t\t   N_(\"synonym for --normalize\"), PARSE_OPT_NONEG),\n+\t\tOPT_BIT(0, \"allow-onelevel\", &flags,\n+\t\t\tN_(\"allow a one-level refname\"),\n+\t\t\tREFNAME_ALLOW_ONELEVEL),\n+\t\tOPT_BIT_F(0, \"refspec-pattern\", &flags,\n+\t\t\t  N_(\"allow a refspec pattern\"),\n+\t\t\t  REFNAME_REFSPEC_PATTERN, PARSE_OPT_NONEG),\n+\t\tOPT_END()\n+\t};\n \n \tBUG_ON_NON_EMPTY_PREFIX(prefix);\n \n@@ -73,22 +92,16 @@ int cmd_check_ref_format(int argc,\n \tif (argc == 3 && !strcmp(argv[1], \"--branch\"))\n \t\treturn check_ref_format_branch(argv[2]);\n \n-\tfor (i = 1; i < argc && argv[i][0] == '-'; i++) {\n-\t\tif (!strcmp(argv[i], \"--normalize\") || !strcmp(argv[i], \"--print\"))\n-\t\t\tnormalize = 1;\n-\t\telse if (!strcmp(argv[i], \"--allow-onelevel\"))\n-\t\t\tflags |= REFNAME_ALLOW_ONELEVEL;\n-\t\telse if (!strcmp(argv[i], \"--no-allow-onelevel\"))\n-\t\t\tflags &= ~REFNAME_ALLOW_ONELEVEL;\n-\t\telse if (!strcmp(argv[i], \"--refspec-pattern\"))\n-\t\t\tflags |= REFNAME_REFSPEC_PATTERN;\n-\t\telse\n-\t\t\tusage(builtin_check_ref_format_usage);\n-\t}\n-\tif (! (i == argc - 1))\n-\t\tusage(builtin_check_ref_format_usage);\n+\targc = parse_options(argc, argv, prefix, options,\n+\t\t\t     builtin_check_ref_format_usage_options,\n+\t\t\t     PARSE_OPT_STOP_AT_NON_OPTION |\n+\t\t\t     PARSE_OPT_KEEP_DASHDASH);\n+\n+\tif (argc != 1)\n+\t\tusage_with_options(builtin_check_ref_format_usage_options,\n+\t\t\t\t   options);\n \n-\trefname = argv[i];\n+\trefname = argv[0];\n \tif (normalize)\n \t\trefname = to_free = collapse_slashes(refname);\n \tif (check_refname_format(refname, flags))\n-- \n2.43.0\n\n\n"},{"id":"557899","messageId":"20261109084455.16915-1-bonheurngezayo4@gmail.com","threadId":"66809","inReplyTo":"20261109081244.16734-1-bonheurngezayo4@gmail.com","subject":"[Outreachy PATCH] parse-options: convert check-ref-format","fromName":"","fromEmail":"bonheurngezayo4@gmail.com","sentAt":"2026-11-09T08:44:55Z","receivedAt":"2026-11-09T08:44:55Z","isPatch":true,"sender":{"key":"bonheurngezayo4@gmail.com","avatar":null},"body":"From: Ngezayo Bonheur <bonheurngezayo4@gmail.com>\n\nSigned-off-by: Ngezayo Bonheur <bonheurngezayo4@gmail.com>\n---\n builtin/check-ref-format.c | 45 ++++++++++++++++++++++++--------------\n 1 file changed, 29 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c\nindex fd1c9c0e0c..a7ad3c8257 100644\n--- a/builtin/check-ref-format.c\n+++ b/builtin/check-ref-format.c\n@@ -8,11 +8,18 @@\n #include \"refs.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n+#include \"parse-options.h\"\n \n static const char builtin_check_ref_format_usage[] =\n \"git check-ref-format [--normalize] [<options>] <refname>\\n\"\n \"   or: git check-ref-format --branch <branchname-shorthand>\";\n \n+static const char * const builtin_check_ref_format_usage_options[] = {\n+\t\"git check-ref-format [--normalize] [<options>] <refname>\",\n+\t\"git check-ref-format --branch <branchname-shorthand>\",\n+\tNULL\n+};\n+\n /*\n  * Return a copy of refname but with leading slashes removed and runs\n  * of adjacent slashes replaced with single slashes.\n@@ -58,12 +65,24 @@ int cmd_check_ref_format(int argc,\n \t\t\t const char *prefix,\n \t\t\t struct repository *repo UNUSED)\n {\n-\tint i;\n \tint normalize = 0;\n \tint flags = 0;\n \tconst char *refname;\n \tchar *to_free = NULL;\n \tint ret = 1;\n+\tstruct option options[] = {\n+\t\tOPT_BOOL_F(0, \"normalize\", &normalize,\n+\t\t\t   N_(\"normalize refname\"), PARSE_OPT_NONEG),\n+\t\tOPT_BOOL_F(0, \"print\", &normalize,\n+\t\t\t   N_(\"synonym for --normalize\"), PARSE_OPT_NONEG),\n+\t\tOPT_BIT(0, \"allow-onelevel\", &flags,\n+\t\t\tN_(\"allow a one-level refname\"),\n+\t\t\tREFNAME_ALLOW_ONELEVEL),\n+\t\tOPT_BIT_F(0, \"refspec-pattern\", &flags,\n+\t\t\t  N_(\"allow a refspec pattern\"),\n+\t\t\t  REFNAME_REFSPEC_PATTERN, PARSE_OPT_NONEG),\n+\t\tOPT_END()\n+\t};\n \n \tBUG_ON_NON_EMPTY_PREFIX(prefix);\n \n@@ -73,22 +92,16 @@ int cmd_check_ref_format(int argc,\n \tif (argc == 3 && !strcmp(argv[1], \"--branch\"))\n \t\treturn check_ref_format_branch(argv[2]);\n \n-\tfor (i = 1; i < argc && argv[i][0] == '-'; i++) {\n-\t\tif (!strcmp(argv[i], \"--normalize\") || !strcmp(argv[i], \"--print\"))\n-\t\t\tnormalize = 1;\n-\t\telse if (!strcmp(argv[i], \"--allow-onelevel\"))\n-\t\t\tflags |= REFNAME_ALLOW_ONELEVEL;\n-\t\telse if (!strcmp(argv[i], \"--no-allow-onelevel\"))\n-\t\t\tflags &= ~REFNAME_ALLOW_ONELEVEL;\n-\t\telse if (!strcmp(argv[i], \"--refspec-pattern\"))\n-\t\t\tflags |= REFNAME_REFSPEC_PATTERN;\n-\t\telse\n-\t\t\tusage(builtin_check_ref_format_usage);\n-\t}\n-\tif (! (i == argc - 1))\n-\t\tusage(builtin_check_ref_format_usage);\n+\targc = parse_options(argc, argv, prefix, options,\n+\t\t\t     builtin_check_ref_format_usage_options,\n+\t\t\t     PARSE_OPT_STOP_AT_NON_OPTION |\n+\t\t\t     PARSE_OPT_KEEP_DASHDASH);\n+\n+\tif (argc != 1)\n+\t\tusage_with_options(builtin_check_ref_format_usage_options,\n+\t\t\t\t   options);\n \n-\trefname = argv[i];\n+\trefname = argv[0];\n \tif (normalize)\n \t\trefname = to_free = collapse_slashes(refname);\n \tif (check_refname_format(refname, flags))\n-- \n2.43.0\n\n\n"}]}