git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "george espinoza via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: George Espinoza <gespinoz2019@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	george espinoza <gespinoz2019@gmail.com>
Subject: [PATCH 5/6] [Outreachy] check-ref-format: parse-options
Date: Thu, 07 Nov 2019 08:09:59 +0000	[thread overview]
Message-ID: <aeff5d9908e80f8534144529bc5cedd6dd190021.1573114201.git.gitgitgadget@gmail.com> (raw)
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.

Because OPT_BOOL data structure is being used on --normalize
--no-normalize can now be utilized.

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

I got all tests to pass at the moment. My next commit will be to
check if OPT_NEGBIT isn't needed and moving around OPT_VERBOSE.

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 | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index c48fb19eda..be3b1bd84d 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -57,10 +57,10 @@ static int check_ref_format_branch(const char *arg)
 int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
 {
 	enum {
+		CHECK_REFNAME_FORMAT = 0,
 		CHECK_REF_FORMAT_BRANCH,
-	};
+	} mode = CHECK_REFNAME_FORMAT;
 
-	int i = 0;
 	int verbose = 0;
 	int normalize = 0;
 	int flags = 0;
@@ -69,17 +69,19 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
 	struct option options[] = {
 		OPT__VERBOSE(&verbose, N_("be verbose")),
 		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_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_CMDMODE(0 , "branch", &mode, N_("branch"), CHECK_REF_FORMAT_BRANCH),
+		OPT_BOOL(0 , "normalize", &normalize, N_("normalize tracked files")),
+		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, 0);
 
-	refname = argv[i];
+	refname = argv[0];
+	if (mode)
+		return  check_ref_format_branch(argv[2]);
 	if (normalize)
 		refname = collapse_slashes(refname);
 	if (check_refname_format(refname, flags))
-- 
gitgitgadget


  parent reply	other threads:[~2019-11-07  8:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-07  8:09 [PATCH 0/6] [Outreachy] check-ref-format: parse-options George Espinoza via GitGitGadget
2019-11-07  8:09 ` [PATCH 1/6] [Outreachy] merge-ours: include parse-option.h george espinoza via GitGitGadget
2019-11-07  9:55   ` Junio C Hamano
2019-11-07  8:09 ` [PATCH 2/6] [Outreachy] check-ref-format: parse-options george espinoza via GitGitGadget
2019-11-07 10:25   ` Junio C Hamano
2019-11-09  7:42     ` George Espinoza
2019-11-07  8:09 ` [PATCH 3/6] This file wasn't supposed to change during my git push for check-ref-format :( george espinoza via GitGitGadget
2019-11-07 10:23   ` Junio C Hamano
2019-11-07  8:09 ` [PATCH 4/6] [Outreachy] check-ref-format: parse options george espinoza via GitGitGadget
2019-11-07  8:09 ` george espinoza via GitGitGadget [this message]
2019-11-07  8:10 ` [PATCH 6/6] [Outreachy] check-ref-format: parse-options george espinoza via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aeff5d9908e80f8534144529bc5cedd6dd190021.1573114201.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=gespinoz2019@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).