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

Re: [PATCH 2/2] [GSOC][RFC] ref-filter: introduce enum atom_type

From
Junio C Hamano <gitster@pobox.com>
Date
May 9, 2021, 08:26 UTC
Message-ID
<xmqqh7jctiru.fsf@gitster.g>
In-Reply-To
<CAP8UFD0mOmqWUS49wywDVoWOyAkCRSUY5+i7Gqq-ZZSNCr-jvg@mail.gmail.com>
Christian Couder <christian.couder@gmail.com> writes:
Show 5 quoted lines
> I am not sure it's worth having an atom_type field for each valid_atom
> element if the value of that field is already the index of the
> element, because then one would always be able to replace
> `valid_atom[i].atom_type` with just `i`. Or is it for some kind of
> type safety issue?
Show 21 quoted lines
> I wonder if the enum should be instead defined like this:
>
> enum atom_type {
> ATOM_UNKNOWN = 0,
> ATOM_REFNAME,
> ...
> ATOM_ELSE,
> ATOM_INVALID, /* should be last */
> };
>
> As a struct containing an atom_type would typically be initialized
> with 0 after being allocated, `ATOM_UNKNOWN = 0` could ensure that we
> can easily distinguish such a struct where the atom_type is known from
> such a struct where it is unknown yet.
>
> Having ATOM_INVALID as always the last enum value (even if some new
> ones are added later) could help us iterate over the valid atoms using
> something like:
>
> for (i = ATOM_UNKNOWN + 1; i < ATOM_INVALID; i++)
>         /* do something with valid_atom[i] */;
OK.

As to "safety", I think it still makes sense to declare "enum", but I agree that we do not necessarily have to have it in the valid_atom[] struct. We could do something like this instead:

    static struct {
            const char *name;
            info_source source;
            cmp_type cmp_type;
            int (*parser)(const struct ref_format *format, struct used_atom *atom,
                          const char *arg, struct strbuf *err);
    } valid_atom[] = {
           [ATOM_REFNAME] = { "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser },
           [ATOM_OBJECTTYPE] = { "objecttype", SOURCE_OTHER, FIELD_STR, objecttype...
           [ATOM_OBJECTSIZE] = { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsi...
           ...
Previous: Christian CouderNext: ZheNing Hu
Message 5 of 27 in “[GSOC][RFC] ref-filter: introduce enum atom_type”
  1. 0/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 8, 2021
  2. 1/2 [GSOC] ref-filter: add objectsize to used_atomZheNing Hu via GitGitGadget, May 8, 2021
  3. 2/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 8, 2021
  4. Christian CouderMay 9, 2021
  5. Junio C HamanoMay 9, 2021
  6. ZheNing HuMay 9, 2021
  7. ZheNing HuMay 9, 2021
  8. 0/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 10, 2021
  9. 1/2 [GSOC] ref-filter: add objectsize to used_atomZheNing Hu via GitGitGadget, May 10, 2021
  10. 2/2 [GSOC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 10, 2021
  11. Junio C HamanoMay 11, 2021
  12. Christian CouderMay 11, 2021
  13. Junio C HamanoMay 11, 2021
  14. ZheNing HuMay 11, 2021
  15. ZheNing HuMay 11, 2021
  16. Junio C HamanoMay 11, 2021
  17. ZheNing HuMay 11, 2021
  18. 0/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 12, 2021
  19. 1/2 [GSOC] ref-filter: add objectsize to used_atomZheNing Hu via GitGitGadget, May 12, 2021
  20. Junio C HamanoMay 12, 2021
  21. ZheNing HuMay 13, 2021
  22. 2/2 [GSOC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 12, 2021
  23. Junio C HamanoMay 12, 2021
  24. ZheNing HuMay 13, 2021
  25. 0/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 13, 2021
  26. 1/2 [GSOC] ref-filter: add objectsize to used_atomZheNing Hu via GitGitGadget, May 13, 2021
  27. 2/2 [GSOC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 13, 2021

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.