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

Re: [RFC-PATCHv6 4/4] pathspec: allow querying for attributes

From
Stefan Beller <sbeller@google.com>
Date
May 17, 2016, 16:45 UTC
Message-ID
<CAGZ79kZSZQwnatExNFKCiWz8zgJfnS+8VWLkZcMaiHS1ESqBaQ@mail.gmail.com>
In-Reply-To
<xmqqa8jpz51m.fsf@gitster.mtv.corp.google.com>
On Mon, May 16, 2016 at 9:23 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 10 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> + * attr:+val to find value set to true
>> + * attr:-val to find a value set to false
>> + * attr:!val to find a value that is not set
>> + *     (i.e. it is neither set as "val", "val=<empty>", nor unset as "-val")
>> + * attr:val=value: to find value that have at least a and b set.
>
> I would have expected that there won't be "attr:+val", but it is
> spelled as "attr:val" instead.

"val" matches if the attr is not unspecified, i.e. one of {true, false, value} "+val" matches {true} only.

Maybe we want to redo that to

"val" matches {true} only. "?val" matches {true, false, value}. (I can leave this case out in the first series, too)

Show 6 quoted lines
>
>> +static void parse_attr_item(struct attr_item *attr, const char *value)
>
> Please do not call something that is not part of the attribute
> infrastructure as "attr_item"; I wasted time looking for the
> structure definition for "attr_item" in <attr.h>.
So "parse_pathspec_attr_match" instead?
Show 20 quoted lines
>
>> +static int match_attrs(const char *name, int namelen,
>> +                    const struct pathspec_item *item)
>> +{
>> +     char *path;
>> +     int i;
>> +
>> +     if (!check) {
>> +             check = git_attr_check_alloc();
>> +             for (i = 0; i < item->attr_nr; i++)
>> +                     git_attr_check_append(check, item->attrs[i].attr);
>> +     }
>> +
>> +     path = xmemdupz(name, namelen);
>> +     git_all_attrs(path, check);
>
> PLEASE DON'T.  git_all_attrs() asks for all the attribute under the
> sun and has no hope to perform sensibly, especially at the very leaf
> level of the pathspec logic where one call to this function is made
> for each and every path in the tree.

This is executed only once, as check is static? From a users perception it doesn't matter if it is executed once just after parsing all pathspec items or at the first path to check for a match, no?

The mistake is using the API wrong. So inside the '!check', after the preparation loop of git_attr_check_append, we'd need to hand over the "check" to git_check_attr instead?

>
> Instead, have a pointer to "struct git_attr_check" in pathspec_item
> and make a call to git_check_attr(path, item->check) here.
I see, then we have multiple `check` structs. Makes sense.
Show 9 quoted lines
>
> Which means that you would need to prepare git_attr_check around ...
>
>> +             if (skip_prefix(copyfrom, "attr:", &body)) {
>> +                     ALLOC_GROW(item->attrs, item->attr_nr + 1, item->attr_alloc);
>> +                     parse_attr_item(&item->attrs[item->attr_nr++], body);
>
> ... HERE.
>
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 18 in “[RFC-PATCHv6 0/4] pathspec attrs [WAS pathspec labels [WAS submodule groups]]”
  1. Stefan BellerMay 17, 2016
  2. 1/4 Documentation: fix a typoStefan Beller, May 17, 2016
  3. 2/4 pathspec: move long magic parsing out of prefix_pathspecStefan Beller, May 17, 2016
  4. 3/4 pathspec: move prefix check out of the inner loopStefan Beller, May 17, 2016
  5. 4/4 pathspec: allow querying for attributesStefan Beller, May 17, 2016
  6. Junio C HamanoMay 17, 2016
  7. Stefan BellerMay 17, 2016
  8. Junio C HamanoMay 17, 2016
  9. Stefan BellerMay 17, 2016
  10. Junio C HamanoMay 17, 2016
  11. Stefan BellerMay 17, 2016
  12. Junio C HamanoMay 17, 2016
  13. Stefan BellerMay 17, 2016
  14. Junio C HamanoMay 17, 2016
  15. Stefan BellerMay 17, 2016
  16. Junio C HamanoMay 17, 2016
  17. Junio C HamanoMay 18, 2016
  18. Junio C HamanoMay 17, 2016

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.