Skip to content

Commit ee73630

Browse files
authored
feat: Allow config cache for microsoft/git 2.53.0.vfs.0.1+ (#2296)
This is a small modification on top of #2268 that updates the Git version check to allow using the cached list of config values when using the latest microsoft/git release. The 2.53.0.vfs.0.1 (and later) releases have microsoft/git#863 which fast-tracked the upstream Git feature that enables this behavior. Getting a GCM release with this version check will allow us to dogfood this performance feature. I expect that we'd want to release GCM with this feature and have users manually install GCM from the GitHub releases page instead of waiting for a new microsoft/git release that bundles it. I have run the test suite with this branch with microsoft/git v2.53.0.vfs.0.2 installed. I also tested by adding some thrown exceptions in the logic that only activates when the Git version check works, and that proved that the test suite _does_ cover these cases when the right Git version exists.
2 parents abfcbe0 + a34a5ce commit ee73630

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/shared/Core/GitConfiguration.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ public class GitProcessConfiguration : IGitConfiguration
324324
{
325325
private static readonly GitVersion TypeConfigMinVersion = new GitVersion(2, 18, 0);
326326
private static readonly GitVersion ConfigListTypeMinVersion = new GitVersion(2, 54, 0);
327+
private static readonly GitVersion ConfigListTypeMinVfsBase = new GitVersion(2, 53, 0);
328+
private static readonly GitVersion ConfigListTypeMinVfsSuffix = new GitVersion(0, 1);
327329

328330
private readonly ITrace _trace;
329331
private readonly GitProcess _git;
@@ -342,17 +344,43 @@ internal GitProcessConfiguration(ITrace trace, GitProcess git, bool useCache)
342344
_trace = trace;
343345
_git = git;
344346

345-
// 'git config list --type=<X>' requires Git 2.54.0+
346-
if (useCache && git.Version < ConfigListTypeMinVersion)
347+
// 'git config list --type=<X>' requires Git 2.54.0+,
348+
// or microsoft/git fork 2.53.0.vfs.0.1+
349+
if (useCache && !SupportsConfigListType(git))
347350
{
348-
trace.WriteLine($"Git version {git.Version} is below {ConfigListTypeMinVersion}; config cache disabled");
351+
trace.WriteLine($"Git version {git.Version.OriginalString} does not support 'git config list --type'; config cache disabled");
349352
useCache = false;
350353
}
351354

352355
_useCache = useCache;
353356
_cache = useCache ? new Dictionary<GitConfigurationType, ConfigCache>() : null;
354357
}
355358

359+
private static bool SupportsConfigListType(GitProcess git)
360+
{
361+
if (git.Version >= ConfigListTypeMinVersion)
362+
return true;
363+
364+
// The microsoft/git fork fast-tracked the fix into 2.53.0.vfs.0.1.
365+
// Version strings like "2.53.0.vfs.0.1" parse as [2,53,0] because
366+
// GitVersion stops at the non-integer "vfs" component, so we check
367+
// the original string for the ".vfs." marker and parse the suffix.
368+
string versionStr = git.Version.OriginalString;
369+
if (versionStr != null)
370+
{
371+
int vfsIdx = versionStr.IndexOf(".vfs.");
372+
if (vfsIdx >= 0)
373+
{
374+
var baseVersion = new GitVersion(versionStr.Substring(0, vfsIdx));
375+
var vfsSuffix = new GitVersion(versionStr.Substring(vfsIdx + 5));
376+
return baseVersion >= ConfigListTypeMinVfsBase
377+
&& vfsSuffix >= ConfigListTypeMinVfsSuffix;
378+
}
379+
}
380+
381+
return false;
382+
}
383+
356384
private void EnsureCacheLoaded(GitConfigurationType type)
357385
{
358386
ConfigCache cache;

0 commit comments

Comments
 (0)