config: add setting to ignore sparsity patterns in some cmds

When sparse checkout is enabled, some users expect the output of certain
commands (such as grep, diff, and log) to be also restricted within the
sparsity patterns. This would allow them to effectively work only on the
subset of files in which they are interested; and allow some commands to
possibly perform better, by not considering uninteresting paths. For
this reason, we taught grep to honor the sparsity patterns, in the
previous patch. But, on the other hand, allowing grep and the other
commands mentioned to optionally ignore the patterns also make for some
interesting use cases. E.g. using grep to search for a function
documentation that resides outside the sparse checkout.

In any case, there is no current way for users to configure the behavior
they want for these commands. Aiming to provide this flexibility, let's
introduce the sparse.restrictCmds setting (and the analogous
--[no]-restrict-to-sparse-paths global option). The default value is
true. For now, grep is the only one affected by this setting, but the
goal is to have support for more commands, in the future.

Helped-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Matheus Tavares
2020-06-12 12:45:04 -03:00
committed by Junio C Hamano
parent e26e8bfcdb
commit 7506484113
12 changed files with 214 additions and 6 deletions

11
sparse-checkout.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef SPARSE_CHECKOUT_H
#define SPARSE_CHECKOUT_H
struct repository;
extern int opt_restrict_to_sparse_paths;
/* Whether or not cmds should restrict behavior on sparse paths, in this repo */
int restrict_to_sparse_paths(struct repository *repo);
#endif /* SPARSE_CHECKOUT_H */