Share transient libgit2 config lookup helper - #2066
Open
tyrielv wants to merge 1 commit into
Open
Conversation
tyrielv
marked this pull request as ready for review
August 7, 2026 22:47
Add LibGit2Repo.GetConfigBoolOrDefault(...) (instance + static overloads) for one-off boolean config reads, replacing scattered short-lived LibGit2Repo/LibGit2RepoInvoker usage at 4 call sites: - GVFS/CommandLine/CloneVerb.cs (gvfs.trust-pack-indexes) - GVFS.Hooks/Program.cs (gvfs.show-hydration-status) - GVFS.Mount/InProcessMount.cs (gvfs.background-cache-auth) - GVFS/CommandLine/PrefetchVerb.cs (gvfs.prefetch-offload) LibGit2RepoInvoker.InitializeSharedRepo() intentionally forces an object-store probe so long-lived/shared callers can amortize object-store load costs. That is wasted work for one-off config reads that immediately dispose the repo. The helper methods live directly on LibGit2Repo rather than a separate extension class, matching the repo.GetConfigBoolOrDefault(name, default) convention already documented in AGENTS.md, and avoiding unnecessary indirection for a class the team owns in the same assembly. Both methods fall back to defaultValue and log a RelatedWarning on any failure, matching the "default on any failure" contract each call site previously implemented independently. Added a protected LibGit2Repo(ITracer tracer) constructor to support test doubles that inject a mock tracer without opening a real repo. Surveyed master for other short-lived config-only LibGit2Repo/ LibGit2RepoInvoker usage; PrefetchStep.cs, GitStatusCache.cs, and GitRepo.cs were left alone because they use shared/long-lived repo access, not the transient anti-pattern this change addresses. Reviewed with an internal 6-lens review-swarm pass (correctness, security, design, tests, async-parallelism, risk-rollout); addressed all actionable findings: - Widened the shared helper's exception handling to a plain catch (Exception), restoring the "default on any failure" guarantee InProcessMount/PrefetchVerb relied on before this refactor. - Fixed a double-RelatedWarning log on the repo-open-failure path. - Replaced a hardcoded, non-portable "Z:\..." path in a unit test with a GUID-suffixed temp path. - Added test coverage for the unset-key (null-coalescing) branch and the InvalidDataException catch arm. - Simplified the parameterless constructor to delegate to the tracer-accepting one. Full unit test suite: 891 passed, 0 failed, 11 skipped (pre-existing, unrelated). Assisted-by: Claude Opus 4.8 Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
tyrielv
force-pushed
the
tyrielv/shared-libgit2-config-lookup
branch
from
August 7, 2026 22:52
970ee18 to
5471e46
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 now a single commit (5471e46), squashed for a clean review/merge history.
Summary
LibGit2Repo.GetConfigBoolOrDefault(...)(instance + static overloads) for one-off boolean config reads, replacing scattered short-livedLibGit2Repo/LibGit2RepoInvokerusage at 4 call sitesLibGit2RepoInvoker's object-store preload for reads that only need a single config value and immediately dispose the repoMotivation
LibGit2RepoInvoker.InitializeSharedRepo()intentionally forces an object-store probe so long-lived/shared callers can amortize object-store load costs. That is wasted work for one-off config reads that immediately dispose the repo. This change centralizes the short-lived config-read pattern behind two methods.Design
The helper methods live directly on
LibGit2Reporather than a separate extension class — this matches therepo.GetConfigBoolOrDefault(name, default)convention already documented inAGENTS.md, and avoids unnecessary indirection for a class the team owns in the same assembly:public bool GetConfigBoolOrDefault(string key, bool defaultValue)— instance method, reads from an already-open repo usingthis.Tracer.public static bool GetConfigBoolOrDefault(ITracer tracer, string repoPath, string key, bool defaultValue)— opens a transientLibGit2Repo, delegates to the instance method, and disposes it.Both fall back to
defaultValueand log aRelatedWarningon any failure (matching the "default on any failure" contract each call site previously implemented independently).Also added a
protected LibGit2Repo(ITracer tracer)constructor purely to support test doubles that need to inject a mock tracer without opening a real repo.Refactored call sites
GVFS/GVFS/CommandLine/CloneVerb.cs—gvfs.trust-pack-indexes(only read when clone succeeded)GVFS/GVFS.Hooks/Program.cs—gvfs.show-hydration-status(runs on every git hook invocation)GVFS/GVFS.Mount/InProcessMount.cs—gvfs.background-cache-authGVFS/GVFS/CommandLine/PrefetchVerb.cs—gvfs.prefetch-offloadGVFS/GVFS.Hooks/GVFS.Hooks.csproj— updated to drop the now-removed extension-class source fileSurvey notes / intentionally left alone
Surveyed
masterfor short-lived config-onlyLibGit2Repo/LibGit2RepoInvokerusage. These were left alone because they are shared/long-lived repo access, not the transient anti-pattern this PR addresses:GVFS/GVFS.Common/Maintenance/PrefetchStep.csGVFS/GVFS.Common/GitStatusCache.csGVFS/GVFS.Common/Git/GitRepo.csStacked PR
#2065 ("Fix NullReferenceException when cloning into a non-empty directory") is rebased on top of this branch and depends on the
LibGit2Repo.GetConfigBoolOrDefaulthelper added here. This PR should merge first.Review
Reviewed with an internal 6-lens review-swarm pass (correctness, security, design, tests, async-parallelism, risk-rollout). All actionable findings were addressed:
catch (Exception), restoring the "default on any failure" guaranteeInProcessMount/PrefetchVerbrelied on before this refactor.RelatedWarninglog on the repo-open-failure path.Z:\...path in a unit test with a GUID-suffixed temp path.null-coalescing) branch and theInvalidDataExceptioncatch arm.Validation
dotnet build GVFS\GVFS.UnitTests\GVFS.UnitTests.csproj -c Debugout\GVFS.UnitTests\bin\Debug\net10.0-windows10.0.17763.0\win-x64\GVFS.UnitTests.exe