Skip to content

Commit

Permalink
Merge pull request #246: Update Git to include prefetch logic
Browse files Browse the repository at this point in the history
See microsoft/git#223 for details.

Resolves #141.

* [x] Call `git gvfs-helper prefetch` in `scalar maintenance fetch-commits-and-trees`
* [x] Delete existing prefetch logic in the C# layer.
  • Loading branch information
derrickstolee authored Dec 17, 2019
2 parents d87a341 + 47b898d commit 0771036
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 1,252 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<!-- Version information -->
<ScalarVersion>0.2.173.2</ScalarVersion>
<GitPackageVersion>2.20191211.2</GitPackageVersion>
<GitPackageVersion>2.20191217.2</GitPackageVersion>
<WatchmanPackageUrl>https://github.com/facebook/watchman/suites/307436006/artifacts/304557</WatchmanPackageUrl>
<GcmCoreOSXPackageUrl>https://github.com/microsoft/Git-Credential-Manager-Core/releases/download/v2.0.79-beta/gcmcore-osx-2.0.79.64449.pkg</GcmCoreOSXPackageUrl>

Expand Down
661 changes: 0 additions & 661 deletions Scalar.Common/Git/GitObjects.cs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Scalar.Common/Git/GitProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ public Result GvfsHelperDownloadCommit(string commitId)
});
}

public Result GvfsHelperPrefetch()
{
return this.InvokeGitInWorkingDirectoryRoot("gvfs-helper prefetch", fetchMissingObjects: false);
}

public Result Status(bool allowObjectDownloads, bool useStatusCache, bool showUntracked = false)
{
string command = "status";
Expand Down
87 changes: 0 additions & 87 deletions Scalar.Common/Http/GitObjectsHttpRequestor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;

namespace Scalar.Common.Http
Expand Down Expand Up @@ -58,92 +57,6 @@ public virtual GitRefs QueryInfoRefs(string branch)
return output.Result;
}

public virtual RetryWrapper<GitObjectTaskResult>.InvocationResult TrySendProtocolRequest(
long requestId,
Func<int, GitEndPointResponseData, RetryWrapper<GitObjectTaskResult>.CallbackResult> onSuccess,
Action<RetryWrapper<GitObjectTaskResult>.ErrorEventArgs> onFailure,
HttpMethod method,
Uri endPoint,
CancellationToken cancellationToken,
string requestBody = null,
MediaTypeWithQualityHeaderValue acceptType = null,
bool retryOnFailure = true)
{
return this.TrySendProtocolRequest(
requestId,
onSuccess,
onFailure,
method,
endPoint,
cancellationToken,
() => requestBody,
acceptType,
retryOnFailure);
}

public virtual RetryWrapper<GitObjectTaskResult>.InvocationResult TrySendProtocolRequest(
long requestId,
Func<int, GitEndPointResponseData, RetryWrapper<GitObjectTaskResult>.CallbackResult> onSuccess,
Action<RetryWrapper<GitObjectTaskResult>.ErrorEventArgs> onFailure,
HttpMethod method,
Uri endPoint,
CancellationToken cancellationToken,
Func<string> requestBodyGenerator,
MediaTypeWithQualityHeaderValue acceptType = null,
bool retryOnFailure = true)
{
return this.TrySendProtocolRequest(
requestId,
onSuccess,
onFailure,
method,
() => endPoint,
requestBodyGenerator,
cancellationToken,
acceptType,
retryOnFailure);
}

public virtual RetryWrapper<GitObjectTaskResult>.InvocationResult TrySendProtocolRequest(
long requestId,
Func<int, GitEndPointResponseData, RetryWrapper<GitObjectTaskResult>.CallbackResult> onSuccess,
Action<RetryWrapper<GitObjectTaskResult>.ErrorEventArgs> onFailure,
HttpMethod method,
Func<Uri> endPointGenerator,
Func<string> requestBodyGenerator,
CancellationToken cancellationToken,
MediaTypeWithQualityHeaderValue acceptType = null,
bool retryOnFailure = true)
{
RetryWrapper<GitObjectTaskResult> retrier = new RetryWrapper<GitObjectTaskResult>(
retryOnFailure ? this.RetryConfig.MaxAttempts : 1,
cancellationToken);
if (onFailure != null)
{
retrier.OnFailure += onFailure;
}

return retrier.Invoke(
tryCount =>
{
using (GitEndPointResponseData response = this.SendRequest(
requestId,
endPointGenerator(),
method,
requestBodyGenerator(),
cancellationToken,
acceptType))
{
if (response.HasErrors)
{
return new RetryWrapper<GitObjectTaskResult>.CallbackResult(response.Error, response.ShouldRetry, new GitObjectTaskResult(response.StatusCode));
}
return onSuccess(tryCount, response);
}
});
}

public class GitObjectTaskResult
{
public GitObjectTaskResult(bool success)
Expand Down
13 changes: 4 additions & 9 deletions Scalar.Common/Maintenance/FetchCommitsAndTreesStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public bool TryFetchCommitsAndTrees(out string error, GitProcess gitProcess = nu
gitProcess = new GitProcess(this.Context.Enlistment);
}

List<string> packIndexes;

// We take our own lock here to keep background and foreground fetches
// (i.e. a user running 'scalar maintenance --fetch-commits-and-trees')
// from running at the same time.
Expand All @@ -46,25 +44,22 @@ public bool TryFetchCommitsAndTrees(out string error, GitProcess gitProcess = nu
Path.Combine(this.Context.Enlistment.GitPackRoot, FetchCommitsAndTreesLock)))
{
WaitUntilLockIsAcquired(this.Context.Tracer, fetchLock);
long maxGoodTimeStamp;

this.GitObjects.DeleteStaleTempPrefetchPackAndIdxs();
this.GitObjects.DeleteTemporaryFiles();

if (!this.TryGetMaxGoodPrefetchPackTimestamp(out maxGoodTimeStamp, out error))
{
return false;
}
GitProcess.Result result = gitProcess.GvfsHelperPrefetch();

if (!this.GitObjects.TryDownloadPrefetchPacks(gitProcess, maxGoodTimeStamp, out packIndexes))
if (result.ExitCodeIsFailure)
{
error = "Failed to download prefetch packs";
error = result.Errors;
return false;
}

this.UpdateKeepPacks();
}

error = null;
return true;
}

Expand Down
124 changes: 0 additions & 124 deletions Scalar.Common/NetworkStreams/PrefetchPacksDeserializer.cs

This file was deleted.

42 changes: 0 additions & 42 deletions Scalar.Common/Paths.Shared.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
using System;
using System.IO;
using System.Linq;

namespace Scalar.Common
{
public static class Paths
{
public static string GetRoot(string startingDirectory, string rootName)
{
startingDirectory = startingDirectory.TrimEnd(Path.DirectorySeparatorChar);
DirectoryInfo dirInfo;

try
{
dirInfo = new DirectoryInfo(startingDirectory);
}
catch (Exception)
{
return null;
}

while (dirInfo != null)
{
if (dirInfo.Exists)
{
DirectoryInfo[] dotScalarDirs = new DirectoryInfo[0];

try
{
dotScalarDirs = dirInfo.GetDirectories(rootName);
}
catch (IOException)
{
}

if (dotScalarDirs.Count() == 1)
{
return dirInfo.FullName;
}
}

dirInfo = dirInfo.Parent;
}

return null;
}

public static string ConvertPathToGitFormat(string path)
{
return path.Replace(Path.DirectorySeparatorChar, ScalarConstants.GitPathSeparator);
Expand Down
Loading

0 comments on commit 0771036

Please sign in to comment.