From 5e3b370b3bf8f34cd975da41fb2a7cc0f633954a Mon Sep 17 00:00:00 2001 From: george espinoza Date: Mon, 28 Oct 2019 12:47:49 -0700 Subject: [PATCH 1/4] [Outreachy] merge-ours: include parse-option.h Prepare this command which currently handles its own argv to use parse-options instead. A lot of the commands already have parse-options and in git.c cmd_struct with the "NO_PARSEOPT" are the one's that still need it. Signed-off-by: george espinoza --- builtin/merge-ours.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c index 45945074205332..3980f4899a617f 100644 --- a/builtin/merge-ours.c +++ b/builtin/merge-ours.c @@ -11,6 +11,11 @@ #include "git-compat-util.h" #include "builtin.h" #include "diff.h" +#include "parse-options.h" + +/* parse-options.h added to initiate replacement of manual option parsing + * with parse-options. + */ static const char builtin_merge_ours_usage[] = "git merge-ours ... -- HEAD ..."; From e8bca0910e7ba7582a50115eeeb66406d965a52a Mon Sep 17 00:00:00 2001 From: george espinoza Date: Sat, 2 Nov 2019 21:28:43 -0700 Subject: [PATCH 2/4] [Outreachy] check-ref-format: parse-options 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 has been 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 Helped by: johannes schindelin Signed-off-by: george espinoza --- builtin/check-ref-format.c | 49 +++++++++++++++++++------------------- git.c | 2 +- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index bc67d3f0a83d35..3fe0b5410a8122 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -6,10 +6,13 @@ #include "refs.h" #include "builtin.h" #include "strbuf.h" +#include "parse-options.h" -static const char builtin_check_ref_format_usage[] = -"git check-ref-format [--normalize] [] \n" -" or: git check-ref-format --branch "; +static const char * const builtin_check_ref_format_usage[] = { + N_("git check-ref-format [--normalize] [] \n"), + N_(" or: git check-ref-format --branch "), + NULL, +}; /* * Return a copy of refname but with leading slashes removed and runs @@ -53,31 +56,29 @@ static int check_ref_format_branch(const char *arg) int cmd_check_ref_format(int argc, const char **argv, const char *prefix) { - int i; - int normalize = 0; + enum { + CHECK_REF_FORMAT_BRANCH, + }; + + int i = 0; + int verbose; + int normalize; + int allow_onelevel; + int refspec_pattern; int flags = 0; const char *refname; - if (argc == 2 && !strcmp(argv[1], "-h")) - usage(builtin_check_ref_format_usage); - - if (argc == 3 && !strcmp(argv[1], "--branch")) - return check_ref_format_branch(argv[2]); + 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_BOOL( 0 , "allow-onelevel", &allow_onelevel, N_("allow one level")), + OPT_BOOL( 0 , "refspec-pattern", &refspec_pattern, N_("refspec pattern")), + OPT_END(), + }; - 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, PARSE_OPT_KEEP_ARGV0); refname = argv[i]; if (normalize) diff --git a/git.c b/git.c index ce6ab0ece2cc6d..13dbfde31c60fe 100644 --- a/git.c +++ b/git.c @@ -478,7 +478,7 @@ static struct cmd_struct commands[] = { { "check-attr", cmd_check_attr, RUN_SETUP }, { "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE }, { "check-mailmap", cmd_check_mailmap, RUN_SETUP }, - { "check-ref-format", cmd_check_ref_format, NO_PARSEOPT }, + { "check-ref-format", cmd_check_ref_format }, { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE }, { "checkout-index", cmd_checkout_index, RUN_SETUP | NEED_WORK_TREE}, From 078a19e86af6fcf1348d8988dc10cfac2e689ba4 Mon Sep 17 00:00:00 2001 From: george espinoza Date: Sat, 2 Nov 2019 22:08:29 -0700 Subject: [PATCH 3/4] This file wasn't supposed to change during my git push for check-ref-format :( Signed-off-by: george espinoza --- builtin/merge-ours.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c index 3980f4899a617f..45945074205332 100644 --- a/builtin/merge-ours.c +++ b/builtin/merge-ours.c @@ -11,11 +11,6 @@ #include "git-compat-util.h" #include "builtin.h" #include "diff.h" -#include "parse-options.h" - -/* parse-options.h added to initiate replacement of manual option parsing - * with parse-options. - */ static const char builtin_merge_ours_usage[] = "git merge-ours ... -- HEAD ..."; From 4f0d7f0882b8fc4427f06128925a90504cf48dc3 Mon Sep 17 00:00:00 2001 From: george espinoza Date: Sat, 2 Nov 2019 22:17:27 -0700 Subject: [PATCH 4/4] [Outreachy] check-ref-format: parse-options 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 has been 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 Helped by: johannes schindelin Signed-off-by: george espinoza --- builtin/check-ref-format.c | 1 - 1 file changed, 1 deletion(-) diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c index 3fe0b5410a8122..4808947548f9f4 100644 --- a/builtin/check-ref-format.c +++ b/builtin/check-ref-format.c @@ -59,7 +59,6 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix) enum { CHECK_REF_FORMAT_BRANCH, }; - int i = 0; int verbose; int normalize;