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

Re: [PATCH] attr: do not mark queried macros as unset

From
Jeff King <peff@peff.net>
Date
Jan 22, 2019, 07:19 UTC
Message-ID
<20190122071921.GC28555@sigill.intra.peff.net>
In-Reply-To
<CAGZ79kaPXQUY=FN3qusc2PNs=o1EiNarcBejOQKiozMSPvEOYw@mail.gmail.com>
On Fri, Jan 18, 2019 at 02:19:55PM -0800, Stefan Beller wrote:
Show 5 quoted lines
> > I dunno. This is why I submitted the initial patch as the simplest fix. ;)
> >
> 
> The first patch is
> Reviewed-by: Stefan Beller <sbeller@google.com>
Thanks!
Show 35 quoted lines
> Diffing across both patches, this seems to be the relevant part:
> [...]
> 
> ---8<---
> @@ -1111,14 +1116,13 @@ static void collect_some_attrs(const struct
> index_state *istate,
> 
>         prepare_attr_stack(istate, path, dirlen, &check->stack);
>         all_attrs_init(&g_attr_hashmap, check);
> -       determine_macros(check->all_attrs, check->stack);
> 
>         if (check->nr) {
>                 rem = 0;
>                 for (i = 0; i < check->nr; i++) {
>                         int n = check->items[i].attr->attr_nr;
>                         struct all_attrs_item *item = &check->all_attrs[n];
> -                       if (item->macro) {
> +                       if (!item->attr->in_stack) {
>                                 item->value = ATTR__UNSET;
>                                 rem++;
>                         }
> @@ -1127,6 +1131,8 @@ static void collect_some_attrs(const struct
> index_state *istate,
>                         return;
>         }
> 
> +       determine_macros(check->all_attrs, check->stack);
> +
>         rem = check->all_attrs_nr;
>         fill(path, pathlen, basename_offset, check->stack,
> check->all_attrs, rem);
>  }
> ---8<---
> 
> which I think is correct.

Yes, that's the interesting part. I think I've convinced myself, too, that it doesn't do the _wrong_ thing ever. But I think it misses the point of the original, which is that you want common ones like "diff" not to trigger in_stack if nobody has actually used them. And doing that really does mean marking in_stack not just when a macro mentions it (because clearly "binary" is going to mention it for every repo), but waiting to see if anybody mentions that macro.

Which means we must call determine_macros(), and then propagate the macro's in_stack to its expansion (if it's indeed called at all).

I don't think that would be _too_ hard to do. But I also wonder if there's much point. We are trying to avoid fill(), but I think that determine_macros() is of roughly the same complexity (look at all matches of all stacks). I guess it does avoid path_matches(), which is a bit more expensive. And in theory it could be cached for a particular stack top, so the work is amortized across many path lookups (though I think that gets even more tricky).

-Peff
Previous: Stefan BellerNext: Duy Nguyen
Message 8 of 15 in “Change on check-attr behavior”
  1. Sérgio PeixotoJan 17, 2019
  2. Jeff KingJan 17, 2019
  3. Sérgio PeixotoJan 18, 2019
  4. Jeff KingJan 18, 2019
  5. attr: do not mark queried macros as unsetJeff King, Jan 18, 2019
  6. Jeff KingJan 18, 2019
  7. Stefan BellerJan 18, 2019
  8. Jeff KingJan 22, 2019
  9. Duy NguyenJan 22, 2019
  10. Junio C HamanoJan 22, 2019
  11. Duy NguyenJan 21, 2019
  12. Jeff KingJan 22, 2019
  13. Duy NguyenJan 22, 2019
  14. Junio C HamanoJan 22, 2019
  15. Jeff KingJan 23, 2019

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.