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

Re: [PATCH v3 2/2] blame: enable and test the sparse index

From
Elijah Newren <newren@gmail.com>
Date
Nov 21, 2021, 01:46 UTC
Message-ID
<CABPp-BH2O+fezCui0utYbpShp6NaMwWapyr8i+mDDjjhzec4LQ@mail.gmail.com>
In-Reply-To
<xmqqh7ct89us.fsf@gitster.g>
On Wed, Nov 3, 2021 at 9:47 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
>
> "Lessley Dennington via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
>
> > We do not include paths outside the sparse checkout cone because blame
> > currently does not support blaming files outside of the sparse definition.
> > Attempting to do so fails with the following error:
> >
> >   fatal: no such path '<path outside sparse definition>' in HEAD
>
> Does this indicate that we need to update how the command line
> safety in verify_working_tree_path() works in a sparsely checked out
> working tree?

I wondered the same thing, but no I don't think we need any extra command line safety here. The behavior Lessley is reporting here is equivalent to the following in a regular (non-sparse) checkout:

$ rm t/test-lib.sh $ git blame t/test-lib.sh fatal: Cannot lstat 't/test-lib.sh': No such file or directory $ git blame -- t/test-lib.sh fatal: Cannot lstat 't/test-lib.sh': No such file or directory

blame without a revision has always failed for files not in the working tree, regardless of whether those files are found in the index or HEAD.

>  If foo/bar is outside the sparse definition,
>
>     git blame HEAD foo/bar

Actually, that works; there's no error and the code with Lessley's patch will show the blame info for foo/bar (assuming foo/bar was a path in HEAD, of course).

Show 5 quoted lines
> may get such a message, but shouldn't
>
>     git blame HEAD -- foo/bar
>
> make it work?

This also works. But both of these things are kind of testing something different; when given a revision, the checkout is irrelevant to git blame: git blame with a revision will work regardless of whether the checkout is full, sparse, completely empty, or non-existent (i.e. a bare clone).

Show 8 quoted lines
> > -# TODO: blame currently does not support blaming files outside of the
> > -# sparse definition. It complains that the file doesn't exist locally.
> > -test_expect_failure 'blame with pathspec outside sparse definition' '
> > +# Blame does not support blaming files outside of the sparse
> > +# definition, so we verify this scenario.
>
> IOW, why is it a good idea to drop the "TODO" and "currently" and pretend
> as if the current behaviour is the desirable one?

I think dropping the TODO is correct, but the wording is confusing -- it has nothing to do with sparse checkouts. I'd rather say, "Without a specified revision, blame will only handle files present in the current working directory and error on any other paths"

Show 44 quoted lines
> > +test_expect_success 'blame with pathspec outside sparse definition' '
> >       init_repos &&
> > +     test_sparse_match git sparse-checkout set &&
> >
> > -     test_all_match git blame folder1/a &&
> > -     test_all_match git blame folder2/a &&
> > -     test_all_match git blame deep/deeper2/a &&
> > -     test_all_match git blame deep/deeper2/deepest/a
> > +     for file in a \
> > +                     deep/a \
> > +                     deep/deeper1/a \
> > +                     deep/deeper1/deepest/a
> > +     do
> > +             test_sparse_match test_must_fail git blame $file &&
> > +             cat >expect <<-EOF &&
> > +             fatal: Cannot lstat '"'"'$file'"'"': No such file or directory
> > +             EOF
> > +             # We compare sparse-checkout-err and sparse-index-err in
> > +             # `test_sparse_match`. Given we know they are the same, we
> > +             # only check the content of sparse-index-err here.
> > +             test_cmp expect sparse-index-err
> > +     done
> >  '
> >
> >  test_expect_success 'checkout and reset (mixed)' '
> > @@ -878,6 +892,18 @@ test_expect_success 'sparse index is not expanded: diff' '
> >       ensure_not_expanded diff --staged
> >  '
> >
> > +test_expect_success 'sparse index is not expanded: blame' '
> > +     init_repos &&
> > +
> > +     for file in a \
> > +                     deep/a \
> > +                     deep/deeper1/a \
> > +                     deep/deeper1/deepest/a
> > +     do
> > +             ensure_not_expanded blame $file
> > +     done
> > +'
> > +
> >  # NEEDSWORK: a sparse-checkout behaves differently from a full checkout
> >  # in this scenario, but it shouldn't.
> >  test_expect_success 'reset mixed and checkout orphan' '
Previous: Lessley DenningtonNext: Lessley Dennington via GitGitGadget
Message 23 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.