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

Re: [PATCH 5/5] treewide: always have a valid "index_state.repo" member

From
Derrick Stolee <derrickstolee@github.com>
Date
Jan 10, 2023, 15:08 UTC
Message-ID
<6b92fad2-6b74-fddb-679c-8c8735e7103d@github.com>
In-Reply-To
<patch-5.5-b3b0e592101-20230110T060340Z-avarab@gmail.com>
On 1/10/2023 1:17 AM, Ævar Arnfjörð Bjarmason wrote:
Show 7 quoted lines
> When the "repo" member was added to "the_index" in [1] the
> repo_read_index() was made to populate it, but the unpopulated
> "the_index" variable didn't get the same treatment.
> 
> Let's do that in initialize_the_repository() when we set it up, and
> likewise for all of the current callers initialized an empty "struct
> index_state".
> +	struct index_state result = { .repo = state->repo };
> +	struct index_state wtindex = { .repo = the_repository };
> +	o.result.repo = r;
> +	struct index_state istate = { .repo = the_repository };

I think these initialization updates (along with the others I didn't include) are satisfactory for now. What worries me is that future consumers that create an index_state will need to remember to manually initialize like this or risk hitting the BUG() statements in read-cache.c.

The only alternative I can think about is to create an initialization method, say "init_index_state(struct index_state *, struct repository *)", that should be called before doing anything with an index_state. This includes running a memset() to clear the struct, making these inline initializers unnecessary.

However, I can't decide if that's actually an improvement. I think things tip in favor of the init_index_state() method if there ever becomes another member of struct index_state that _needs_ to be set before the struct is "valid". I doubt that we would add such a thing in the near future, so I recommend sticking with this patch as-is.

Thanks, -Stolee

Previous: Jeff HostetlerNext: Derrick Stolee
Message 12 of 32 in “cache API: always have a "istate->repo"”
  1. 0/5 cache API: always have a "istate->repo"Ævar Arnfjörð Bjarmason, Jan 10, 2023
  2. 1/5 builtin/difftool.c: { 0 }-initialize rather than using memset()Ævar Arnfjörð Bjarmason, Jan 10, 2023
  3. 2/5 sparse-index.c: expand_to_path() can assume non-NULL "istate"Ævar Arnfjörð Bjarmason, Jan 10, 2023
  4. 3/5 sparse-index API: fix TODO, BUG() out on NULL ensure_full_index()Ævar Arnfjörð Bjarmason, Jan 10, 2023
  5. Philip OakleyJan 10, 2023
  6. Ævar Arnfjörð BjarmasonJan 10, 2023
  7. Derrick StoleeJan 10, 2023
  8. 4/5 read-cache.c: refactor set_new_index_sparsity() for subsequent commitÆvar Arnfjörð Bjarmason, Jan 10, 2023
  9. 5/5 treewide: always have a valid "index_state.repo" memberÆvar Arnfjörð Bjarmason, Jan 10, 2023
  10. Ævar Arnfjörð BjarmasonJan 10, 2023
  11. Jeff HostetlerJan 10, 2023
  12. Derrick StoleeJan 10, 2023
  13. Derrick StoleeJan 10, 2023
  14. 0/6 cache API: always have a "istate->repo"Ævar Arnfjörð Bjarmason, Jan 12, 2023
  15. 1/6 builtin/difftool.c: { 0 }-initialize rather than using memset()Ævar Arnfjörð Bjarmason, Jan 12, 2023
  16. 2/6 sparse-index.c: expand_to_path() can assume non-NULL "istate"Ævar Arnfjörð Bjarmason, Jan 12, 2023
  17. 3/6 sparse-index API: BUG() out on NULL ensure_full_index()Ævar Arnfjörð Bjarmason, Jan 12, 2023
  18. 4/6 read-cache.c: refactor set_new_index_sparsity() for subsequent commitÆvar Arnfjörð Bjarmason, Jan 12, 2023
  19. 5/6 cache API: add a "INDEX_STATE_INIT" macro/function, add release_index()Ævar Arnfjörð Bjarmason, Jan 12, 2023
  20. Derrick StoleeJan 12, 2023
  21. Ævar Arnfjörð BjarmasonJan 12, 2023
  22. Derrick StoleeJan 12, 2023
  23. 6/6 treewide: always have a valid "index_state.repo" memberÆvar Arnfjörð Bjarmason, Jan 12, 2023
  24. Derrick StoleeJan 12, 2023
  25. Derrick StoleeJan 12, 2023
  26. Junio C HamanoJan 13, 2023
  27. Junio C HamanoJan 13, 2023
  28. Ævar Arnfjörð BjarmasonJan 16, 2023
  29. Philip OakleyJan 16, 2023
  30. Junio C HamanoJan 16, 2023
  31. treewide: always have a valid "index_state.repo" memberÆvar Arnfjörð Bjarmason, Jan 17, 2023
  32. Derrick StoleeJan 17, 2023

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.