Skip to content

Commit 2ad18e8

Browse files
authored
Merge pull request microsoft#1849 from tyrielv/async-prefetch
Prefetch in background when cloning if pack indexes are not trusted
2 parents 26b88aa + fb77a47 commit 2ad18e8

3 files changed

Lines changed: 46 additions & 18 deletions

File tree

GVFS/GVFS.Common/Enlistment.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,18 @@ public virtual GitProcess CreateGitProcess()
109109
{
110110
return new GitProcess(this);
111111
}
112+
113+
public bool GetTrustPackIndexesConfig()
114+
{
115+
var gitProcess = this.CreateGitProcess();
116+
bool trustPackIndexes = true;
117+
if (gitProcess.TryGetFromConfig(GVFSConstants.GitConfig.TrustPackIndexes, forceOutsideEnlistment: false, out var valueString)
118+
&& bool.TryParse(valueString, out var trustPackIndexesConfig))
119+
{
120+
trustPackIndexes = trustPackIndexesConfig;
121+
}
122+
123+
return trustPackIndexes;
124+
}
112125
}
113126
}

GVFS/GVFS.Common/Git/GitObjects.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,7 @@ public virtual bool TryDownloadPrefetchPacks(GitProcess gitProcess, long latestT
135135
* pack file and an index file that do not match.
136136
* Eventually we will make this the default, but it has a high performance cost for the first prefetch after
137137
* cloning a large repository, so it must be explicitly enabled for now. */
138-
bool trustPackIndexes = true;
139-
if (gitProcess.TryGetFromConfig(GVFSConstants.GitConfig.TrustPackIndexes, forceOutsideEnlistment: false, out var valueString)
140-
&& bool.TryParse(valueString, out var trustPackIndexesConfig))
141-
{
142-
trustPackIndexes = trustPackIndexesConfig;
143-
}
138+
bool trustPackIndexes = this.Enlistment.GetTrustPackIndexesConfig();
144139
metadata.Add("trustPackIndexes", trustPackIndexes);
145140

146141
long requestId = HttpRequestor.GetNewRequestId();

GVFS/GVFS/CommandLine/CloneVerb.cs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,40 @@ public override void Execute()
215215
{
216216
if (!this.NoPrefetch)
217217
{
218-
ReturnCode result = this.Execute<PrefetchVerb>(
219-
enlistment,
220-
verb =>
218+
bool trustPackIndexes = enlistment.GetTrustPackIndexesConfig();
219+
/* If pack indexes are not trusted, the prefetch can take a long time.
220+
* We will run the prefetch command in the background.
221+
*/
222+
if (trustPackIndexes)
223+
{
224+
ReturnCode result = this.Execute<PrefetchVerb>(
225+
enlistment,
226+
verb =>
227+
{
228+
verb.Commits = true;
229+
verb.SkipVersionCheck = true;
230+
verb.ResolvedCacheServer = cacheServer;
231+
verb.ServerGVFSConfig = serverGVFSConfig;
232+
});
233+
234+
if (result != ReturnCode.Success)
221235
{
222-
verb.Commits = true;
223-
verb.SkipVersionCheck = true;
224-
verb.ResolvedCacheServer = cacheServer;
225-
verb.ServerGVFSConfig = serverGVFSConfig;
226-
});
236+
this.Output.WriteLine("\r\nError during prefetch @ {0}", fullEnlistmentRootPathParameter);
237+
exitCode = (int)result;
238+
}
239+
}
227240

228-
if (result != ReturnCode.Success)
241+
else
229242
{
230-
this.Output.WriteLine("\r\nError during prefetch @ {0}", fullEnlistmentRootPathParameter);
231-
exitCode = (int)result;
243+
Process.Start(new ProcessStartInfo(
244+
fileName: "gvfs",
245+
arguments: "prefetch --commits")
246+
{
247+
UseShellExecute = true,
248+
WindowStyle = ProcessWindowStyle.Hidden,
249+
WorkingDirectory = enlistment.EnlistmentRoot
250+
});
251+
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");
232252
}
233253
}
234254

@@ -247,7 +267,7 @@ public override void Execute()
247267
verb.SkipVersionCheck = true;
248268
verb.ResolvedCacheServer = cacheServer;
249269
verb.DownloadedGVFSConfig = serverGVFSConfig;
250-
});
270+
});
251271
}
252272
}
253273
else

0 commit comments

Comments
 (0)