Skip to content

Download commit pack even when commit exists as loose object#1995

Open
tyrielv wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/skip-clone-commit-download
Open

Download commit pack even when commit exists as loose object#1995
tyrielv wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/skip-clone-commit-download

Conversation

@tyrielv
Copy link
Copy Markdown
Contributor

@tyrielv tyrielv commented Jun 1, 2026

Summary

Fixes the worst-case clone performance when a commit exists as a loose object in the shared cache (e.g., from a prior git show or git log in a mounted enlistment).

Before: TryDownloadCommit checks CommitAndRootTreeExists - if the commit and root tree exist (even as loose objects), the commit+trees pack download is skipped. git checkout -f then fails with unable to read tree because subtrees are missing, triggering an expensive fallback: re-download the pack + retry checkout. On a large repo this wastes ~60 seconds.

After: TryDownloadCommit additionally checks whether the commit is a loose object via the new GitRepo.LooseObjectExists() method. If the commit is loose, the pack is downloaded proactively. If the commit is in a pack file, trees are included by the GVFS protocol, so the download is safely skipped.

Changes

  • GVFSVerb.cs: When CommitAndRootTreeExists returns true, check LooseObjectExists before skipping download
  • GitRepo.cs: New LooseObjectExists method - fast filesystem check for loose object files

Performance Impact (large repo)

Scenario Before After
Commit in pack Skip download (22s saved) Same
Commit is loose object Skip -> checkout fails -> fallback (~60s wasted) Download proactively (~60s saved)
Commit not in cache Download pack Same

When TryDownloadCommit finds the commit via CommitAndRootTreeExists,
it now checks whether the commit is a loose object. Loose commits
(e.g., from a prior 'git show' or 'git log' in a mounted enlistment)
do not include reachable trees. Skipping the download in this case
causes 'git checkout -f' to fail with 'unable to read tree', followed
by an expensive fallback that re-downloads and retries checkout.

If the commit is in a pack file (prefetch or commit pack), trees are
included by the GVFS protocol, so the download can safely be skipped.

Added GitRepo.LooseObjectExists() to check whether a SHA exists as a
loose object file in the shared cache or local object store.

Assisted-by: Claude Opus 4.6
Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
@tyrielv tyrielv force-pushed the tyrielv/skip-clone-commit-download branch from 474a50d to 1784125 Compare June 2, 2026 21:05
@tyrielv tyrielv changed the title Skip redundant commit pack download during clone when prefetch packs exist Download commit pack even when commit exists as loose object Jun 2, 2026
@tyrielv tyrielv marked this pull request as ready for review June 2, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant