{"thread":{"id":"4107","subject":"[PATCH/RFC] gitopt - command-line parsing enhancements","startedAt":"2006-05-09T05:06:43Z","lastAt":"2006-05-09T21:14:13Z","messageCount":5,"participants":["Eric Wong","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19764","messageId":"1147151209168-git-send-email-normalperson@yhbt.net","threadId":"4107","inReplyTo":null,"subject":"[PATCH/RFC] gitopt - command-line parsing enhancements","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-05-09T05:06:43Z","receivedAt":"2006-05-09T05:06:43Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"\nHere's my take at a new command-line option parser to reduce wear on my\nfingers.  It handles both long and short options, permuting, automatic\nabbreviations, required arguments, optional arguments, and bundling.\n\nIt doesn't use getopt or argp, so it should be easily portable to\nnon-GNU systems (and only uses git-isms trivially, so other programs can\nuse it easily, too).\n\nI've tested everything lightly but it seems to be working well.  The\nunit test was very helpful throughout.\nMore intensive testing, bugfixes and comments would be greatly\nappreciated.\n\nIt should be pretty easy to convert other git-* programs to use gitopt,\nand write shell wrappers for git.c like I did with am/checkout/commit.\nI'll probably do so in a few days once my fingers recover a bit, of\ncourse feedback and patches for bug reports/enhancements are encouraged,\ntoo.\n\n1 - gitopt: a new command-line option parser for git\n\tThis adds the parser, tests, and some simple changes to\n\tthe git.c wrapper.\n\n2 - update-index: convert to using gitopt\n3 - ls-tree: convert to gitopt\n4 - ls-files: convert to using gitopt\n\tThese three are fairly straightforward conversions.\n\tI was somewhat disappointed that update-index didn't take\n\tkindly to permuting arguments, but it's also a good example\n\thow to disable permuting via gitopt: a == b\n\n5 - gitopt: convert setup_revisions(), and diff_opt_parse()\n\tThis is a fairly intrusive change that affects several\n\timportant programs.  All the tests still pass, so it must be\n\tworking :)\n\n6 - commit: allow --pretty= args to be abbreviated\n\tThis one isn't strictly dependent on gitopt, and can be\n\ttrivially changed to work without the parent patches.\n\n-- \nEric Wong\n"},{"id":"19775","messageId":"7vzmhr7fys.fsf@assigned-by-dhcp.cox.net","threadId":"4107","inReplyTo":"1147151209168-git-send-email-normalperson@yhbt.net","subject":"Re: [PATCH/RFC] gitopt - command-line parsing enhancements","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-09T08:35:55Z","receivedAt":"2006-05-09T08:35:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Wong <normalperson@yhbt.net> writes:\n\n> Here's my take at a new command-line option parser to reduce wear on my\n> fingers.  It handles both long and short options, permuting, automatic\n> abbreviations, required arguments, optional arguments, and bundling.\n\nTaken a superficial look at it.\n\nSounds nice, might be a tad too ambitious though.  Looks\nintrusive at places.\n\nAnd scary, especially the \"eat\" macros are very scary.\n\nI have to think about it a bit.\n"},{"id":"19791","messageId":"20060509194825.GC3676@localdomain","threadId":"4107","inReplyTo":"7vzmhr7fys.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH/RFC] gitopt - command-line parsing enhancements","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-05-09T19:48:25Z","receivedAt":"2006-05-09T19:48:25Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Eric Wong <normalperson@yhbt.net> writes:\n> \n> > Here's my take at a new command-line option parser to reduce wear on my\n> > fingers.  It handles both long and short options, permuting, automatic\n> > abbreviations, required arguments, optional arguments, and bundling.\n> \n> Taken a superficial look at it.\n> \n> Sounds nice, might be a tad too ambitious though.  Looks\n> intrusive at places.\n\nI wasn't overly happy with the addition of global variables to existing\nfiles and the way they're set (setup_revisions).  But at least they're\nstatic.  Of course, I'm not yet certain that I haven't introduced new\nbugs.  All the tests pass, at least...\n\n> And scary, especially the \"eat\" macros are very scary.\n\nThey look weird at first, but I think they help readability and\nmaintainability once you get used to them.  They let you focus on the\nimportant part of the function while hiding the boring parts from you.\nQuite elegant, imho.\n\n-- \nEric Wong\n"},{"id":"19794","messageId":"7vr7332ba0.fsf@assigned-by-dhcp.cox.net","threadId":"4107","inReplyTo":"20060509194825.GC3676@localdomain","subject":"Re: [PATCH/RFC] gitopt - command-line parsing enhancements","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-09T20:28:23Z","receivedAt":"2006-05-09T20:28:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Wong <normalperson@yhbt.net> writes:\n\n>> And scary, especially the \"eat\" macros are very scary.\n>\n> They look weird at first, but I think they help readability and\n> maintainability once you get used to them.  They let you focus on the\n> important part of the function while hiding the boring parts from you.\n> Quite elegant, imho.\n\nSorry, there is no elegance to it as far as I can see.  A macro\ninvocation that creates a private function while it does not\nlook like a function definition is already bad, you cannot have\na comma in the stmt part, and the bare semicolons in the\nparenthesised text look insane.\n\nIf your patch were like this, it would have been a bit easier\nfor me to understand what was going on during my first pass:\n\n    static struct exec_args *ui_optparse\n            (struct opt_spec *s, int ac, char **av, int *ac_p, int what)\n    {\n            struct exec_args *ea = one_arg(s, ac, av, ac_p);\n            if (!ea) return NULL;\n            switch (what) {\n            case IGNORE_MISSING:\n                    not_new = 1; break;\n            case VERBOSE:\n                    verbose = 1; break;\n            case HELP:\n                    usage(update_index_usage); break;\n            }\n            return nil_exec_args(ea);\n    }\n\ninstead of\n\n    gitopt_eat(opt_ignore_missing, not_new = 1;)\n    gitopt_eat(opt_verbose, verbose = 1;)\n    gitopt_eat(opt_h, usage(update_index_usage);)\n\nThen, you would give an extra element in the table, and your\nargument parsing/splitting routine passes that one to the\nhandler function:\n\n    static const struct opt_spec update_index_ost[] = {\n    ...\n    { \"ignore-missing\", 0,\t0, 0, ui_optparse, IGNORE_MISSING },\n    { \"verbose\",\t    0,\t0, 0, ui_optparse, VERBOSE },\n    { \"help\",\t   'h',\t0, 0, ui_optparse, HELP },\n    { 0, 0 }\n\nAnother thing is I do not think we would want to make the\nargument parsing into callback style interface like you did.  It\nactively encourages the option variables to be global (you could\nmake it file scoped static but they are global nevertheless).\nIf you can make it an iterator style, it would be a lot easier\nto see what is going on, I suspect.  Then you would not even\nneed the callback function pointers and small functions created\nby magic eat() macros.\n"},{"id":"19798","messageId":"20060509211413.GA12589@localdomain","threadId":"4107","inReplyTo":"7vr7332ba0.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH/RFC] gitopt - command-line parsing enhancements","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-05-09T21:14:13Z","receivedAt":"2006-05-09T21:14:13Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> If you can make it an iterator style, it would be a lot easier\n> to see what is going on, I suspect.  Then you would not even\n> need the callback function pointers and small functions created\n> by magic eat() macros.\n\nThat sounds like a great idea, I'll work on it tonight.\n\n-- \nEric Wong\n"}]}