Repository navigation
Add sparse-checkout cone builder, writer, and path matcher - #2190
Draft
Tyrie Vella (tyrielv) wants to merge 1 commit into
Draft
Tyrie Vella (tyrielv) wants to merge 1 commit into
Tyrie Vella (tyrielv) wants to merge 1 commit into
Conversation
Tyrie Vella (tyrielv)
force-pushed
the
tyrielv/sparse-index/cone-builder
branch
3 times, most recently
from
November 16, 2026 22:06
2ad6c76 to
5ed6d29
Compare
Tyrie Vella (tyrielv)
changed the base branch from
vnext
to
tyrielv/sparse-index/projection-expand-sparse-dirs
November 16, 2026 22:06
Tyrie Vella (tyrielv)
force-pushed
the
tyrielv/sparse-index/cone-builder
branch
from
November 17, 2026 18:06
5ed6d29 to
3054c61
Compare
Tyrie Vella (tyrielv)
force-pushed
the
tyrielv/sparse-index/cone-builder
branch
from
November 18, 2026 01:13
3054c61 to
3a02c18
Compare
Tyrie Vella (tyrielv)
force-pushed
the
tyrielv/sparse-index/cone-builder
branch
from
November 18, 2026 18:04
3a02c18 to
cde072a
Compare
Add a library in GVFS.Common.Sparse that computes the sparse-checkout cone that GVFS needs for a sparse index, and writes it to info/sparse-checkout. Nothing calls the library yet. A later change uses it from the mount process. - ConeBuilder maps modified paths to cone patterns. A modified file adds parent-only patterns for its directory and each ancestor, so it does not pull a whole subtree into the index. A modified folder adds one recursive pattern. GVFS does not use "git sparse-checkout set", because "set" makes every input directory recursive. - ConePatternSet holds the cone and its case rule. It rejects a directory that is in the cone twice under that rule, and a directory that git cannot read back from a cone file. When core.ignoreCase is true, git treats "Src" and "src" as a repeated pattern and turns off cone matching. So the builder merges directories that differ only in ASCII case when core.ignoreCase is true. - ConeFileWriter writes the file in git's cone format through a temporary file and a rename. It keeps a backup for rollback. It writes nothing when the bytes do not change. It fails, and does not write, when it cannot read the existing file. A git process that reads the file keeps it open without delete sharing, so the rename can fail with ERROR_ACCESS_DENIED or ERROR_SHARING_VIOLATION. The writer then tries the replace again with git's mingw_rename delays, within a total wait that the caller sets (100 ms by default). - ConePathMatcher decides whether a path is in the cone with git's cone rules, including git's ASCII-only case folding. - SparseCheckoutPathResolver finds the per-worktree sparse-checkout file. MockFileSystem now throws FileNotFoundException when a test reads a missing file, as the real file system does. It also keeps the exact bytes when it moves or copies a file. Add unit tests for the builder, the pattern set, the comparer, the writer success and failure paths, the replace retry, the matcher, and the resolver. The unit tests start no external programs. Add a local component functional test that compares the matcher with "git sparse-checkout check-rules" with core.ignoreCase on and off. Assisted-by: Claude Opus 5.5 Signed-off-by: Tyrie Vella <[email protected]>
Tyrie Vella (tyrielv)
force-pushed
the
tyrielv/sparse-index/cone-builder
branch
from
November 18, 2026 19:03
cde072a to
64071d4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR is part of a stack of PRs into
vnext. It builds on #2193, and its base branch is the branch of #2193, so the diff shows only this layer.Important
Test with the git changes. This stack needs the git-side changes in microsoft/git#1027, #1025, #1028, #1024, and #1026. VFS for Git CI uses a released git without them, so CI skips the AutoSparseIndex functional tests (NUnit reports them as ignored). To run the tests locally, install the unsigned preview git from sparse-index-preview-1. Its release notes give the install, test, and removal steps.
Latest preview validation: run 44388006189 on
64071d42: 4 passed, 0 failed, 0 ignored.Problem and Context
A sparse index keeps one index entry for each directory that is fully outside the sparse-checkout cone. GVFS can use a sparse index only if it keeps a cone-mode
info/sparse-checkoutfile that matches the user's work. This cone must include each modified path, because git does not show a file that is in a collapsed directory.This PR adds the library that computes and writes that cone. Nothing calls it yet. A later change uses it from the mount process. Thus this PR does not change behavior. The unit tests and one local component functional test are the evidence that it is correct.
Why GVFS does not use
git sparse-checkout setIn cone mode,
git sparse-checkout setsends each input directory throughstrbuf_to_cone_patterntoinsert_recursive_pattern(builtin/sparse-checkout.c). Thus every input becomes a recursive pattern. To include one modified file,setmust include its whole parent directory recursively, with every file below it. If that directory is large, one edit adds all of its files back to the index.setalso updates the working tree, which a virtualized enlistment must not do.Git's cone format also has "parent" patterns: a directory's direct files are in the cone, but its child directories are not.
setcannot make these patterns from a file path. So GVFS writes the file itself, in the same format that git'swrite_cone_to_filewrites.Case sensitivity
GVFS stores modified paths case-insensitively on Windows, so the list can contain both
Src/a.csandsrc/b.cs. Whencore.ignoreCaseis true, git compares cone directories with ASCII-only case folding (fspathhashandfspathncmp). If the cone file names bothSrcandsrc, git printspattern '/src' is repeatedand turns off cone matching. Then the index cannot stay sparse. The cone must use the same case rule as the repository.Git folds only ASCII letters.
Äandäare different directories to git, even whencore.ignoreCaseis true.StringComparer.OrdinalIgnoreCasefolds both, so it is not correct for cone paths. If GVFS mergedÄandä, the files of one directory would be outside the cone.Directories that a cone file cannot contain
Git reads the file line by line, and it reads some escaped names differently. A directory name with a line break would add extra pattern lines. For example, a directory named
z\n!src\nbadds a!srcline, and git turns off cone matching and leavessrc/out. Git also reads/A/\*/back as/A. A cone with such a directory would leave modified files out of the cone, and git would not show them. So the library rejects these directories and does not write the file.Changes
All new types are in
GVFS.Common.Sparse.ConeBuilder.BuildFromModifiedPaths(paths, ignoreCase)maps modified paths to aConePatternSet./) adds one recursive pattern, and parent-only patterns for its ancestors.ignoreCaseis true, directories that differ only in ASCII case become one directory. Each directory keeps its ordinally smallest spelling, so the output does not depend on input order.strcmp.ArgumentException. It checks each input directory before it removes covered patterns, so an invalid directory below a recursive directory also fails.ConePatternSetis the in-memory cone: a list of parent-only directories, a list of recursive directories, and the case rule (IgnoreCase)..,.., or*segment, a line break, NUL, a backslash, or an unpaired surrogate.IsValidDirectorymakes the same check.ConeFileWriterwrites the cone file.Serializewrites git's cone format: the/*and!/*/header, a/D/and!/D/*/pair for each parent-only directory, and/D/for each recursive directory. It escapes*,?,[, and\as git'sescaped_patterndoes.WritereturnsConeFileWriteResult.Unchanged,Written, orFailed.Writewrites nothing, not even a backup. It compares bytes, because git cannot read the same text in another encoding.sparse-checkout.gvfsbackup, then writes the new content as UTF-8 to a temporary file and renames it over the target. A failure leaves the target with its previous content.Writereads the existing file instead of asking whether it exists.File.Existsreturns false when access is denied, and the write must not then replace the file without a backup. Only a missing file or directory counts as "no file".info/sparse-checkoutkeeps it open without delete sharing. While git reads the file, the rename over it fails withERROR_ACCESS_DENIEDorERROR_SHARING_VIOLATION. SoWritetries the replace again after these two errors, as git'smingw_renamedoes. The waits are 0, 1, 10, 20, and 40 ms, as in git'sretry_ask_yes_no, then 40 ms again. The caller gives the total wait time asreplaceRetryBudget, because a hook can wait less than a background task. The default is 100 ms. Zero makes one attempt only. Other errors fail at once.TryRestoreBackupcopies the backup back byte for byte for a rollback, with the same retry. The writer does not lock the file. The caller must keep other writers, including git, away between the write and a possible restore.ConePathMatcher.IsInCone(path)decides whether git would treat a path as inside the cone. It uses the case rule of theConePatternSet. It followspath_matches_pattern_listindir.c. A path with a trailing/is a directory. Git checks a directory as if it were a file named-directly inside that directory.SparseCheckoutPathResolver.GetSparseCheckoutFilePathhas a different job: it finds the location of theinfo/sparse-checkoutfile. A linked worktree has its own file in its per-worktree git dir.GVFSEnlistment.DotGitRootpoints to the shared git dir for a worktree, so it cannot be used for this file.GitPathComparer(internal) compares paths with git's rule: exact, or ASCII-only case folding.MockFileSystem.ReadAllTextandReadAllBytesnow throwFileNotFoundExceptionfor a missing file, as the real file system does. Before, they threwNullReferenceException.MockFileSystem.MoveAndOverwriteFilenow keeps the exact bytes, andMockFileSystemimplementsTryCopyToTempFileAndRename. Like the real method, it returns false for aWin32Exception.core.ignoreCase, and paths with a line break or a..segment.ConePatternSetvalidation and forGitPathComparer.TryRestoreBackup, and the rejection of a negative budget.GVFS.FunctionalTests.Tests.LocalComponents.ConePathMatcherGitTests) that comparesConePathMatcherwithgit sparse-checkout check-rules. The test builds a cone from paths that contain ASCII case variants, non-ASCII case variants, and glob characters. It writes the cone to a temporary repository and asks git about 252 file and directory paths, withcore.ignoreCaseon and off. The test asserts that git and the matcher agree on every path, that git puts every modified path in the cone, and that git prints no warning. The test uses the repository's own patterns, becausecheck-rules --rules-filewith--conereads directory names, not raw patterns. It configures only the git child process environment, and it needs no enlistment. This follows the local component test convention that Move system-dependent unit coverage to functional components #2163 added onmaster. The unit tests in this PR start no external programs.Functional tests in this layer
GVFS.FunctionalTests.Tests.LocalComponents.ConePathMatcherGitTests(added). It is not an AutoSparseIndex test. It needs only a git that hasgit sparse-checkout check-rules, so CI runs it, and it does not need the preview git.Known gaps and deliberate decisions
info/sparse-checkout, away betweenWriteand a possibleTryRestoreBackup. The writer also does not delete old backups. No follow-up planned in this library.UnauthorizedAccessException, because .NET reportsERROR_ACCESS_DENIEDthat way. So a file that is always read-only fails only after the full budget, which is 100 ms by default.ConeBuilderthrowsArgumentExceptionfor a directory that a cone file cannot contain. Windows file names cannot contain most of these characters, but NTFS allows an unpaired surrogate. The caller must treat this as "cannot use a sparse index", not as an empty cone.