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

Re: [PATCH] config: Use parseopt.

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Feb 14, 2009, 12:15 UTC
Message-ID
<94a0d4530902140415j4168d09dh8abac0d6eba0b8cf@mail.gmail.com>
In-Reply-To
<alpine.DEB.1.00.0902141230250.10279@pacific.mpi-cbg.de>

On Sat, Feb 14, 2009 at 1:40 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:

Show 17 quoted lines
> Hi,
>
> On Sat, 14 Feb 2009, Felipe Contreras wrote:
>
>> Then why are you asking?
>
> Out of curiosity, I guess, as it would happen to answer my curiosity as
> well.
>
>> This is more a "I would like to increase the chances of my patches
>> being accepted so I'd do some chores to gain the trust of some
>> developers", and Johannes Schindelin was pushing me to do this.
>
> Heh, I'll gladly take the blame for that!
>
> Note that in contrast to Junio, I think "git config" is a chimera between
> plumbing and porcelain, and would benefit tremendously from a nice help.
I agree on that.
Show 52 quoted lines
>> >> +static int type_int, type_bool, type_bool_or_int;
>> >
>> > You can have either (no type specified, int, bool, bool-or-int) at the
>> > end.  Using three independent variables does not feel right.
>> >
>> > Hint: OPTION_SET_INT.
>>
>> That definitely makes things easier, it would have been nice to see an
>> example of this; I didn't knew it was there.
>>
>> The only problem is that --bool and --int would be possible in the
>> same command and there would be no way to output an error, but I guess
>> that's not a big problem.
>
> I think that is okay.
>
>> >> +     else if (do_add) {
>> >> +             if (argc > 2)
>> >> +                     die("Too many arguments.");
>> >> +             if (argc != 2)
>> >> +                     die("Need name value.");
>> >> +             value = normalize_value(argv[0], argv[1]);
>> >> +             return git_config_set_multivar(argv[0], value, "^$", 0);
>> >
>> > This part did not lose argc error checking, but...
>> >
>> >> +     }
>> >> +     else if (do_replace_all) {
>> >> +             value = normalize_value(argv[0], argv[1]);
>> >> +             return git_config_set_multivar(argv[0], value, (argc == 3 ? argv[2] : NULL), 1);
>> >
>> > You do not check argc here (nor in many "else if" below) to make sure you
>> > have sufficient number of arguments.  "git config --unset" is now allowed
>> > to segfault, and "git config --unset a b c d e f" can silently ignore
>> > excess arguments for example?
>>
>> Yes the arguments check need to be revised.
>>
>> My hope was somebody would review this and suggest a clever and
>> generic way of doing this. Perhaps a util function check_min_args, or
>> maybe something in parseopt that receives the number of args?
>
> Maybe a helper, yes.  Something like:
>
>        static void check_argc(int argc, int min, int max) {
>                if (argc >= min && argc <= max)
>                        return;
>                fprintf(stderr, "Wrong number of arguments: %d\n", argc);
>                usage_with_options(config_usage, config_options);
>        }
>
> Of course, this assumes that config_usage and config_options are global...
Cool.

I've sent a new patch with this helper (a bit modified), and all the changes Junio suggested.

I still have a few doubts:
1) --list when no config file is given uses all the config files,
wouldn't it make sense to have a --repo option?
2) --get-colorbool prints "true" or "false" only when there are two
arguments, is that correct or should stdout_is_tty be used instead?
3) should the documentation be updated for the --get-color* options to
use 'slot' instead of 'name'?
-- 
Felipe Contreras
Previous: Junio C HamanoNext: Johannes Schindelin
Message 29 of 45 in “config: Use parseopt.”
  1. config: Use parseopt.Felipe Contreras, Feb 14, 2009
  2. Junio C HamanoFeb 14, 2009
  3. Junio C HamanoFeb 14, 2009
  4. Felipe ContrerasFeb 14, 2009
  5. Felipe ContrerasFeb 14, 2009
  6. Johannes SchindelinFeb 14, 2009
  7. config: Use parseopt.Felipe Contreras, Feb 14, 2009
  8. Jeff KingFeb 14, 2009
  9. Felipe ContrerasFeb 14, 2009
  10. Johannes SchindelinFeb 14, 2009
  11. Junio C HamanoFeb 14, 2009
  12. human readable diffs, was Re: [PATCH v2] config: Use parseopt.Johannes Schindelin, Feb 14, 2009
  13. Felipe ContrerasFeb 14, 2009
  14. Johannes SchindelinFeb 14, 2009
  15. Jakub NarebskiFeb 14, 2009
  16. Johannes SchindelinFeb 14, 2009
  17. Felipe ContrerasFeb 15, 2009
  18. Johannes SchindelinFeb 15, 2009
  19. Felipe ContrerasFeb 15, 2009
  20. Johannes SchindelinFeb 15, 2009
  21. Felipe ContrerasFeb 15, 2009
  22. Felipe ContrerasFeb 15, 2009
  23. Junio C HamanoFeb 15, 2009
  24. Johannes SchindelinFeb 15, 2009
  25. Junio C HamanoFeb 15, 2009
  26. Johannes SchindelinFeb 15, 2009
  27. Felipe ContrerasFeb 17, 2009
  28. Junio C HamanoFeb 15, 2009
  29. Felipe ContrerasFeb 14, 2009
  30. Johannes SchindelinFeb 14, 2009
  31. Felipe ContrerasFeb 14, 2009
  32. Johannes SchindelinFeb 14, 2009
  33. Johannes SchindelinFeb 14, 2009
  34. Felipe ContrerasFeb 14, 2009
  35. Junio C HamanoFeb 14, 2009
  36. Felipe ContrerasFeb 14, 2009
  37. Junio C HamanoFeb 14, 2009
  38. Felipe ContrerasFeb 14, 2009
  39. Junio C HamanoFeb 14, 2009
  40. Felipe ContrerasFeb 14, 2009
  41. Johannes SchindelinFeb 14, 2009
  42. Junio C HamanoFeb 15, 2009
  43. Jakub NarebskiFeb 14, 2009
  44. Felipe ContrerasFeb 14, 2009
  45. Jeff KingFeb 14, 2009

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.