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

Re: [PATCH v16 05/14] ref-filter: introduce match_atom_name()

From
Karthik Nayak <karthik.188@gmail.com>
Date
Sep 7, 2015, 18:07 UTC
Message-ID
<CAOLa=ZSscCk77f4viVPUhXRhpFXF=fa8c=G9mF0RovRqKqeLmg@mail.gmail.com>
In-Reply-To
<CAPig+cSN1s6qAj7p_+qG9W52X2L-7eBR+-j+918vfycADvUyWw@mail.gmail.com>
On Mon, Sep 7, 2015 at 1:22 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 34 quoted lines
> On Sat, Sep 5, 2015 at 2:52 PM, Karthik Nayak <karthik.188@gmail.com> wrote:
>> Introduce match_atom_name() which helps in checking if a particular
>> atom is the atom we're looking for and if it has a value attached to
>> it or not.
>>
>> Use it instead of starts_with() for checking the value of %(color:...)
>> atom. Write a test for the same.
>>
>> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
>> ---
>> diff --git a/ref-filter.c b/ref-filter.c
>> index a993216..e99c342 100644
>> --- a/ref-filter.c
>> +++ b/ref-filter.c
>> +static int match_atom_name(const char *name, const char *atom_name, const char **val)
>> +{
>> +       const char *body;
>> +
>> +       if (!skip_prefix(name, atom_name, &body))
>> +               return 0; /* doesn't even begin with "atom_name" */
>> +       if (!body[0] || !body[1]) {
>> +               *val = NULL; /* %(atom_name) and no customization */
>> +               return 1;
>
> If this is invoked as match_atom_name("colors", "color", ...), then it
> will return true (matched, but no value), which is not correct at all;
> "colors" is not a match for atom %(color). Maybe you meant?
>
>     if (!body[0] || (body[0] == ':' && !body[1])) {
>
> But, that's getting ugly and complicated, and would be bettered
> handled by reordering the logic of this function for dealing with the
> various valid and invalid cases. However...
>

Well as you infered the logic is to check so that there is something existing after the ':'. About why I didn't do something like this "(body[0] == ':' && !body[1])" is because ref-filter already checks for invalid atom names.

So before even match_atom_name() is called, the check is done in parse_ref_filter_atom().

Show 23 quoted lines
>> +       }
>> +       if (body[0] != ':')
>> +               return 0; /* "atom_namefoo" is not "atom_name" or "atom_name:..." */
>> +       *val = body + 1; /* "atomname:val" */
>> +       return 1;
>> +}
>
> It's not clear why this function exists in the first place. It's only
> purpose seems to be to specially recognize instances of atoms which
> should have a ":" but lack it, so that the caller can then report an
> error.
>
> But why is this better than the more generic solution of merely
> reporting an error for *any* unrecognized atom? How does it help to
> single out these special cases?
>
> There is a further inconsistency in that you are only specially
> recognizing %(color) and %(align) lacking ":", but not
> %(content:lines) lacking "=" in patch 8/14. Why do %(color:...) and
> %(align:...) get special treatment but %(content:lines=...) does not?
> Such inconsistency again argues in favor of a generic "unrecognized
> atom" detection and reporting over special case handling.
>

This is from http://article.gmane.org/gmane.comp.version-control.git/277099 Junio suggested to have this to check for ":" rather than rely on skip_prefix() and check manually after that.

Agreed, a more generic solution would be better, and If I remember I said, I'll work on that after this entire series.

About contents:lines, we declare contents:lines itself as an atom, this was to keep it similar to how the other contents atoms are declared, so the testing for this again is already done by parse_ref_filter_atom().

-- 
Regards,
Karthik Nayak
Previous: Eric SunshineNext: Karthik Nayak
Message 8 of 30 in “port tag.c to use ref-filter APIs”
  1. 00/14 port tag.c to use ref-filter APIsKarthik Nayak, Sep 5, 2015
  2. 01/14 ref-filter: move `struct atom_value` to ref-filter.cKarthik Nayak, Sep 5, 2015
  3. 02/14 ref-filter: introduce ref_formatting_state and ref_formatting_stackKarthik Nayak, Sep 5, 2015
  4. 03/14 utf8: add function to align a string into given strbufKarthik Nayak, Sep 5, 2015
  5. 04/14 ref-filter: introduce handler function for each atomKarthik Nayak, Sep 5, 2015
  6. 05/14 ref-filter: introduce match_atom_name()Karthik Nayak, Sep 5, 2015
  7. Eric SunshineSep 6, 2015
  8. Karthik NayakSep 7, 2015
  9. 06/14 ref-filter: implement an `align` atomKarthik Nayak, Sep 5, 2015
  10. Eric SunshineSep 6, 2015
  11. Karthik NayakSep 7, 2015
  12. 07/14 ref-filter: add option to filter out tags, branches and remotesKarthik Nayak, Sep 5, 2015
  13. 08/14 ref-filter: add support for %(contents:lines=X)Karthik Nayak, Sep 5, 2015
  14. 09/14 ref-filter: add support to sort by versionKarthik Nayak, Sep 5, 2015
  15. 10/14 ref-filter: add option to match literal patternKarthik Nayak, Sep 5, 2015
  16. 11/14 tag.c: use 'ref-filter' data structuresKarthik Nayak, Sep 5, 2015
  17. 12/14 tag.c: use 'ref-filter' APIsKarthik Nayak, Sep 5, 2015
  18. 13/14 tag.c: implement '--format' optionKarthik Nayak, Sep 5, 2015
  19. 14/14 tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak, Sep 5, 2015
  20. Matthieu MoySep 6, 2015
  21. Karthik NayakSep 6, 2015
  22. Junio C HamanoSep 7, 2015
  23. Matthieu MoySep 7, 2015
  24. Karthik NayakSep 7, 2015
  25. Matthieu MoySep 7, 2015
  26. Karthik NayakSep 8, 2015
  27. Junio C HamanoSep 8, 2015
  28. Karthik NayakSep 9, 2015
  29. Junio C HamanoSep 9, 2015
  30. Junio C HamanoSep 8, 2015

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.