diff --git a/GVFS/GVFS.Common/Enlistment.cs b/GVFS/GVFS.Common/Enlistment.cs index 3f061257f..090a81c9e 100644 --- a/GVFS/GVFS.Common/Enlistment.cs +++ b/GVFS/GVFS.Common/Enlistment.cs @@ -109,5 +109,18 @@ public virtual GitProcess CreateGitProcess() { return new GitProcess(this); } + + public bool GetTrustPackIndexesConfig() + { + var gitProcess = this.CreateGitProcess(); + bool trustPackIndexes = true; + if (gitProcess.TryGetFromConfig(GVFSConstants.GitConfig.TrustPackIndexes, forceOutsideEnlistment: false, out var valueString) + && bool.TryParse(valueString, out var trustPackIndexesConfig)) + { + trustPackIndexes = trustPackIndexesConfig; + } + + return trustPackIndexes; + } } } diff --git a/GVFS/GVFS.Common/Git/GitObjects.cs b/GVFS/GVFS.Common/Git/GitObjects.cs index 6614bd573..e21d4a1d1 100644 --- a/GVFS/GVFS.Common/Git/GitObjects.cs +++ b/GVFS/GVFS.Common/Git/GitObjects.cs @@ -135,12 +135,7 @@ public virtual bool TryDownloadPrefetchPacks(GitProcess gitProcess, long latestT * pack file and an index file that do not match. * Eventually we will make this the default, but it has a high performance cost for the first prefetch after * cloning a large repository, so it must be explicitly enabled for now. */ - bool trustPackIndexes = true; - if (gitProcess.TryGetFromConfig(GVFSConstants.GitConfig.TrustPackIndexes, forceOutsideEnlistment: false, out var valueString) - && bool.TryParse(valueString, out var trustPackIndexesConfig)) - { - trustPackIndexes = trustPackIndexesConfig; - } + bool trustPackIndexes = this.Enlistment.GetTrustPackIndexesConfig(); metadata.Add("trustPackIndexes", trustPackIndexes); long requestId = HttpRequestor.GetNewRequestId(); diff --git a/GVFS/GVFS/CommandLine/CloneVerb.cs b/GVFS/GVFS/CommandLine/CloneVerb.cs index 47d7d3f97..e81030837 100644 --- a/GVFS/GVFS/CommandLine/CloneVerb.cs +++ b/GVFS/GVFS/CommandLine/CloneVerb.cs @@ -215,20 +215,40 @@ public override void Execute() { if (!this.NoPrefetch) { - ReturnCode result = this.Execute( - enlistment, - verb => + bool trustPackIndexes = enlistment.GetTrustPackIndexesConfig(); + /* If pack indexes are not trusted, the prefetch can take a long time. + * We will run the prefetch command in the background. + */ + if (trustPackIndexes) + { + ReturnCode result = this.Execute( + enlistment, + verb => + { + verb.Commits = true; + verb.SkipVersionCheck = true; + verb.ResolvedCacheServer = cacheServer; + verb.ServerGVFSConfig = serverGVFSConfig; + }); + + if (result != ReturnCode.Success) { - verb.Commits = true; - verb.SkipVersionCheck = true; - verb.ResolvedCacheServer = cacheServer; - verb.ServerGVFSConfig = serverGVFSConfig; - }); + this.Output.WriteLine("\r\nError during prefetch @ {0}", fullEnlistmentRootPathParameter); + exitCode = (int)result; + } + } - if (result != ReturnCode.Success) + else { - this.Output.WriteLine("\r\nError during prefetch @ {0}", fullEnlistmentRootPathParameter); - exitCode = (int)result; + Process.Start(new ProcessStartInfo( + fileName: "gvfs", + arguments: "prefetch --commits") + { + UseShellExecute = true, + WindowStyle = ProcessWindowStyle.Hidden, + WorkingDirectory = enlistment.EnlistmentRoot + }); + this.Output.WriteLine("\r\nPrefetch of commit graph has been started as a background process. Git operations involving history may be slower until prefetch has completed.\r\n"); } } @@ -247,7 +267,7 @@ public override void Execute() verb.SkipVersionCheck = true; verb.ResolvedCacheServer = cacheServer; verb.DownloadedGVFSConfig = serverGVFSConfig; - }); + }); } } else