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

Re: [PATCH v2 1/2] diff: enable and test the sparse index

From
Lessley Dennington <lessleydennington@gmail.com>
Date
Oct 26, 2021, 16:10 UTC
Message-ID
<6e2c07e7-c66f-01c0-a64e-2e8b5b7c1f8e@gmail.com>
In-Reply-To
<YXcX5QWFQFIFNXo0@nand.local>
On 10/25/21 1:47 PM, Taylor Blau wrote:
Show 22 quoted lines
> On Fri, Oct 15, 2021 at 09:20:34PM +0000, Lessley Dennington via GitGitGadget wrote:
>> From: Lessley Dennington <lessleydennington@gmail.com>
>>
>> Enable the sparse index within the 'git diff' command. Its implementation
>> already safely integrates with the sparse index because it shares code with
>> the 'git status' and 'git checkout' commands that were already integrated.
> 
> Good, it looks like most of the heavy-lifting to make `git diff` work
> with the sparse index was already done elsewhere.
> 
> It may be helpful here to include either one of two things to help
> readers and reviewers understand what's going on:
> 
>    - A summary of what `git status` and/or `git checkout` does to work
>      with the sparse index.
>    - Or the patches which make those commands work with the sparse index
>      so that readers can refer back to them.
> 
> Having either of those would help readers who are unfamiliar with
> builtin/diff.c convince themselves more easily that setting
> 'command_requires_full_index = 0' is all that's needed here.
> 
Great suggestion, thank you!
Show 92 quoted lines
>> The most interesting thing to do is to add tests that verify that 'git diff'
>> behaves correctly when the sparse index is enabled. These cases are:
>>
>> 1. The index is not expanded for 'diff' and 'diff --staged'
>> 2. 'diff' and 'diff --staged' behave the same in full checkout, sparse
>> checkout, and sparse index repositories in the following partially-staged
>> scenarios (i.e. the index, HEAD, and working directory differ at a given
>> path):
>>      1. Path is within sparse-checkout cone
>>      2. Path is outside sparse-checkout cone
>>      3. A merge conflict exists for paths outside sparse-checkout cone
> 
> Nice, these are all of the test cases that I would expect to demonstrate
> interesting behavior.
> 
>> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
>> index f19c1b3e2eb..e5d15be9d45 100755
>> --- a/t/t1092-sparse-checkout-compatibility.sh
>> +++ b/t/t1092-sparse-checkout-compatibility.sh
>> @@ -386,6 +386,46 @@ test_expect_success 'diff --staged' '
>>   	test_all_match git diff --staged
>>   '
>>
>> +test_expect_success 'diff partially-staged' '
>> +	init_repos &&
>> +
>> +	write_script edit-contents <<-\EOF &&
>> +	echo text >>$1
>> +	EOF
>> +
>> +	# Add file within cone
>> +	test_sparse_match git sparse-checkout set deep &&
>> +	run_on_all ../edit-contents deep/testfile &&
>> +	test_all_match git add deep/testfile &&
>> +	run_on_all ../edit-contents deep/testfile &&
>> +
>> +	test_all_match git diff &&
>> +	test_all_match git diff --staged &&
>> +
>> +	# Add file outside cone
>> +	test_all_match git reset --hard &&
>> +	run_on_all mkdir newdirectory &&
>> +	run_on_all ../edit-contents newdirectory/testfile &&
>> +	test_sparse_match git sparse-checkout set newdirectory &&
>> +	test_all_match git add newdirectory/testfile &&
>> +	run_on_all ../edit-contents newdirectory/testfile &&
>> +	test_sparse_match git sparse-checkout set &&
>> +
>> +	test_all_match git diff &&
>> +	test_all_match git diff --staged &&
>> +
>> +	# Merge conflict outside cone
>> +	# The sparse checkout will report a warning that is not in the
>> +	# full checkout, so we use `run_on_all` instead of
>> +	# `test_all_match`
>> +	run_on_all git reset --hard &&
>> +	test_all_match git checkout merge-left &&
>> +	test_all_match test_must_fail git merge merge-right &&
>> +
>> +	test_all_match git diff &&
>> +	test_all_match git diff --staged
>> +'
>> +
>>   # NEEDSWORK: sparse-checkout behaves differently from full-checkout when
>>   # running this test with 'df-conflict-2' after 'df-conflict-1'.
>>   test_expect_success 'diff with renames and conflicts' '
>> @@ -800,6 +840,11 @@ test_expect_success 'sparse-index is not expanded' '
>>   	# Wildcard identifies only full sparse directories, no index expansion
>>   	ensure_not_expanded reset deepest -- folder\* &&
>>
>> +	echo a test change >>sparse-index/README.md &&
>> +	ensure_not_expanded diff &&
> 
> Thinking aloud here as somebody who is unfamiliar with the sparse-index
> tests. ensure_not_expanded relies on the existence of the "sparse-index"
> repository, and its top-level README.md is outside of the
> sparse-checkout cone.
> 
> That makes sense, and when I create a repository with a file outside of
> the sparse-checkout cone and then run `git diff`, I see no changes as
> expected.
> 
> But isn't the top-level directory always part of the cone? If so, I
> think that what this (and the below test) is demonstrating is that we
> can show changes inside of the cone without expanding the sparse-index.
> 
> Having that test makes absolute sense to me. But I think it might also
> make sense to have a test that creates some directory structure outside
> of the cone, modifies it, and then ensures that both (a) those changes
> aren't visible to `git diff` when the sparse-checkout is active and (b)
> that running `git diff` doesn't cause the sparse-index to be expanded.
> 

README.md is actually within the sparse checkout cone - all files at root are included by default. So your understanding is correct - we are ensuring that making a change to a file in the cone and running both diff and diff --staged once the file is in the index doesn't expand the sparse index.

I like your idea of verifying that running diff against files outside the sparse checkout cone won't expand the index. I've updated the diff tests in v3 (which I will send out shortly) to do so.

> Thanks,
> Taylor
> 

Best, Lessley

Previous: Taylor BlauNext: Taylor Blau
Message 10 of 66 in “Sparse Index: diff and blame builtins”
  1. 0/2 Sparse Index: diff and blame builtinsLessley Dennington via GitGitGadget, Oct 14, 2021
  2. 1/2 diff: enable and test the sparse indexLessley Dennington via GitGitGadget, Oct 14, 2021
  3. Derrick StoleeOct 15, 2021
  4. 2/2 blame: enable and test the sparse indexLessley Dennington via GitGitGadget, Oct 14, 2021
  5. Elijah NewrenNov 23, 2021
  6. Lessley DenningtonNov 23, 2021
  7. 0/2 Sparse Index: diff and blame builtinsLessley Dennington via GitGitGadget, Oct 15, 2021
  8. 1/2 diff: enable and test the sparse indexLessley Dennington via GitGitGadget, Oct 15, 2021
  9. Taylor BlauOct 25, 2021
  10. Lessley DenningtonOct 26, 2021
  11. Taylor BlauOct 26, 2021
  12. 2/2 blame: enable and test the sparse indexLessley Dennington via GitGitGadget, Oct 15, 2021
  13. Taylor BlauOct 25, 2021
  14. Lessley DenningtonOct 26, 2021
  15. Elijah NewrenNov 21, 2021
  16. 0/2 Sparse Index: diff and blame builtinsLessley Dennington via GitGitGadget, Nov 1, 2021
  17. 1/2 diff: enable and test the sparse indexLessley Dennington via GitGitGadget, Nov 1, 2021
  18. Junio C HamanoNov 3, 2021
  19. Lessley DenningtonNov 4, 2021
  20. 2/2 blame: enable and test the sparse indexLessley Dennington via GitGitGadget, Nov 1, 2021
  21. Junio C HamanoNov 3, 2021
  22. Lessley DenningtonNov 5, 2021
  23. Elijah NewrenNov 21, 2021
  24. 0/4 Sparse Index: diff and blame builtinsLessley Dennington via GitGitGadget, Nov 22, 2021
  25. 1/4 sparse index: enable only for git reposLessley Dennington via GitGitGadget, Nov 22, 2021
  26. Elijah NewrenNov 23, 2021
  27. Lessley DenningtonNov 23, 2021
  28. Junio C HamanoNov 23, 2021
  29. Lessley DenningtonNov 24, 2021
  30. Junio C HamanoNov 24, 2021
  31. Lessley DenningtonNov 29, 2021
  32. Junio C HamanoNov 30, 2021
  33. Lessley DenningtonNov 30, 2021
  34. 2/4 test-read-cache: set up repo after git directoryLessley Dennington via GitGitGadget, Nov 22, 2021
  35. Junio C HamanoNov 23, 2021
  36. Lessley DenningtonNov 24, 2021
  37. Junio C HamanoNov 24, 2021
  38. Lessley DenningtonNov 29, 2021
  39. 3/4 diff: enable and test the sparse indexLessley Dennington via GitGitGadget, Nov 22, 2021
  40. Elijah NewrenNov 23, 2021
  41. Lessley DenningtonNov 23, 2021
  42. Junio C HamanoNov 23, 2021
  43. 4/4 blame: enable and test the sparse indexLessley Dennington via GitGitGadget, Nov 22, 2021
  44. Junio C HamanoNov 23, 2021
  45. Lessley DenningtonNov 24, 2021
  46. 0/7 Sparse Index: diff and blame builtinsLessley Dennington via GitGitGadget, Dec 3, 2021
  47. 1/7 git: esnure correct git directory setup with -hLessley Dennington via GitGitGadget, Dec 3, 2021
  48. Elijah NewrenDec 4, 2021
  49. Junio C HamanoDec 4, 2021
  50. 2/7 commit-graph: return if there is no git directoryLessley Dennington via GitGitGadget, Dec 3, 2021
  51. 4/7 repo-settings: prepare_repo_settings only in git reposLessley Dennington via GitGitGadget, Dec 3, 2021
  52. Ævar Arnfjörð BjarmasonDec 7, 2021
  53. Lessley DenningtonDec 8, 2021
  54. 3/7 test-read-cache: set up repo after git directoryLessley Dennington via GitGitGadget, Dec 3, 2021
  55. 5/7 diff: replace --staged with --cached in t1092 testsLessley Dennington via GitGitGadget, Dec 3, 2021
  56. 6/7 diff: enable and test the sparse indexLessley Dennington via GitGitGadget, Dec 3, 2021
  57. 7/7 blame: enable and test the sparse indexLessley Dennington via GitGitGadget, Dec 3, 2021
  58. Elijah NewrenDec 4, 2021
  59. 0/7 Sparse Index: diff and blame builtinsLessley Dennington via GitGitGadget, Dec 6, 2021
  60. 1/7 git: ensure correct git directory setup with -hLessley Dennington via GitGitGadget, Dec 6, 2021
  61. 2/7 commit-graph: return if there is no git directoryLessley Dennington via GitGitGadget, Dec 6, 2021
  62. 3/7 test-read-cache: set up repo after git directoryLessley Dennington via GitGitGadget, Dec 6, 2021
  63. 4/7 repo-settings: prepare_repo_settings only in git reposLessley Dennington via GitGitGadget, Dec 6, 2021
  64. 5/7 diff: replace --staged with --cached in t1092 testsLessley Dennington via GitGitGadget, Dec 6, 2021
  65. 6/7 diff: enable and test the sparse indexLessley Dennington via GitGitGadget, Dec 6, 2021
  66. 7/7 blame: enable and test the sparse indexLessley Dennington via GitGitGadget, Dec 6, 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.