Re: [PATCH 1/4] Add a simple option parser for use by builtin-commit.c.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Kristian <krh@...>
Cc: <gitster@...>, <git@...>
Date: Sunday, September 30, 2007 - 9:11 am

Hello Kristian,

I have some comments on your patch. Some of the "improvement" might have
to wait until after your builtin-commit changes hits git.git. However,
if we could agree on some of the general changes, I could start porting
other of the main porcelain commands to use the option parser without
depending on the state of the remaining builtin-commit series.

Kristian Høgsberg <krh@redhat.com> wrote Thu, Sep 27, 2007:

I don't know if this is a bug, but you do not remove "--" from argv,
which is later (in the patch that adds builtin-commit.c) passed to
add_files_to_cache and then get_pathspec where it is not removed or
detected either.


I think the goto can be avoided by simply breaking out of the above loop
when an option has been found and add ...

	case OPTION_LAST
		usage(usage_string);
		break;


I've been looking at builtin-blame.c which IMO has some of the most
obscure option parsing and maybe this can be changed to increment in
order to support stuff like changing the meaning by passing the same arg
multiple times (e.g. "-C -C -C") better.

Blame option parsing also sports (enum) flags being masked together,
this can of course be rewritten to a boolean option followed by
masking when parse_options is done (to keep it sane).


Maybe change this ...


... and this to:

		if (!value) {
			error("option %s requires a value.", (*argv)[-1]);
			usage(usage_string);
		}


Space vs tab indentation.

One of the last things I miss from Cogito is the nice abbreviated help
messages that was available via '-h'. I don't know if it would be
acceptable (at least for the main porcelain commands) to put this
functionality into the option parser by adding a "description" member to
struct option and have parse_options print a nice:

	<error message if any>
	<usage string>
	<option summary>

on failure, or, if that is regarded as too verbose, simply when -h is
detected.


This prefix aware option parsing has not been ported over to the other
builtins when they were lifted from shell code. It might be nice to have
of course. Is it really needed?


I think the interface could be improved a bit. For example, it doesn't
need to count argument since the last entry in the options array is
OPTION_LAST and thus the size can be detected that way.

Also, I think for this to be more usable for other built-in programs it
shouldn't modify argv, but instead take both argc and argv (so we don't
need to have code like "*++(*argv)" ;), parse _all_ options in one go,
and return the index (of argv) for any remaining options.

Then the following:

	while (parse_options(argv, commit_options, ARRAY_SIZE(commit_options),
		builtin_commit_usage))
		;

becomes:

	int i;
	...
	i = parse_options(argc, argv, commit_options, builtin_commit_usage);

This fits better with how option parsing is currently done. Take
builtin-add for example:

	for (i = 1 ; i < argc ; i++) {
		const char *arg = argv[i];
		/* ... */
	}
	if (argc <= i)
		usage(builtin_rm_usage);

[ BTW, blame option parsing actually wants to know if "--" has been seen,
  but I think that can be worked around by simply checking argv[i - 1]
  after calling the option parser. ]


OK, I will stop these ramblings here. I hope the fact that I read your
patch both back and forth and added comments in the process didn't make
it too confusing.

-- 
Jonas Fonseca
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/4] Add a simple option parser for use by builtin-co..., Kristian Høgsberg, (Thu Sep 27, 12:50 am)
Re: [PATCH 1/4] Add a simple option parser for use by builti..., Jonas Fonseca, (Sun Sep 30, 9:11 am)
Re: [PATCH 1/4] Add a simple option parser for use by builti..., Johannes Schindelin, (Mon Oct 1, 2:13 pm)
Re: [PATCH 1/4] Add a simple option parser for use by builti..., Johannes Schindelin, (Mon Oct 1, 6:14 am)
Re: [PATCH 1/4] Add a simple option parser for use by builti..., Johannes Schindelin, (Mon Oct 1, 7:39 am)
[PATCH 2/4] This exports the update() function from builtin-..., Kristian Høgsberg, (Thu Sep 27, 12:50 am)
Re: [PATCH 2/4] This exports the update() function from buil..., Johannes Schindelin, (Thu Sep 27, 7:47 am)
[PATCH 3/4] Implement git commit as a builtin command., Kristian Høgsberg, (Thu Sep 27, 12:50 am)