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

Re: [PATCH v4 4/4] sparse-index: update do_read_index to ensure correct sparsity

From
Elijah Newren <newren@gmail.com>
Date
Nov 22, 2021, 17:36 UTC
Message-ID
<CABPp-BGU=HHeydt3arF=RF2P81cFbe3NfX6tqiBHb8xkhOALgg@mail.gmail.com>
In-Reply-To
<b67cd9d07f8a3802e5b50d58965f283620cd3876.1635515487.git.gitgitgadget@gmail.com>

On Fri, Oct 29, 2021 at 6:56 AM Victoria Dye via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 6 quoted lines
>
> From: Victoria Dye <vdye@github.com>
>
> If `command_requires_full_index` is false, ensure correct in-core index
> sparsity on read by calling `ensure_correct_sparsity`. This change is meant
> to update the how the index is read in a command after sparse index-related
s/update the how/update how/ ?
Show 8 quoted lines
> repository settings are modified. Previously, for example, if `index.sparse`
> were changed from `true` to `false`, the in-core index on the next command
> would be sparse. The index would only be expanded to full when it was next
> written to disk.
>
> By adding a call to `ensure_correct_sparsity`, the in-core index now matches
> the sparsity dictated by the relevant repository settings as soon as it is
> read into memory, rather than when it is later written to disk.

I split up reading this series across different days, and when I got here, my first reaction was "Okay, but why would you want that? Sounds like extra work for no gain." I went and looked up the cover letter and saw you mentioned that this "introduces the ability to enable/disable the sparse index on a command-by-command basis (e.g., allowing a user to troubleshoot a sparse-aware command with '-c index.sparse=false' [1]). That seems like a good reason to me, and sounds like it belongs in this commit message. But it sounds like you had other reasons in mind. If so, could you share them; I'm having difficulty understanding how this would make a difference other than in the troubleshooting scenario.

Show 75 quoted lines
>
> Helped-by: Junio C Hamano <gitster@pobox.com>
> Co-authored-by: Derrick Stolee <dstolee@microsoft.com>
> Signed-off-by: Victoria Dye <vdye@github.com>
> ---
>  read-cache.c                             |  8 ++++++
>  t/t1092-sparse-checkout-compatibility.sh | 31 ++++++++++++++++++++++++
>  2 files changed, 39 insertions(+)
>
> diff --git a/read-cache.c b/read-cache.c
> index a78b88a41bf..b3772ba70a1 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2337,9 +2337,17 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
>
>         if (!istate->repo)
>                 istate->repo = the_repository;
> +
> +       /*
> +        * If the command explicitly requires a full index, force it
> +        * to be full. Otherwise, correct the sparsity based on repository
> +        * settings and other properties of the index (if necessary).
> +        */
>         prepare_repo_settings(istate->repo);
>         if (istate->repo->settings.command_requires_full_index)
>                 ensure_full_index(istate);
> +       else
> +               ensure_correct_sparsity(istate);
>
>         return istate->cache_nr;
>
> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
> index ca91c6a67f8..59accde1fa3 100755
> --- a/t/t1092-sparse-checkout-compatibility.sh
> +++ b/t/t1092-sparse-checkout-compatibility.sh
> @@ -694,6 +694,37 @@ test_expect_success 'sparse-index is expanded and converted back' '
>         test_region index ensure_full_index trace2.txt
>  '
>
> +test_expect_success 'index.sparse disabled inline uses full index' '
> +       init_repos &&
> +
> +       # When index.sparse is disabled inline with `git status`, the
> +       # index is expanded at the beginning of the execution then never
> +       # converted back to sparse. It is then written to disk as a full index.
> +       rm -f trace2.txt &&
> +       GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
> +               git -C sparse-index -c index.sparse=false status &&
> +       ! test_region index convert_to_sparse trace2.txt &&
> +       test_region index ensure_full_index trace2.txt &&
> +
> +       # Since index.sparse is set to true at a repo level, the index
> +       # is converted from full to sparse when read, then never expanded
> +       # over the course of `git status`. It is written to disk as a sparse
> +       # index.
> +       rm -f trace2.txt &&
> +       GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
> +               git -C sparse-index status &&
> +       test_region index convert_to_sparse trace2.txt &&
> +       ! test_region index ensure_full_index trace2.txt &&
> +
> +       # Now that the index has been written to disk as sparse, it is not
> +       # converted to sparse (or expanded to full) when read by `git status`.
> +       rm -f trace2.txt &&
> +       GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
> +               git -C sparse-index status &&
> +       ! test_region index convert_to_sparse trace2.txt &&
> +       ! test_region index ensure_full_index trace2.txt
> +'
> +
>  ensure_not_expanded () {
>         rm -f trace2.txt &&
>         echo >>sparse-index/untracked.txt &&
> --
> gitgitgadget
The rest of the patch looks fine.
Previous: Victoria Dye via GitGitGadgetNext: Victoria Dye
Message 35 of 44 in “sparse-index: expand/collapse based on 'index.sparse'”
  1. 0/2 sparse-index: expand/collapse based on 'index.sparse'Victoria Dye via GitGitGadget, Oct 15, 2021
  2. 1/2 test-read-cache.c: prepare_repo_settings after config initVictoria Dye via GitGitGadget, Oct 15, 2021
  3. 2/2 sparse-index: update index read to consider index.sparse configVictoria Dye via GitGitGadget, Oct 15, 2021
  4. Junio C HamanoOct 15, 2021
  5. Derrick StoleeOct 17, 2021
  6. Junio C HamanoOct 17, 2021
  7. Derrick StoleeOct 17, 2021
  8. Junio C HamanoOct 18, 2021
  9. Derrick StoleeOct 18, 2021
  10. Victoria DyeOct 18, 2021
  11. Derrick StoleeOct 21, 2021
  12. Junio C HamanoOct 18, 2021
  13. 0/3 sparse-index: expand/collapse based on 'index.sparse'Victoria Dye via GitGitGadget, Oct 21, 2021
  14. 1/3 test-read-cache.c: prepare_repo_settings after config initVictoria Dye via GitGitGadget, Oct 21, 2021
  15. 3/3 sparse-index: update do_read_index to ensure correct sparsityVictoria Dye via GitGitGadget, Oct 21, 2021
  16. 2/3 sparse-index: add ensure_correct_sparsity functionVictoria Dye via GitGitGadget, Oct 21, 2021
  17. Junio C HamanoOct 21, 2021
  18. Victoria DyeOct 27, 2021
  19. 0/3 sparse-index: expand/collapse based on 'index.sparse'Victoria Dye via GitGitGadget, Oct 27, 2021
  20. 1/3 test-read-cache.c: prepare_repo_settings after config initVictoria Dye via GitGitGadget, Oct 27, 2021
  21. 2/3 sparse-index: add ensure_correct_sparsity functionVictoria Dye via GitGitGadget, Oct 27, 2021
  22. Derrick StoleeOct 27, 2021
  23. Junio C HamanoOct 27, 2021
  24. Derrick StoleeOct 28, 2021
  25. Victoria DyeOct 29, 2021
  26. 3/3 sparse-index: update do_read_index to ensure correct sparsityVictoria Dye via GitGitGadget, Oct 27, 2021
  27. Derrick StoleeOct 27, 2021
  28. 0/4 sparse-index: expand/collapse based on 'index.sparse'Victoria Dye via GitGitGadget, Oct 29, 2021
  29. 1/4 test-read-cache.c: prepare_repo_settings after config initVictoria Dye via GitGitGadget, Oct 29, 2021
  30. 2/4 sparse-index: avoid unnecessary cache tree clearingVictoria Dye via GitGitGadget, Oct 29, 2021
  31. Junio C HamanoOct 29, 2021
  32. Derrick StoleeOct 29, 2021
  33. Junio C HamanoOct 29, 2021
  34. 4/4 sparse-index: update do_read_index to ensure correct sparsityVictoria Dye via GitGitGadget, Oct 29, 2021
  35. Elijah NewrenNov 22, 2021
  36. Victoria DyeNov 22, 2021
  37. 3/4 sparse-index: add ensure_correct_sparsity functionVictoria Dye via GitGitGadget, Oct 29, 2021
  38. Elijah NewrenNov 22, 2021
  39. 0/4 sparse-index: expand/collapse based on 'index.sparse'Victoria Dye via GitGitGadget, Nov 23, 2021
  40. 1/4 test-read-cache.c: prepare_repo_settings after config initVictoria Dye via GitGitGadget, Nov 23, 2021
  41. 2/4 sparse-index: avoid unnecessary cache tree clearingVictoria Dye via GitGitGadget, Nov 23, 2021
  42. 3/4 sparse-index: add ensure_correct_sparsity functionVictoria Dye via GitGitGadget, Nov 23, 2021
  43. 4/4 sparse-index: update do_read_index to ensure correct sparsityVictoria Dye via GitGitGadget, Nov 23, 2021
  44. Elijah NewrenNov 23, 2021

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.