In [1], we discovered that users working on different sparse-checkout specification may download unnecessary blobs from each other's specification in collaboration. In [2] Junio suggested that maybe we can restrict some git command's filespec in sparse-checkout specification to elegantly solve this problem above. In [3]: Newren and Derrick Stolee prefer to name the option --scope={sparse, all}. So this patch is attempt to do this thing on git diff: v1: 1. add --restrict option to git diff, which restrict diff filespec in sparse-checkout specification. [4] v2. 1. rename --restrict to --scope={sparse, all}, support --no-scope. 2. add config: diff.scope={sparse,all}. v3. 1. with the help of newren's review, fix the wrong --scope behavior, its previous meaning was misrepresented as sparse patterns, and now it is fixed to match sparse specification. [5] 2. remove wrong diff.scope config. 3. apply --scope to git diff, git diff-index, git diff-tree. v4. 1. create a OPT_SPARSE_SCOPE macro for easier add --scope option to other git commands later. 2. introduce --scope option to "git grep ". Since I split --scope into a separate option, this option will not be directly inherited by git commands such as git log, git format-patch, etc. If necessary, we can add it to git log or other commands in a similar way later. Global scope config haven’t implement yet... Since we haven't decided on an appropriate name for scope config. [6] Note why I don't add --scope to "git grep --cached", because we can't use "" with "--cached", whether we use --scope=sparse or not , the resulting set of files it gets is the same. [1]: https://lore.kernel.org/git/CAOLTT8SHo66kGbvWr=+LQ9UVd1NHgqGGEYK2qq6==QgRCgLZqQ@xxxxxxxxxxxxxx/ [2]: https://lore.kernel.org/git/xmqqzgeqw0sy.fsf@gitster.g/ [3]: https://lore.kernel.org/git/07a25d48-e364-0d9b-6ffa-41a5984eb5db@xxxxxxxxxx/ [4]: https://lore.kernel.org/git/pull.1368.git.1664036052741.gitgitgadget@xxxxxxxxx/ [5]: https://lore.kernel.org/git/CAOLTT8TceM-NpV2_hUCZj2Dx=W30f_9SHW8CcRH-pw32BRd-oA@xxxxxxxxxxxxxx/ [6]: https://lore.kernel.org/git/CABPp-BGHMsMxP6e7p0HAZA=ugk+GY3XW6_EaTN=HzaLQYAzQYA@xxxxxxxxxxxxxx/ ZheNing Hu (2): [RFC] diff: introduce --scope option [RPC] grep: introduce --scope option Documentation/diff-options.txt | 33 ++++ Documentation/git-grep.txt | 24 +++ builtin/diff-index.c | 24 ++- builtin/diff-tree.c | 11 ++ builtin/diff.c | 23 ++- builtin/grep.c | 10 + cache.h | 5 + diff-lib.c | 43 +++++ diff.c | 2 + diff.h | 7 + dir.c | 52 ++++++ dir.h | 4 + grep.h | 2 + parse-options.h | 7 + t/t1090-sparse-checkout-scope.sh | 303 +++++++++++++++++++++++++++++++ tree-diff.c | 7 + 16 files changed, 551 insertions(+), 6 deletions(-) base-commit: 815c1e82021edbd99a2c423cf27f28863f28cef3 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1398%2Fadlternative%2Fzh%2Fdiff-scope-v3 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1398/adlternative/zh/diff-scope-v3 Pull-Request: https://github.com/gitgitgadget/git/pull/1398 Contributor requested no range-diff. You can review it using these commands: git fetch https://github.com/gitgitgadget/git c000d916 1d1b6618 git range-diff <options> c000d916..471a0691 083e0127..1d1b6618 -- gitgitgadget