git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] Re: Convert 'git blame' to parse_options()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 23, 2008, 17:04 UTC
Message-ID
<alpine.DEB.1.00.0806231756340.6440@racer>
In-Reply-To
<alpine.LFD.1.10.0806230912230.2926@woody.linux-foundation.org>
Hi,
On Mon, 23 Jun 2008, Linus Torvalds wrote:
Show 5 quoted lines
> On Mon, 23 Jun 2008, Johannes Schindelin wrote:
> > 
> > Thinking about the recursive approach again, I came up with this POC:
> 
> "recursive" is pointless.
Nope, it is not.

To keep things _simple_ a callback is not good. Sure, you can work around the limitations of callbacks for aggregation, but the code change looks horrible. And the same holds true for the help message.

Just compare that to the recursive approach.
Okay, now for the "granted, your approach has merits" part.
> Look at cmd_apply() in builtin-apply.c. Notice how it currently 
> absolutely CANNOT sanely be turned into using "parse_options()", not 
> because it needs any "recursive" handling, but simply because it wants 
> to do *incremental* handling.

That is a totally independent issue from the one I discussed, namely sane handling of the diff (and rev) options.

> 	for (;;) {
> 		const char *arg;
> 		argc = parse_options(argc, argv,
> 			options, usage, PARSE_OPT_STOP_AT_UNKNOWN);

We do have PARSE_OPT_STOP_AT_NON_OPTION since a0ec9d25(parseopt: add flag to stop on first non option), which tries to solve a _similar_ problem, and it should be not hard at all to get PARSE_OPT_STOP_AT_UNKNOWN without changing the loop as you suggested.

Heck, we could just as easily introduce PARSE_OPT_IGNORE_UNKNOWN.
> Could you handle the "recursive" use of parse_options() in builtin-blame.c 
> by teaching it about recursion? Yes. But again, it's just _simpler_ to 
> just teach parse_options() to parse the things it knows about, and leave 
> the other things in place.

And here I disagree. You might not need a nice "--help" output, but most mortals do. And this is not easy with your approach.

In contrast, by using my approach of having an option_table for a bundle of common options, which just set variables in a certain struct, you can have a relatively painless migration, and you get all the benefits of parse-options.

But I guess the approach of whoever has more time to work on it will win... ;-)

Ciao, Dscho

Previous: Johannes SixtNext: Linus Torvalds
Message 57 of 82 in “Convert 'git blame' to parse_options()”
  1. Linus TorvaldsJun 23, 2008
  2. Junio C HamanoJun 23, 2008
  3. Johannes SchindelinJun 23, 2008
  4. [RFC] Re: Convert 'git blame' to parse_options()Pierre Habouzit, Jun 23, 2008
  5. Johannes SchindelinJun 23, 2008
  6. Pierre HabouzitJun 23, 2008
  7. Johannes SchindelinJun 23, 2008
  8. Linus TorvaldsJun 23, 2008
  9. Jeff KingJun 23, 2008
  10. Linus TorvaldsJun 23, 2008
  11. Jeff KingJun 23, 2008
  12. Linus TorvaldsJun 23, 2008
  13. Jeff KingJun 23, 2008
  14. Linus TorvaldsJun 23, 2008
  15. Linus TorvaldsJun 23, 2008
  16. Jeff KingJun 23, 2008
  17. Linus TorvaldsJun 23, 2008
  18. Linus TorvaldsJun 23, 2008
  19. Pierre HabouzitJun 23, 2008
  20. parse-opt: have parse_options_{start,end}.Pierre Habouzit, Jun 23, 2008
  21. parse-opt: Export a non NORETURN usage dumper.Pierre Habouzit, Jun 23, 2008
  22. parse-opt: create parse_options_step.Pierre Habouzit, Jun 23, 2008
  23. parse-opt: do not pring errors on unknown options, return -2 intead.Pierre Habouzit, Jun 23, 2008
  24. parse-opt: fake short strings for callers to believe in.Pierre Habouzit, Jun 23, 2008
  25. Junio C HamanoJun 23, 2008
  26. Pierre HabouzitJun 23, 2008
  27. Pierre HabouzitJun 23, 2008
  28. Junio C HamanoJun 23, 2008
  29. Pierre HabouzitJun 23, 2008
  30. Linus TorvaldsJun 23, 2008
  31. Linus TorvaldsJun 23, 2008
  32. Pierre HabouzitJun 23, 2008
  33. Junio C HamanoJun 23, 2008
  34. Pierre HabouzitJun 23, 2008
  35. Pierre HabouzitJun 23, 2008
  36. Junio C HamanoJun 23, 2008
  37. Pierre HabouzitJun 23, 2008
  38. Linus TorvaldsJun 23, 2008
  39. Junio C HamanoJun 23, 2008
  40. Pierre HabouzitJun 24, 2008
  41. Jeff KingJun 24, 2008
  42. Jeff KingJun 23, 2008
  43. Pierre HabouzitJun 23, 2008
  44. Linus TorvaldsJun 23, 2008
  45. Jeff KingJun 24, 2008
  46. Linus TorvaldsJun 24, 2008
  47. Johannes SchindelinJun 24, 2008
  48. Jeff KingJun 24, 2008
  49. Linus TorvaldsJun 24, 2008
  50. Jeff KingJun 24, 2008
  51. Junio C HamanoJun 24, 2008
  52. Pierre HabouzitJun 24, 2008
  53. Linus TorvaldsJun 24, 2008
  54. Pierre HabouzitJun 24, 2008
  55. Pierre HabouzitJun 24, 2008
  56. Johannes SixtJun 25, 2008
  57. Johannes SchindelinJun 23, 2008
  58. Linus TorvaldsJun 23, 2008
  59. Johannes SchindelinJun 23, 2008
  60. Jeff KingJun 23, 2008
  61. Johannes SchindelinJun 23, 2008
  62. Pierre HabouzitJun 23, 2008
  63. Linus TorvaldsJun 23, 2008
  64. Making parse-opt incremental, reworked seriesPierre Habouzit, Jun 24, 2008
  65. 1/7 parse-opt: have parse_options_{start,end}.Pierre Habouzit, Jun 24, 2008
  66. 2/7 parse-opt: Export a non NORETURN usage dumper.Pierre Habouzit, Jun 24, 2008
  67. 3/7 parse-opt: create parse_options_step.Pierre Habouzit, Jun 24, 2008
  68. 4/7 parse-opt: do not pring errors on unknown options, return -2 intead.Pierre Habouzit, Jun 24, 2008
  69. 5/7 parse-opt: fake short strings for callers to believe in.Pierre Habouzit, Jun 24, 2008
  70. 6/7 parse-opt: add PARSE_OPT_KEEP_ARGV0 parser option.Pierre Habouzit, Jun 24, 2008
  71. 7/7 Migrate git-blame to parse-option partially.Pierre Habouzit, Jun 24, 2008
  72. Pierre HabouzitJun 24, 2008
  73. Linus TorvaldsJun 24, 2008
  74. Pierre HabouzitJun 24, 2008
  75. Pierre HabouzitJun 24, 2008
  76. Linus TorvaldsJun 24, 2008
  77. Pierre HabouzitJun 24, 2008
  78. Andreas EricssonJun 25, 2008
  79. parse-opt: fake short strings for callers to believe in.Pierre Habouzit, Jun 24, 2008
  80. Pierre HabouzitJun 26, 2008
  81. Junio C HamanoJun 26, 2008
  82. Pierre HabouzitJun 26, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.