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

Re: [PATCH v2 3/8] config: Use parseopt.

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Feb 17, 2009, 13:55 UTC
Message-ID
<94a0d4530902170555l4e3f769wa24513b0ffbdd6a0@mail.gmail.com>
In-Reply-To
<7vbpt1by1y.fsf@gitster.siamese.dyndns.org>
On Tue, Feb 17, 2009 at 4:24 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> +     if (HAS_MULTI_BITS(actions)) {
>> +             error("only one action at a time.");
>> +             usage_with_options(builtin_config_usage, builtin_config_options);
>
> My initial reaction was:
>
>        Can we easily say "--get and --getall are mutually incompatible"?
>
> and knowing that it would take much more code, the second reaction was:
>
>        Does the user know what we mean by "action"?
>
> Since the answer to this is "Yes, the usage message comes from parseopt
> and there is a clear categorization", I think the message is good enough.
>
> What happens when the user says "config --get --get-colorbool user.name"?
> Is it an error?  Is it diagnosed as an error?
>
> It probably is easy to fix it by defining two bits of fake actions and do:
>
>        if (get_color_slot)
>                actions |= ACTION_GET_COLOR;
>        if (get_colorbool_slot)
>                actions |= ACTION_GET_COLORBOOL;
>
> immediately before this HAS_MULTI_BITS check.
>
> I know I suggested these to are type-like, but I realize that these two
> are better categorized as actions tied to a specific type (color), as you
> had in your earlier round.
All right, done.
Show 15 quoted lines
>> +     if (actions == 0)
>> +             switch (argc) {
>> +             case 1: actions |= ACTION_GET; break;
>> +             case 2: actions |= ACTION_ADD; break;
>> +             case 3: actions |= ACTION_REPLACE_ALL; break;
>
> Straight assignment, not ORing-in please.  It wastes a few seconds from
> the reader wondering what other bits in the variable "actions" are used
> for things other than ACTION_* (the answer is none).
>
> Similarly, later conditions:
>
>> +     if (actions & ACTION_LIST) {
>
> would read better if they used equality == checks.

Cool, I was worried those where not logical to the reader but I couldn't think of a better solution... this one looks much better!

I've also made the same change for the 'types' variable in a later patch.
-- 
Felipe Contreras
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 24 in “config: Trivial rename in preparation for parseopt.”
  1. 1/8 config: Trivial rename in preparation for parseopt.Felipe Contreras, Feb 17, 2009
  2. 2/8 config: Reorganize get_color*.Felipe Contreras, Feb 17, 2009
  3. 3/8 config: Use parseopt.Felipe Contreras, Feb 17, 2009
  4. 4/8 config: Disallow multiple variable types.Felipe Contreras, Feb 17, 2009
  5. 5/8 config: Disallow multiple config file locations.Felipe Contreras, Feb 17, 2009
  6. 6/8 config: Don't allow extra arguments for -e or -l.Felipe Contreras, Feb 17, 2009
  7. 7/8 config: Codestyle cleanups.Felipe Contreras, Feb 17, 2009
  8. 8/8 config: Cleanup editor action.Felipe Contreras, Feb 17, 2009
  9. Junio C HamanoFeb 17, 2009
  10. Junio C HamanoFeb 17, 2009
  11. Junio C HamanoFeb 17, 2009
  12. Felipe ContrerasFeb 17, 2009
  13. Junio C HamanoFeb 17, 2009
  14. Felipe ContrerasFeb 17, 2009
  15. Johannes SchindelinFeb 17, 2009
  16. Felipe ContrerasFeb 17, 2009
  17. Felipe ContrerasFeb 17, 2009
  18. Junio C HamanoFeb 17, 2009
  19. Junio C HamanoFeb 17, 2009
  20. Felipe ContrerasFeb 17, 2009
  21. Johannes SchindelinFeb 17, 2009
  22. Felipe ContrerasFeb 17, 2009
  23. Gerrit PapeFeb 17, 2009
  24. Johannes SchindelinFeb 17, 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.