git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] [Outreachy] check-ref-format: parse options

From
GGgeorge espinoza via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 7, 2019, 08:09 UTC
Message-ID
<0a1c8e2dea25d2e485cbf8350b08953ed33e96b7.1573114201.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.449.git.1573114201.gitgitgadget@gmail.com>
From: george espinoza <gespinoz2019@gmail.com>

This command currently handles its own argv so by teaching it to use parse-options instead we can standardize the way commands handle user input across the project.

As a consequence of using OPT_BOOL data structure on --normalize & --refspec-pattern, --no-normalize & --no-refspec-pattern can now be used.

NO_PARSEOPT flag was also removed to update git.c with the conversion of the structure in this command.

This is a rough draft and I need some advice if I'm doing this correctly since its being built but it is failing tests.

Helped by: emily shaffer emilyshaffer@google.com Helped by: johannes schindelin johannes.schindelin@gmx.de

Signed-off-by: george espinoza <gespinoz2019@gmail.com>
---
 builtin/check-ref-format.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index 3fe0b5410a..c48fb19eda 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -61,10 +61,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
 	};
 
 	int i = 0;
-	int verbose;
-	int normalize;
-	int allow_onelevel;
-	int refspec_pattern;
+	int verbose = 0;
+	int normalize = 0;
 	int flags = 0;
 	const char *refname;
 
@@ -73,12 +71,13 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
 		OPT_GROUP(""),
 		OPT_CMDMODE( 0 , "branch", &check_ref_format_branch, N_("branch"), CHECK_REF_FORMAT_BRANCH),
 		OPT_BOOL( 0 , "normalize", &normalize, N_("normalize tracked files")),
-		OPT_BOOL( 0 , "allow-onelevel", &allow_onelevel, N_("allow one level")),
-		OPT_BOOL( 0 , "refspec-pattern", &refspec_pattern, N_("refspec pattern")),
+		OPT_BIT( 0 , "allow-onelevel", &flags, N_("allow one level"), REFNAME_ALLOW_ONELEVEL),
+		OPT_NEGBIT( 0, "no-allow-onelevel", &flags, N_("no allow one level"), REFNAME_ALLOW_ONELEVEL),
+		OPT_BIT( 0 , "refspec-pattern", &flags, N_("refspec pattern"), REFNAME_REFSPEC_PATTERN),
 		OPT_END(),
 	};
 
-	argc = parse_options(argc, argv, prefix, options, builtin_check_ref_format_usage, PARSE_OPT_KEEP_ARGV0);
+	argc = parse_options(argc, argv, prefix, options, builtin_check_ref_format_usage, 0);
 
 	refname = argv[i];
 	if (normalize)
-- 
gitgitgadget
Previous: Junio C Hamano
Message 11 of 11 in “[Outreachy] check-ref-format: parse-options”
  1. 0/6 [Outreachy] check-ref-format: parse-optionsGeorge Espinoza via GitGitGadget, Nov 7, 2019
  2. 2/6 [Outreachy] check-ref-format: parse-optionsgeorge espinoza via GitGitGadget, Nov 7, 2019
  3. Junio C HamanoNov 7, 2019
  4. George EspinozaNov 9, 2019
  5. 1/6 [Outreachy] merge-ours: include parse-option.hgeorge espinoza via GitGitGadget, Nov 7, 2019
  6. Junio C HamanoNov 7, 2019
  7. 5/6 [Outreachy] check-ref-format: parse-optionsgeorge espinoza via GitGitGadget, Nov 7, 2019
  8. 6/6 [Outreachy] check-ref-format: parse-optionsgeorge espinoza via GitGitGadget, Nov 7, 2019
  9. 3/6 This file wasn't supposed to change during my git push for check-ref-format :(george espinoza via GitGitGadget, Nov 7, 2019
  10. Junio C HamanoNov 7, 2019
  11. 4/6 [Outreachy] check-ref-format: parse optionsgeorge espinoza via GitGitGadget, Nov 7, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.