git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/6] [Outreachy] check-ref-format: parse-options
@ 2019-11-07  8:09 George Espinoza via GitGitGadget
  2019-11-07  8:09 ` [PATCH 1/6] [Outreachy] merge-ours: include parse-option.h george espinoza via GitGitGadget
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: George Espinoza via GitGitGadget @ 2019-11-07  8:09 UTC (permalink / raw)
  To: git; +Cc: George Espinoza, Junio C Hamano

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.

This is Micro-Project #3 that states: Teach a command which currently
handles its own argv how to use parse-options instead..

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

Signed-off-by: george espinoza gespinoz2019@gmail.com
[gespinoz2019@gmail.com]

george espinoza (6):
  [Outreachy] merge-ours: include parse-option.h
  [Outreachy] check-ref-format: parse-options
  This file wasn't supposed to change during my git push for
    check-ref-format :(
  [Outreachy] check-ref-format: parse options
  [Outreachy] check-ref-format: parse-options
  [Outreachy] check-ref-format: parse-options

 builtin/check-ref-format.c | 47 +++++++++++++++++++-------------------
 git.c                      |  2 +-
 2 files changed, 24 insertions(+), 25 deletions(-)


base-commit: efd54442381a2792186abc994060b8f7dd8b834b
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-449%2FGeorgecanfly%2Fcheck-ref-format-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-449/Georgecanfly/check-ref-format-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/449
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/6] [Outreachy] merge-ours: include parse-option.h
  2019-11-07  8:09 [PATCH 0/6] [Outreachy] check-ref-format: parse-options George Espinoza via GitGitGadget
@ 2019-11-07  8:09 ` 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
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: george espinoza via GitGitGadget @ 2019-11-07  8:09 UTC (permalink / raw)
  To: git; +Cc: George Espinoza, Junio C Hamano, george espinoza

From: george espinoza <gespinoz2019@gmail.com>

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 <gespinoz2019@gmail.com>
---
 builtin/merge-ours.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index 4594507420..3980f4899a 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 <base>... -- HEAD <remote>...";
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/6] [Outreachy] check-ref-format: parse-options
  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  8:09 ` george espinoza via GitGitGadget
  2019-11-07 10:25   ` Junio C Hamano
  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
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: george espinoza via GitGitGadget @ 2019-11-07  8:09 UTC (permalink / raw)
  To: git; +Cc: George Espinoza, Junio C Hamano, george espinoza

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 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 <emilyshaffer@google.com>
Helped by: johannes schindelin <johannes.schindelin@gmx.de>

Signed-off-by: george espinoza <gespinoz2019@gmail.com>
---
 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 bc67d3f0a8..3fe0b5410a 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] [<options>] <refname>\n"
-"   or: git check-ref-format --branch <branchname-shorthand>";
+static const char * const builtin_check_ref_format_usage[] = {
+	N_("git check-ref-format [--normalize] [<options>] <refname>\n"),
+	N_("   or: git check-ref-format --branch <branchname-shorthand>"),
+	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 ce6ab0ece2..13dbfde31c 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},
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/6] This file wasn't supposed to change during my git push for check-ref-format :(
  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  8:09 ` [PATCH 2/6] [Outreachy] check-ref-format: parse-options george espinoza via GitGitGadget
@ 2019-11-07  8:09 ` 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
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: george espinoza via GitGitGadget @ 2019-11-07  8:09 UTC (permalink / raw)
  To: git; +Cc: George Espinoza, Junio C Hamano, george espinoza

From: george espinoza <gespinoz2019@gmail.com>

Signed-off-by: george espinoza <gespinoz2019@gmail.com>
---
 builtin/merge-ours.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index 3980f4899a..4594507420 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 <base>... -- HEAD <remote>...";
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/6] [Outreachy] check-ref-format: parse options
  2019-11-07  8:09 [PATCH 0/6] [Outreachy] check-ref-format: parse-options George Espinoza via GitGitGadget
                   ` (2 preceding siblings ...)
  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  8:09 ` george espinoza via GitGitGadget
  2019-11-07  8:09 ` [PATCH 5/6] [Outreachy] check-ref-format: parse-options george espinoza via GitGitGadget
  2019-11-07  8:10 ` [PATCH 6/6] " george espinoza via GitGitGadget
  5 siblings, 0 replies; 11+ messages in thread
From: george espinoza via GitGitGadget @ 2019-11-07  8:09 UTC (permalink / raw)
  To: git; +Cc: George Espinoza, Junio C Hamano, george espinoza

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/6] [Outreachy] check-ref-format: parse-options
  2019-11-07  8:09 [PATCH 0/6] [Outreachy] check-ref-format: parse-options George Espinoza via GitGitGadget
                   ` (3 preceding siblings ...)
  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
  2019-11-07  8:10 ` [PATCH 6/6] " george espinoza via GitGitGadget
  5 siblings, 0 replies; 11+ messages in thread
From: george espinoza via GitGitGadget @ 2019-11-07  8:09 UTC (permalink / raw)
  To: git; +Cc: George Espinoza, Junio C Hamano, george espinoza

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/6] [Outreachy] check-ref-format: parse-options
  2019-11-07  8:09 [PATCH 0/6] [Outreachy] check-ref-format: parse-options George Espinoza via GitGitGadget
                   ` (4 preceding siblings ...)
  2019-11-07  8:09 ` [PATCH 5/6] [Outreachy] check-ref-format: parse-options george espinoza via GitGitGadget
@ 2019-11-07  8:10 ` george espinoza via GitGitGadget
  5 siblings, 0 replies; 11+ messages in thread
From: george espinoza via GitGitGadget @ 2019-11-07  8:10 UTC (permalink / raw)
  To: git; +Cc: George Espinoza, Junio C Hamano, george espinoza

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.

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 | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index be3b1bd84d..ea703cfabd 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -61,18 +61,15 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
 		CHECK_REF_FORMAT_BRANCH,
 	} mode = CHECK_REFNAME_FORMAT;
 
-	int verbose = 0;
 	int normalize = 0;
 	int flags = 0;
 	const char *refname;
 
 	struct option options[] = {
-		OPT__VERBOSE(&verbose, N_("be verbose")),
 		OPT_GROUP(""),
-		OPT_CMDMODE(0 , "branch", &mode, N_("branch"), CHECK_REF_FORMAT_BRANCH),
+		OPT_CMDMODE(0 , "branch", &mode, N_("check for valid branch name"), 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(),
 	};
@@ -81,7 +78,7 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
 
 	refname = argv[0];
 	if (mode)
-		return  check_ref_format_branch(argv[2]);
+		return check_ref_format_branch(argv[2]);
 	if (normalize)
 		refname = collapse_slashes(refname);
 	if (check_refname_format(refname, flags))
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/6] [Outreachy] merge-ours: include parse-option.h
  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
  0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2019-11-07  9:55 UTC (permalink / raw)
  To: george espinoza via GitGitGadget; +Cc: git, George Espinoza

"george espinoza via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: george espinoza <gespinoz2019@gmail.com>
>
> 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 <gespinoz2019@gmail.com>
> ---
>  builtin/merge-ours.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
> index 4594507420..3980f4899a 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. 
> + */

See Documentation/CodingGuidelines and learn how we write multi-line
comments.

Since there is no "manual option parsing" to be replaced, there is
no other change to this file, I guess (so what's the point of this
step?).



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/6] This file wasn't supposed to change during my git push for check-ref-format :(
  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
  0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2019-11-07 10:23 UTC (permalink / raw)
  To: george espinoza via GitGitGadget; +Cc: git, George Espinoza

"george espinoza via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: george espinoza <gespinoz2019@gmail.com>
>
> Signed-off-by: george espinoza <gespinoz2019@gmail.com>
> ---

While developing your first patch, it is expected that you make
mistake in an earlier step (e.g. 2/6) and then later realize it and
want to fix, like this one.  Instead of going back to the earlier
mistake and fixing it right there before building more on top,
tentatively fixing with "oops that was wrong" like this one and
building further (i.e. 4 and later steps) is an expedient way.

But once you are done, you need to get your act together before
presenting the resulting series to the general public.

Please learn to use "rebase -i" to clean up the series before
asking GGG to publish it to the list.

Thanks.

>  builtin/merge-ours.c | 5 -----
>  1 file changed, 5 deletions(-)
>
> diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
> index 3980f4899a..4594507420 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 <base>... -- HEAD <remote>...";

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/6] [Outreachy] check-ref-format: parse-options
  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
  0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2019-11-07 10:25 UTC (permalink / raw)
  To: george espinoza via GitGitGadget; +Cc: git, George Espinoza

"george espinoza via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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 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 <emilyshaffer@google.com>
> Helped by: johannes schindelin <johannes.schindelin@gmx.de>

I do not think they spell their name like the above.  In general,
most of us do not spell our names in all lowercase around here. I
appreciate people with originality, but I'd rather see them to be
original not in how they spell their names but in more productive
ways ;-)

> Signed-off-by: george espinoza <gespinoz2019@gmail.com>
> ---
>  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 bc67d3f0a8..3fe0b5410a 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] [<options>] <refname>\n"
> -"   or: git check-ref-format --branch <branchname-shorthand>";
> +static const char * const builtin_check_ref_format_usage[] = {
> +	N_("git check-ref-format [--normalize] [<options>] <refname>\n"),
> +	N_("   or: git check-ref-format --branch <branchname-shorthand>"),
> +	NULL,
> +};

OK.  This is the bog-standard prep for calling usage_with_options().

> @@ -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;

Discard the blank line before "int i = 0" line, and keep the blank
line you have here between the last declaration and the first
statement.

> -	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),

This is an iffy/tricky way to use CMDMODE.  The way CMDMODE is
designed to be used is to have multiple ones that sets the same
target variable so that parse_options() can notice conflicting
command line request that gives more than one from the same set.

The command has two modes (i.e. the "--branch" mode and the unnamed
mode), so it is understandable that there is only one CMDMODE in the
options[] array, but I am not sure how well it would work for a
command like this.  For example, "check-ref-format --branch
--normalize --allow-onelevel $v" should error out because --branch
is not compatible with any other options.  I do not think a single
parse_options() call with a single options[] array can express that
kind of constraints.

Besides, shouldn't the third parameter of OPT_CMDMODE supposed to be
the address of the variable that would receive the value in its fifth
parameter?  I do not see a decl for check_ref_format_branch variable
(isn't that the name of the function???).

Ahh, you said it builds but does not pass test.  Of course, that is
because this part is completely bogus.

It appears that to your series the only thing that matters is the
shape of the tree after applying all of the patches, and individual
steps are not ready to be reviewd, so I'd stop here.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/6] [Outreachy] check-ref-format: parse-options
  2019-11-07 10:25   ` Junio C Hamano
@ 2019-11-09  7:42     ` George Espinoza
  0 siblings, 0 replies; 11+ messages in thread
From: George Espinoza @ 2019-11-09  7:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: george espinoza via GitGitGadget, Git List

On Thu, Nov 7, 2019 at 2:25 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> "george espinoza via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > 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 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 <emilyshaffer@google.com>
> > Helped by: johannes schindelin <johannes.schindelin@gmx.de>
>
> I do not think they spell their name like the above.  In general,
> most of us do not spell our names in all lowercase around here. I
> appreciate people with originality, but I'd rather see them to be
> original not in how they spell their names but in more productive
> ways ;-)
>

Ah, I see. I will use capital letters.
> > Signed-off-by: george espinoza <gespinoz2019@gmail.com>
> > ---
> >  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 bc67d3f0a8..3fe0b5410a 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] [<options>] <refname>\n"
> > -"   or: git check-ref-format --branch <branchname-shorthand>";
> > +static const char * const builtin_check_ref_format_usage[] = {
> > +     N_("git check-ref-format [--normalize] [<options>] <refname>\n"),
> > +     N_("   or: git check-ref-format --branch <branchname-shorthand>"),
> > +     NULL,
> > +};
>
> OK.  This is the bog-standard prep for calling usage_with_options().

I see, I will look into doing something more here as necessary.
>
> > @@ -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;
>
> Discard the blank line before "int i = 0" line, and keep the blank
> line you have here between the last declaration and the first
> statement.

I meant to squash all my earlier commits but had an issue with git rebase -i.
It only says noop. I had an issue when I first started my other branch
and might of reset it. I'll look into fixing this before submitting my
next patch.
>
> > -     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),
>
> This is an iffy/tricky way to use CMDMODE.  The way CMDMODE is
> designed to be used is to have multiple ones that sets the same
> target variable so that parse_options() can notice conflicting
> command line request that gives more than one from the same set.
>
> The command has two modes (i.e. the "--branch" mode and the unnamed
> mode), so it is understandable that there is only one CMDMODE in the
> options[] array, but I am not sure how well it would work for a
> command like this.  For example, "check-ref-format --branch
> --normalize --allow-onelevel $v" should error out because --branch
> is not compatible with any other options.  I do not think a single
> parse_options() call with a single options[] array can express that
> kind of constraints.

Ok I will look into another data structure to use for branch.
>
> Besides, shouldn't the third parameter of OPT_CMDMODE supposed to be
> the address of the variable that would receive the value in its fifth
> parameter?  I do not see a decl for check_ref_format_branch variable
> (isn't that the name of the function???).
>
> Ahh, you said it builds but does not pass test.  Of course, that is
> because this part is completely bogus.
>
> It appears that to your series the only thing that matters is the
> shape of the tree after applying all of the patches, and individual
> steps are not ready to be reviewd, so I'd stop here.
>

I had only intended /submit to show the last commit I had made that had passed
all the tests. I will review everything and only submit again once im 100%
sure everything is in order. Sorry Junio!

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-11-09  7:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 5/6] [Outreachy] check-ref-format: parse-options george espinoza via GitGitGadget
2019-11-07  8:10 ` [PATCH 6/6] " george espinoza via GitGitGadget

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).