Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Documentation/config/core.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,17 @@ core.virtualFilesystem::
will identify all files and directories that are present in
the working directory. Git will only track and update files
listed in the virtual file system. Using the virtual file system
will supersede the sparse-checkout settings which will be ignored.
will supersede the sparse-checkout settings which will be ignored,
unless the repository uses cone-mode sparse-checkout and sets
`index.sparse` to `true` (the default value does not count). Then
the cone patterns decide which directories collapse into
sparse-directory entries in the index. Git does not check the
working tree for a path inside such a directory, even when the
virtual file system lists the path. In this mode, when
`git sparse-checkout set`, `add`, `reapply`, or `disable` applies
the patterns, Git changes only the index. It does not check out or
remove files in the working tree. `git sparse-checkout clean` still
removes directories outside of the cone.
See the "virtual file system" section of linkgit:githooks[5].

core.trustctime::
Expand Down
9 changes: 9 additions & 0 deletions builtin/sparse-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ static void clean_tracked_sparse_directories(struct repository *r)
*/
if (!r || !r->index || !r->worktree)
return;

/*
* A virtual file system owns the working tree, including the
* directories outside of the sparse-checkout cone. Do not delete
* them.
*/
if (repo_config_get_virtualfilesystem(the_repository))
return;

if (init_sparse_checkout_patterns(r->index) ||
!r->index->sparse_checkout_patterns->use_cone_patterns)
return;
Expand Down
18 changes: 14 additions & 4 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1539,12 +1539,19 @@ enum pattern_match_result path_matches_pattern_list(
int result = NOT_MATCHED;
size_t slash_pos;

if (core_virtualfilesystem) {
if (core_virtualfilesystem &&
!(pl->use_cone_patterns && vfs_sparse_index_configured())) {
/*
* The virtual file system data is used to prevent git from traversing
* any part of the tree that is not in the virtual file system. Return
* 1 to exclude the entry if it is not found in the virtual file system,
* else fall through to the regular excludes logic as it may further exclude.
*
* Skip this for cone-mode patterns when
* vfs_sparse_index_configured() is true. Here, a return value of
* 1 means "in the cone", so a directory that the virtual file
* system does not report would be in the cone, and it could
* never collapse into a sparse-directory entry.
*/
if (*dtype == DT_UNKNOWN)
*dtype = resolve_dtype(DT_UNKNOWN, istate, pathname, pathlen);
Expand Down Expand Up @@ -1644,10 +1651,13 @@ static int path_in_sparse_checkout_1(const char *path,
const char *end, *slash;

/*
* When using a virtual filesystem, there aren't really patterns
* to follow, but be extra careful to skip this check.
* A virtual file system decides which paths are present, so the
* sparse-checkout patterns do not apply. The exception is a
* repository that sets index.sparse to true and uses cone mode
* (see vfs_uses_cone_patterns()). There, the cone patterns decide,
* so that convert_to_sparse() can collapse out-of-cone directories.
*/
if (core_virtualfilesystem)
if (core_virtualfilesystem && !vfs_uses_cone_patterns(istate))
return 1;

/*
Expand Down
8 changes: 7 additions & 1 deletion read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2371,11 +2371,17 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
* If the command explicitly requires a full index, force it
* to be full. Otherwise, correct the sparsity based on repository
* settings and other properties of the index (if necessary).
*
* With a virtual file system, do not collapse a full index here.
* The skip-worktree bits that convert_to_sparse() checks are not
* correct until apply_virtualfilesystem() sets them, after this
* function. The index collapses when it is written.
*/
prepare_repo_settings(istate->repo);
if (istate->repo->settings.command_requires_full_index)
ensure_full_index_with_reason(istate, "incompatible builtin");
else
else if (!repo_config_get_virtualfilesystem(the_repository) ||
!vfs_uses_cone_patterns(istate))
ensure_correct_sparsity(istate);

return istate->cache_nr;
Expand Down
12 changes: 8 additions & 4 deletions sparse-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
struct pathspec ps;
int dtype = DT_UNKNOWN;

/*
* The name-hash of 'istate' is discarded below, but 'full'
* reuses this entry. Clear CE_HASHED so that the next
* lazy_init_name_hash() adds the entry to the new name-hash.
*/
ce->ce_flags &= ~CE_HASHED;

if (!S_ISSPARSEDIR(ce->ce_mode)) {
set_index_entry(full, full->cache_nr++, ce);
continue;
Expand Down Expand Up @@ -448,10 +455,7 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
}

/* Copy back into original index. */
if (istate->name_hash_initialized) {
hashmap_clear(&istate->name_hash);
hashmap_clear(&istate->dir_hash);
}
free_name_hash(istate);

istate->name_hash_initialized = full->name_hash_initialized;
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
Expand Down
32 changes: 32 additions & 0 deletions t/helper/test-read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,59 @@
#include "test-tool.h"
#include "config.h"
#include "environment.h"
#include "name-hash.h"
#include "read-cache-ll.h"
#include "repository.h"
#include "setup.h"
#include "sparse-index.h"

/*
* Look up 'name' in the name-hash, expand the index to a full index, and
* look it up again. The first lookup initializes the name-hash.
*/
static void expand_and_find(struct index_state *istate, const char *name)
{
int before = !!index_file_exists(istate, name, strlen(name), 0);

ensure_full_index(istate);
printf("%s: %s, %s\n", name,
before ? "found" : "not found",
index_file_exists(istate, name, strlen(name), 0) ?
"found" : "not found");
}

int cmd__read_cache(int argc, const char **argv)
{
int i, cnt = 1;
const char *name = NULL;
const char *find_name = NULL;

if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
argc--;
argv++;
}

if (argc > 1 &&
skip_prefix(argv[1], "--expand-and-find=", &find_name)) {
argc--;
argv++;
}

if (argc == 2)
cnt = strtol(argv[1], NULL, 0);
setup_git_directory(the_repository);
repo_config(the_repository, git_default_config, NULL);

if (find_name) {
/* Read the index as it is on disk, without an expansion. */
prepare_repo_settings(the_repository);
the_repository->settings.command_requires_full_index = 0;
}

for (i = 0; i < cnt; i++) {
repo_read_index(the_repository);
if (find_name)
expand_and_find(the_repository->index, find_name);
if (name) {
int pos;

Expand Down
3 changes: 3 additions & 0 deletions t/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ integration_tests = [
't1091-sparse-checkout-builtin.sh',
't1092-sparse-checkout-compatibility.sh',
't1093-virtualfilesystem.sh',
't1095-virtualfilesystem-sparse-index.sh',
't1096-virtualfilesystem-sparse-cone.sh',
't1097-virtualfilesystem-sparsity-index-only.sh',
't1100-commit-tree-options.sh',
't1300-config.sh',
't1301-shared-repo.sh',
Expand Down
35 changes: 35 additions & 0 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2863,4 +2863,39 @@ test_expect_success 'ensure_full_index_with_reason' '
"failed to clear skip-worktree while sparse" <status-trace
'

test_expect_success 'name-hash finds reused entries after expansion' '
init_repos &&

test-tool -C sparse-index read-cache --expand-and-find=deep/a >actual &&
echo "deep/a: found, found" >expect &&
test_cmp expect actual
'

test_expect_success 'status with core.ignoreCase after the index expands' '
git init icase &&
(
cd icase &&
mkdir out zin &&
for f in out/f zin/a zin/b
do
echo "$f" >$f || return 1
done &&
git add . &&
git commit -m init &&
git config core.ignoreCase true &&
git config index.sparse true &&
git config sparse.expectFilesOutsideOfPatterns true &&
git sparse-checkout set zin &&

# If readdir() returns "out/" before "zin/" (as on NTFS),
# the lookup in "out/" expands the index before the walk
# looks up "zin/". The test above does not depend on this.
mkdir out &&
echo new >out/new &&
git status --porcelain >../icase-actual
) &&
echo "?? out/new" >expect &&
test_cmp expect icase-actual
'

test_done
Loading
Loading