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

Re: [PATCH 2/2] [GSOC] ref-filter: add %(raw) atom

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 3, 2021, 21:35 UTC
Message-ID
<xmqq35ty6391.fsf@gitster.g>
In-Reply-To
<CAOLTT8TiyAtJfcrPoBF6SECfaKOTKt24NSOtTmf84JwHrU8g1A@mail.gmail.com>
ZheNing Hu <adlternative@gmail.com> writes:
Show 16 quoted lines
>>  * We do have enumerated constants for each atom types, but this
>>    early check and return does string comparison.
>>
>
> Note that at this time we must compare strings... parse_ref_filter_atom()
> passes string form of the atom. Code block A also requires comparing strings.
>
> -------------------
> Code block A:
>
>         for (i = 0; i < used_atom_cnt; i++) {
>                int len = strlen(used_atom[i].name);
>                if (len == ep - atom && !memcmp(used_atom[i].name, atom, len))
>                        return i;
>        }
> -------------------

The point is that you can piggyback existing string comparison (which is called "parsing") and use the parsed result (i.e. if you can compare with ATOM_RAW instead of adding another strcmp(), that can be a better solution).

Show 10 quoted lines
> All the following replies are based on such a fact:
> We will reuse used atoms as much as possible.
>
> Think about this situation:
>
> $ git for-each-ref --format="%(raw)" --sort="raw" --python
>
> Since we specified --sort="raw",`parse_sorting_atom()`
> will be called in parse_opt_ref_sorting(), but at this time
> we haven't parsed --<lang> yet.

That only says using parse_sorting_atom() and relying on the check in the function is still too early, and does not necessarily support the posted patch that redundantly runs strcmp().

After parsing all the command line options, we have used_atom[] fully populated and we know what host language we are quoting the result for---and that makes a good place to check for comflicting requests.

Show 22 quoted lines
>> +static int raw_atom_parser(const struct ref_format *format, struct used_atom *atom,
>> +                               const char *arg, struct strbuf *err)
>> +{
>> +       if (!arg)
>> +               atom->u.raw_data.option = RAW_BARE;
>> +       else if (!strcmp(arg, "size"))
>> +               atom->u.raw_data.option = RAW_LENGTH;
>> +       else
>> +               return strbuf_addf_ret(err, -1, _("unrecognized %%(raw) argument: %s"), arg);
>> +
>> +       if (atom->u.raw_data.option == RAW_BARE && format->quote_style)
>> +               return strbuf_addf_ret(err, -1,
>> +                                      _("--format=%%(raw) cannot be used with ...")...);
>> +
>> +       return 0;
>> +}
>
> It's same, "*.parser()" is below Code Block A.
>
> After all, the reason why this must be done here is the ref-filter
> original logic
> has not considered rejecting a format atom and an option.
That is something you can fix to make the code easier to follow, no?
Previous: Junio C HamanoNext: ZheNing Hu
Message 10 of 23 in “[GSOC] ref-filter: add %(raw) atom”
  1. 0/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 1, 2021
  2. 1/2 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 1, 2021
  3. Junio C HamanoJun 3, 2021
  4. ZheNing HuJun 3, 2021
  5. 2/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 1, 2021
  6. Junio C HamanoJun 3, 2021
  7. ZheNing HuJun 3, 2021
  8. ZheNing HuJun 3, 2021
  9. Junio C HamanoJun 3, 2021
  10. Junio C HamanoJun 3, 2021
  11. ZheNing HuJun 4, 2021
  12. Bagas SanjayaJun 3, 2021
  13. ZheNing HuJun 3, 2021
  14. 0/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 4, 2021
  15. 1/2 [GSOC] ref-filter: add obj-type check in grab contentsZheNing Hu via GitGitGadget, Jun 4, 2021
  16. 2/2 [GSOC] ref-filter: add %(raw) atomZheNing Hu via GitGitGadget, Jun 4, 2021
  17. Christian CouderJun 4, 2021
  18. Christian CouderJun 4, 2021
  19. ZheNing HuJun 5, 2021
  20. Christian CouderJun 5, 2021
  21. ZheNing HuJun 5, 2021
  22. Christian CouderJun 5, 2021
  23. ZheNing HuJun 5, 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.