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

Re: [PATCH v2 09/12] attr: (re)introduce git_check_attr() and struct git_attr_check

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 17, 2016, 04:19 UTC
Message-ID
<CAPig+cR5ksdATefkYkG7-+a_nK0w+Fdu8ae-Z4=PTp8yAYhiQQ@mail.gmail.com>
In-Reply-To
<20160516210545.6591-10-gitster@pobox.com>
On Mon, May 16, 2016 at 5:05 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 37 quoted lines
> A common pattern to check N attributes for many paths is to
>
>  (1) prepare an array A of N git_attr_check_elem items;
>  (2) call git_attr() to intern the N attribute names and fill A;
>  (3) repeatedly call git_check_attrs() for path with N and A;
> [...snip...]
> Introduce "struct git_attr_check" that contains N, the number of
> attributes being sought, and A, the array that holds N
> git_attr_check_elem items, and a function git_check_attr() that
> takes a path P and this structure as its parameters.  This structure
> can later be extended to hold extra data necessary for optimization.
>
> Also, to make it easier to write the first two steps in common
> cases, introduce git_attr_check_initl() helper function, which takes
> a NULL-terminated list of attribute names and initialize this
> structure.
> [...snip...]
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> diff --git a/attr.c b/attr.c
> @@ -825,3 +825,37 @@ void git_attr_set_direction(enum git_attr_direction new, struct index_state *ist
> +struct git_attr_check *git_attr_check_initl(const char *one, ...)
> +{
> +       [...]
> +       check = xcalloc(1,
> +                       sizeof(*check) + cnt * sizeof(*(check->check)));
> +       check->check_nr = cnt;
> +       check->check = (struct git_attr_check_elem *)(check + 1);
> +       [...]
> +       return check;
> +}
> diff --git a/attr.h b/attr.h
> @@ -29,6 +29,15 @@ struct git_attr_check_elem {
> +struct git_attr_check {
> +       int check_nr;
> +       int check_alloc;

This field is unused, and git_attr_check_initl() neglects to initialize it (if it is intended to be used in the future).

> +       struct git_attr_check_elem *check;
> +};
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 27 in “revamping git_check_attr() API”
  1. 00/12 revamping git_check_attr() APIJunio C Hamano, May 16, 2016
  2. 01/12 commit.c: use strchrnul() to scan for one lineJunio C Hamano, May 16, 2016
  3. Stefan BellerMay 16, 2016
  4. Junio C HamanoMay 16, 2016
  5. Stefan BellerMay 16, 2016
  6. 02/12 attr.c: use strchrnul() to scan for one lineJunio C Hamano, May 16, 2016
  7. Stefan BellerMay 16, 2016
  8. Junio C HamanoMay 16, 2016
  9. 03/12 attr.c: update a stale comment on "struct match_attr"Junio C Hamano, May 16, 2016
  10. Stefan BellerMay 16, 2016
  11. Junio C HamanoMay 16, 2016
  12. 04/12 attr.c: explain the lack of attr-name syntax check in parse_attr()Junio C Hamano, May 16, 2016
  13. 05/12 attr.c: complete a sentence in a commentJunio C Hamano, May 16, 2016
  14. 06/12 attr.c: mark where #if DEBUG ends more clearlyJunio C Hamano, May 16, 2016
  15. 07/12 attr.c: simplify macroexpand_one()Junio C Hamano, May 16, 2016
  16. 08/12 attr: rename function and struct related to checking attributesJunio C Hamano, May 16, 2016
  17. 09/12 attr: (re)introduce git_check_attr() and struct git_attr_checkJunio C Hamano, May 16, 2016
  18. Eric SunshineMay 17, 2016
  19. Junio C HamanoMay 17, 2016
  20. 10/12 attr: convert git_all_attrs() to use "struct git_attr_check"Junio C Hamano, May 16, 2016
  21. Junio C HamanoMay 17, 2016
  22. Junio C HamanoMay 17, 2016
  23. Stefan BellerMay 18, 2016
  24. 11/12 attr: convert git_check_attrs() callers to use the new APIJunio C Hamano, May 16, 2016
  25. 12/12 attr: retire git_check_attrs() APIJunio C Hamano, May 16, 2016
  26. Stefan BellerMay 18, 2016
  27. Junio C HamanoMay 18, 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.