Re: [PATCH/RFC] gitopt - command-line parsing enhancements

From: Junio C Hamano <>
Date: 2006-05-10 06:28:23
Eric Wong <> writes:

>> And scary, especially the "eat" macros are very scary.
> They look weird at first, but I think they help readability and
> maintainability once you get used to them.  They let you focus on the
> important part of the function while hiding the boring parts from you.
> Quite elegant, imho.

Sorry, there is no elegance to it as far as I can see.  A macro
invocation that creates a private function while it does not
look like a function definition is already bad, you cannot have
a comma in the stmt part, and the bare semicolons in the
parenthesised text look insane.

If your patch were like this, it would have been a bit easier
for me to understand what was going on during my first pass:

    static struct exec_args *ui_optparse
            (struct opt_spec *s, int ac, char **av, int *ac_p, int what)
            struct exec_args *ea = one_arg(s, ac, av, ac_p);
            if (!ea) return NULL;
            switch (what) {
            case IGNORE_MISSING:
                    not_new = 1; break;
            case VERBOSE:
                    verbose = 1; break;
            case HELP:
                    usage(update_index_usage); break;
            return nil_exec_args(ea);

instead of

    gitopt_eat(opt_ignore_missing, not_new = 1;)
    gitopt_eat(opt_verbose, verbose = 1;)
    gitopt_eat(opt_h, usage(update_index_usage);)

Then, you would give an extra element in the table, and your
argument parsing/splitting routine passes that one to the
handler function:

    static const struct opt_spec update_index_ost[] = {
    { "ignore-missing", 0,	0, 0, ui_optparse, IGNORE_MISSING },
    { "verbose",	    0,	0, 0, ui_optparse, VERBOSE },
    { "help",	   'h',	0, 0, ui_optparse, HELP },
    { 0, 0 }

Another thing is I do not think we would want to make the
argument parsing into callback style interface like you did.  It
actively encourages the option variables to be global (you could
make it file scoped static but they are global nevertheless).
If you can make it an iterator style, it would be a lot easier
to see what is going on, I suspect.  Then you would not even
need the callback function pointers and small functions created
by magic eat() macros.

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at
Received on Wed May 10 06:29:08 2006

This archive was generated by hypermail 2.1.8 : 2006-05-10 06:29:30 EST