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

Re: [PATCH v3 5/5] config: add setting to ignore sparsity patterns in some cmds

From
Matheus Tavares Bernardino <matheus.bernardino@usp.br>
Date
Jun 10, 2020, 21:15 UTC
Message-ID
<CAHd-oW5gqs1uG5L4=JaT6Jzs58StE1WO0goPJE2atumbyC3Wow@mail.gmail.com>
In-Reply-To
<CABPp-BH0d5WKz7bXLkFQGDBKXbd0tccS_+1_iNc1Wqr93h+KaQ@mail.gmail.com>
On Tue, Jun 2, 2020 at 11:40 PM Elijah Newren <newren@gmail.com> wrote:
Show 20 quoted lines
>
> On Sun, May 31, 2020 at 9:46 PM Matheus Tavares Bernardino
> <matheus.bernardino@usp.br> wrote:
> >
>
> Moving it to grep's manpage seems ideal to me.  grep's behavior should
> be defined in grep's manual.
>
> > sparse.restrictCmds::
> > See complete definition in linkgit:git-config[1]. In grep, the
> > restriction takes effect in three cases: with --cached; when a
> > commit-ish is given; when searching a working tree where some paths
> > excluded by the sparsity patterns are present (e.g. manually created
> > paths or not removed submodules).
>
> That looks more than a little confusing.  Could this definition be
> something more like "See base definition in linkgit:git-config[1].
> grep honors sparse.restrictCmds by limiting searches to the sparsity
> paths in three cases: when searching the working tree, when searching
> the index with --cached, or when searching a specified commit"

Yes, this looks better, thanks. I would only add a brief explanation on what we mean by limiting the search in the working tree case. Since the working tree should already contain only the sparse paths (in most cases), I think this sentence may sound a little confusing without some explanation. Even further, some users might expect that `git -c sparse.restrictCmds=false grep $pattern` would restore the previous behavior of falling back to the cache for non-present entries, which is not true.

In particular, I would like to emphasize that the use for `sparse.restrictCmds=false` in the working tree case, is for situations like the one you described in [1]:

* uses sparse-checkout to remove a bunch of files/directories they
don't care about
* creates a new file that happens to have the same name as an
(unfortunately) generically worded filename that exists in the index
(but is marked SKIP_WORKTREE and had previously been removed)

In this situation, grep would ignore the said file by default, but search it with `sparse.restrictCmds=false`.

So what do you think of the following:

sparse.restrictCmds:: See base definition in linkgit:git-config[1]. grep honors sparse.restrictCmds by limiting searches to the sparsity paths in three cases: when searching the working tree, when searching the index with --cached, and when searching a specified commit. Note: when this option is set to true (default), the working tree search will ignore paths that are present despite not matching the sparsity patterns. This can happen, for example, if you create a new file in a path that was previously removed by git-sparse-checkout. Or if you don't deinitialize a submodule that is excluded by the sparsity patterns (thus remaining in the working copy, anyway).

[1]: https://lore.kernel.org/git/CABPp-BE+BL3Nq=Co=-kNB_wr=6gqX8zcGwa0ega_pGBpk6xYsg@mail.gmail.com/
Previous: Elijah NewrenNext: Elijah Newren
Message 18 of 31 in “grep: honor sparse checkout and add option to ignore it”
  1. 0/5 grep: honor sparse checkout and add option to ignore itMatheus Tavares, May 28, 2020
  2. 1/5 doc: grep: unify info on configuration variablesMatheus Tavares, May 28, 2020
  3. 3/5 config: correctly read worktree configs in submodulesMatheus Tavares, May 28, 2020
  4. Elijah NewrenMay 30, 2020
  5. Matheus Tavares BernardinoJun 1, 2020
  6. 2/5 t/helper/test-config: return exit codes consistentlyMatheus Tavares, May 28, 2020
  7. Elijah NewrenMay 30, 2020
  8. Matheus Tavares BernardinoJun 1, 2020
  9. 4/5 grep: honor sparse checkout patternsMatheus Tavares, May 28, 2020
  10. Elijah NewrenMay 30, 2020
  11. Matheus Tavares BernardinoJun 1, 2020
  12. Elijah NewrenJun 3, 2020
  13. Matheus Tavares BernardinoJun 10, 2020
  14. 5/5 config: add setting to ignore sparsity patterns in some cmdsMatheus Tavares, May 28, 2020
  15. Elijah NewrenMay 30, 2020
  16. Matheus Tavares BernardinoJun 1, 2020
  17. Elijah NewrenJun 3, 2020
  18. Matheus Tavares BernardinoJun 10, 2020
  19. Elijah NewrenJun 11, 2020
  20. 0/6 grep: honor sparse checkout and add option to ignore itMatheus Tavares, Jun 12, 2020
  21. 2/6 t/helper/test-config: return exit codes consistentlyMatheus Tavares, Jun 12, 2020
  22. 1/6 doc: grep: unify info on configuration variablesMatheus Tavares, Jun 12, 2020
  23. 3/6 t/helper/test-config: facilitate addition of new cli optionsMatheus Tavares, Jun 12, 2020
  24. 4/6 config: correctly read worktree configs in submodulesMatheus Tavares, Jun 12, 2020
  25. Elijah NewrenJun 16, 2020
  26. Matheus Tavares BernardinoJun 21, 2020
  27. Jonathan NiederSep 1, 2020
  28. Matheus Tavares BernardinoSep 1, 2020
  29. 5/6 grep: honor sparse checkout patternsMatheus Tavares, Jun 12, 2020
  30. 6/6 config: add setting to ignore sparsity patterns in some cmdsMatheus Tavares, Jun 12, 2020
  31. Elijah NewrenJun 16, 2020

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.