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
ZheNing Hu <adlternative@gmail.com>
Date
May 9, 2021, 13:40 UTC
Message-ID
<CAOLTT8TGa2U=O6jAOcmqVwiKv6RiSt5j7FuA_XTO=JVi73ts2w@mail.gmail.com>
In-Reply-To
<CAP8UFD0mOmqWUS49wywDVoWOyAkCRSUY5+i7Gqq-ZZSNCr-jvg@mail.gmail.com>
Christian Couder <christian.couder@gmail.com> 于2021年5月9日周日 下午2:21写道:
Show 11 quoted lines
>
> > At the same time, The value of an atom_type is the coordinate
> > of its corresponding valid_atom entry, we can quickly index
> > to the corresponding valid_atom entry by the atom_type value.
>
> 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?
>

Well, I think the security issue here is just to allow used_atom and valid_atom to be correctly mapped through atom_type. We don’t want the coder to forget to update "enum atom_type" when adding new atoms to valid_atom in the future. So maybe Junio's suggestion is reasonable, we delete the member atom_type in valid_atom, but maintain the connection between atom_type and valid_atom items by specifying atom_type as array coordinates.

Show 22 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] */;
>
Thanks, this suggestion is good!
Show 26 quoted lines
> > +
> >  /*
> >   * An atom is a valid field atom listed below, possibly prefixed with
> >   * a "*" to denote deref_tag().
> > @@ -122,6 +166,7 @@ static struct used_atom {
> >         const char *name;
> >         cmp_type type;
> >         info_source source;
> > +       enum atom_type atom_type;
> >         union {
> >                 char color[COLOR_MAXLEN];
> >                 struct align align;
> > @@ -500,53 +545,54 @@ static int head_atom_parser(const struct ref_format *format, struct used_atom *a
> >  }
> >
> >  static struct {
> > +       enum atom_type atom_type;
> >         const char *name;
> >         info_source source;
> >         cmp_type cmp_type;
>
> I can see that the fields are already not in the same order as in
> struct used_atom, but my opinion is that it would be better if they
> would we as much as possible in the same order. Maybe one day we could
> even unify these structs in some way.
>

Yes, atom_value, valid_atom, used_atom, It may be difficult to read for the first time. Maybe unifying them is a good direction for the future.

> Also as discussed above we might not even need to add an atom_type to
> valid_atom[].
>
OK.
Show 16 quoted lines
> >         int (*parser)(const struct ref_format *format, struct used_atom *atom,
> >                       const char *arg, struct strbuf *err);
> >  } valid_atom[] = {
>
> > @@ -628,6 +674,7 @@ static int parse_ref_filter_atom(const struct ref_format *format,
> >         at = used_atom_cnt;
> >         used_atom_cnt++;
> >         REALLOC_ARRAY(used_atom, used_atom_cnt);
> > +       used_atom[at].atom_type = valid_atom[i].atom_type;
>
> As discussed above, if the value of an atom_type is the coordinate of
> its corresponding valid_atom entry, then here the following would be
> simpler:
>
>        used_atom[at].atom_type = i;
>
I agree.
Show 17 quoted lines
> >         used_atom[at].name = xmemdupz(atom, ep - atom);
> >         used_atom[at].type = valid_atom[i].cmp_type;
> >         used_atom[at].source = valid_atom[i].source;
> > @@ -652,7 +699,7 @@ static int parse_ref_filter_atom(const struct ref_format *format,
> >                 return -1;
> >         if (*atom == '*')
> >                 need_tagged = 1;
> > -       if (!strcmp(valid_atom[i].name, "symref"))
> > +       if (valid_atom[i].atom_type == ATOM_SYMREF)
>
> In the same way as above, the above line might be replaced with the simpler:
>
>        if (i == ATOM_SYMREF)
>
> >                 need_symref = 1;
> >         return at;
> >  }

Thanks! -- ZheNing Hu

Previous: ZheNing HuNext: ZheNing Hu via GitGitGadget
Message 7 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.