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
14 changes: 13 additions & 1 deletion Documentation/config/core.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,19 @@ 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. A build of Git that
supports a sparse index under a virtual file system prints
`feature: vfs-sparse-index` in `git version --build-options`.
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
69 changes: 65 additions & 4 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,26 @@ static int read_skip_worktree_file_from_index(struct index_state *istate,
struct oid_stat *oid_stat)
{
int pos, len;
struct cache_entry *sparse_dir;

len = strlen(path);

/*
* Everything inside a sparse-directory entry has the skip-worktree
* bit, so read the blob from the tree of that entry. Compare with
* case, as index_name_pos() does.
*/
sparse_dir = vfs_sparse_dir_containing(istate, path, len, 0);
if (sparse_dir) {
struct object_id oid;
unsigned short mode;

if (sparse_dir_get_tree_entry(istate, sparse_dir, path, len, 0,
&oid, &mode))
return -1;
return do_read_blob(&oid, oid_stat, size_out, data_out);
}

pos = index_name_pos(istate, path, len);
if (pos < 0)
return -1;
Expand Down Expand Up @@ -1252,6 +1270,8 @@ static int add_patterns(const char *fname, const char *base, int baselen,
!match_stat_data_racy(istate, &oid_stat->stat, &st))
; /* no content change, oid_stat->oid still good */
else if (istate &&
!vfs_sparse_dir_containing(istate, fname,
strlen(fname), 0) &&
(pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
!ce_stage(istate->cache[pos]) &&
ce_uptodate(istate->cache[pos]) &&
Expand Down Expand Up @@ -1539,12 +1559,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 +1671,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 Expand Up @@ -1994,6 +2024,29 @@ static enum exist_status directory_exists_in_index(struct index_state *istate,
const char *dirname, int len)
{
int pos;
struct cache_entry *sparse_dir;

/*
* The name hash does not contain the directories inside a
* sparse-directory entry, so look in its tree before the
* case-insensitive lookup below.
*/
sparse_dir = vfs_sparse_dir_containing(
istate, dirname, len, repo_ignore_case(the_repository));
if (sparse_dir) {
struct object_id oid;
unsigned short mode;

if (sparse_dir_get_tree_entry(istate, sparse_dir, dirname, len,
repo_ignore_case(the_repository),
&oid, &mode))
return index_nonexistent;
if (S_ISDIR(mode))
return index_directory;
if (S_ISGITLINK(mode))
return index_gitdir;
return index_nonexistent;
}

if (repo_ignore_case(the_repository))
return directory_exists_in_index_icase(istate, dirname, len);
Expand Down Expand Up @@ -2400,6 +2453,14 @@ static int get_index_dtype(struct index_state *istate,
return DT_REG;
}

/*
* A sparse-directory entry contains this path, so the index has no
* entries below it to scan. Return DT_UNKNOWN and let the caller
* use lstat(), instead of an expansion of the whole index.
*/
if (vfs_sparse_dir_containing(istate, path, len, 0))
return DT_UNKNOWN;

/* Try to look it up as a directory */
pos = index_name_pos(istate, path, len);
if (pos >= 0)
Expand Down
15 changes: 15 additions & 0 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,21 @@ void get_version_info(struct strbuf *buf, int show_build_options)

if (fsmonitor_ipc__is_supported())
strbuf_addstr(buf, "feature: fsmonitor--daemon\n");
/*
* A virtual file system reads this line before it enables
* a sparse index. Under core.virtualFilesystem, the line
* promises all of this: the working-tree walk and
* apply_virtualfilesystem() do not expand a sparse index;
* expand_index() keeps the name-hash correct; with cone
* mode and an explicit index.sparse=true, the cone
* patterns decide which directories collapse, a full
* index collapses when it is written, not when it is read,
* and "git sparse-checkout set", "add", "reapply", "init",
* and "disable" change only the index: they do not check
* out, remove, or clean up files in the working tree. If
* any part goes away, remove the line.
*/
strbuf_addstr(buf, "feature: vfs-sparse-index\n");
#if !defined NO_GETTEXT
strbuf_addstr(buf, "gettext: enabled\n");
#endif
Expand Down
31 changes: 30 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 Expand Up @@ -3501,8 +3507,31 @@ int index_name_is_other(struct index_state *istate, const char *name,
int namelen)
{
int pos;
struct cache_entry *sparse_dir;

if (namelen && name[namelen - 1] == '/')
namelen--;

/*
* An index has entries for files only, so a directory in the tree
* of a sparse-directory entry is still "other". Compare without
* case if core.ignoreCase is set: with a full index, the walk
* already drops such tracked paths with index_file_exists().
*/
sparse_dir = vfs_sparse_dir_containing(
istate, name, namelen, repo_ignore_case(the_repository));
if (sparse_dir) {
struct object_id oid;
unsigned short mode;

if (sparse_dir_get_tree_entry(istate, sparse_dir, name, namelen,
repo_ignore_case(the_repository),
&oid, &mode) ||
S_ISDIR(mode))
return 1;
return 0;
}

pos = index_name_pos(istate, name, namelen);
if (0 <= pos)
return 0; /* exact match */
Expand Down
Loading
Loading