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

Re: [PATCH v3 2/3] sparse-index: add ensure_correct_sparsity function

From
Victoria Dye <vdye@github.com>
Date
Oct 29, 2021, 13:43 UTC
Message-ID
<74501e70-7bac-e301-4075-09152f292884@github.com>
In-Reply-To
<bc960863-7ff2-d6bf-9710-6803f3784751@gmail.com>
Derrick Stolee wrote:
Show 72 quoted lines
> On 10/27/2021 5:32 PM, Junio C Hamano wrote:
>> Derrick Stolee <stolee@gmail.com> writes:
>>
>>>> +int convert_to_sparse(struct index_state *istate, int flags)
>>>> +{
>>>> +	/*
>>>> +	 * If the index is already sparse, empty, or otherwise
>>>> +	 * cannot be converted to sparse, do not convert.
>>>> +	 */
>>>> +	if (istate->sparse_index || !istate->cache_nr ||
>>>> +	    !is_sparse_index_allowed(istate, flags))
>>>> +		return 0;
>>
>> Shouldn't we also at least do this?  Blindly blowing away the entire
>> cache-tree and rebuilding it from scratch may be hiding a latent bug
>> somewhere else, but is never supposed to be needed, and is a huge
>> waste of computational resources.
>>
>> I say "at least" here, because a cache tree that is partially valid
>> should be safely salvageable---at least that was the intention back
>> when I designed the subsystem.
> 
> I think you are right, what you propose below. It certainly seems
> like it would work, and even speed up the conversion from full to
> sparse. I think I erred on the side of extreme caution and used
> a hope that converting to sparse would be rare.
> 
>>  sparse-index.c | 24 +++++++++++++-----------
>>  1 file changed, 13 insertions(+), 11 deletions(-)
>>
>> diff --git c/sparse-index.c w/sparse-index.c
>> index bc3ee358c6..a95c3386f3 100644
>> --- c/sparse-index.c
>> +++ w/sparse-index.c
>> @@ -188,17 +188,19 @@ int convert_to_sparse(struct index_state *istate, int flags)
>>  	if (index_has_unmerged_entries(istate))
>>  		return 0;
>>  
>> -	/* Clear and recompute the cache-tree */
>> -	cache_tree_free(&istate->cache_tree);
>> -	/*
>> -	 * Silently return if there is a problem with the cache tree update,
>> -	 * which might just be due to a conflict state in some entry.
>> -	 *
>> -	 * This might create new tree objects, so be sure to use
>> -	 * WRITE_TREE_MISSING_OK.
>> -	 */
>> -	if (cache_tree_update(istate, WRITE_TREE_MISSING_OK))
>> -		return 0;
>> +	if (!cache_tree_fully_valid(&istate->cache_tree)) {
>> +		/* Clear and recompute the cache-tree */
>> +		cache_tree_free(&istate->cache_tree);
>> +		/*
>> +		 * Silently return if there is a problem with the cache tree update,
>> +		 * which might just be due to a conflict state in some entry.
>> +		 *
>> +		 * This might create new tree objects, so be sure to use
>> +		 * WRITE_TREE_MISSING_OK.
>> +		 */
>> +		if (cache_tree_update(istate, WRITE_TREE_MISSING_OK))
>> +			return 0;
>> +	}
> 
> I think at this point we have enough tests that check the sparse index
> and its different conversion points that the test suite might catch if
> this is a bad idea. Note that this is only a change of behavior if the
> cache-tree is valid, which I expect to be the case most of the time in
> the tests.
> 
> Thanks,
> -Stolee
> 

This change doesn't appear to introduce any test failures or other unwanted behavior, so I don't see a reason not to include it. I'll add it in a re-roll - thanks!

Previous: Derrick StoleeNext: Victoria Dye via GitGitGadget
Message 25 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.