8000 Update to use modern version of LibGit2Sharp and use indent heuristic when diffing by jcansdale · Pull Request #2142 · github/VisualStudio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Update to use modern version of LibGit2Sharp and use indent heuristic when diffing #2142

Merged
merged 26 commits into from
Mar 26, 2019
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e8d9527
Update to be compatible with LigGit2Sharp 0.26
jcansdale Dec 18, 2018
4658122
Fix tests that use LibGit2Sharp
jcansdale Dec 18, 2018
b0c037b
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Dec 18, 2018
8b6a488
Remove obsolete IQueryableCommitLog.QueryBy imple
jcansdale Dec 18, 2018
32c4aac
Update to use LibGit2Sharp 0.26.0-preview-0080
jcansdale Dec 18, 2018
bbc0504
Commit[] no longer accepts \ in path
jcansdale Dec 19, 2018
128cfbe
Remove unused defaultOriginName field
jcansdale Jan 7, 2019
057844a
Enable IndentHeuristic when comparing
jcansdale Jan 8, 2019
62ccc9b
Move Compare and CompareWith to IGitService
jcansdale Jan 8, 2019
e6ebab6
Add failing Indent_Heuristic_Is_Enabled test
jcansdale Jan 8, 2019
e0eb92c
Add tests for GitService.CompareWith
jcansdale Jan 8, 2019
c222de2
Enable IndentHeuristic and make tests pass
jcansdale Jan 8, 2019
d95149d
Move IGitClient.Compare method to IGitService
jcansdale Jan 8, 2019
df677af
Add test for Compare that returns TreeChanges
jcansdale Jan 8, 2019
ca6de27
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Jan 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update to be compatible with LigGit2Sharp 0.26
Stop using obsolete LigGit2Sharp methods.
Also changed from using Task.Factory.StartNew to Task.Run.
  • Loading branch information
jcansdale committed Dec 18, 2018
commit e8d9527cdd2a0019e0889783a893a3482f3c45ad
82 changes: 42 additions & 40 deletions src/GitHub.App/Services/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ public GitClient(IGitHubCredentialProvider credentialProvider, IGitService gitSe
public Task Pull(IRepository repository)
{
Guard.ArgumentNotNull(repository, nameof(repository));
return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var signature = repository.Config.BuildSignature(DateTimeOffset.UtcNow);
#pragma warning disable 0618 // TODO: Replace `Network.Pull` with `Commands.Pull`.
repository.Network.Pull(signature, pullOptions);
#pragma warning restore 0618
if (repository is Repository repo)
{
LibGit2Sharp.Commands.Pull(repo, signature, pullOptions);
}
else
{
log.Error("Couldn't pull because {Variable} isn't an instance of {Type}", nameof(repository), typeof(Repository));
}
});
}

Expand All @@ -59,7 +64,7 @@ public Task Push(IRepository repository, string branchName, string remoteName)
Guard.ArgumentNotEmptyString(branchName, nameof(branchName));
Guard.ArgumentNotEmptyString(remoteName, nameof(remoteName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
if (repository.Head?.Commits != null && repository.Head.Commits.Any())
{
Expand All @@ -75,14 +80,11 @@ public Task Fetch(IRepository repository, string remoteName)
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(remoteName, nameof(remoteName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
try
{
var remote = repository.Network.Remotes[remoteName];
#pragma warning disable 0618 // TODO: Replace `Network.Fetch` with `Commands.Fetch`.
repository.Network.Fetch(remote, fetchOptions);
#pragma warning restore 0618
repository.Network.Fetch(remoteName, new[] { "+refs/heads/*:refs/remotes/origin/*" }, fetchOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess things have changed since this warning was disabled...

}
catch (Exception ex)
{
Expand All @@ -104,7 +106,7 @@ public Task Fetch(IRepository repo, UriString cloneUrl, params string[] refspecs
}
}

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
try
{
Expand All @@ -114,17 +116,15 @@ public Task Fetch(IRepository repo, UriString cloneUrl, params string[] refspecs
var removeRemote = false;
if (repo.Network.Remotes[remoteName] != null)
{
// If a remote with this neme already exists, use a unique name and remove remote afterwards
// If a remote with this name already exists, use a unique name and remove remote afterwards
remoteName = cloneUrl.Owner + "-" + Guid.NewGuid();
removeRemote = true;
}

var remote = repo.Network.Remotes.Add(remoteName, remoteUri.ToString());
repo.Network.Remotes.Add(remoteName, remoteUri.ToString());
try
{
#pragma warning disable 0618 // TODO: Replace `Network.Fetch` with `Commands.Fetch`.
repo.Network.Fetch(remote, refspecs, fetchOptions);
#pragma warning restore 0618
repo.Network.Fetch(remoteName, refspecs, fetchOptions);
}
finally
{
Expand All @@ -149,14 +149,11 @@ public Task Fetch(IRepository repository, string remoteName, params string[] ref
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(remoteName, nameof(remoteName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
try
{
var remote = repository.Network.Remotes[remoteName];
#pragma warning disable 0618 // TODO: Replace `Network.Fetch` with `Commands.Fetch`.
repository.Network.Fetch(remote, refspecs, fetchOptions);
#pragma warning restore 0618
repository.Network.Fetch(remoteName, refspecs, fetchOptions);
}
catch (Exception ex)
{
Expand All @@ -173,11 +170,16 @@ public Task Checkout(IRepository repository, string branchName)
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(branchName, nameof(branchName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
#pragma warning disable 0618 // TODO: Replace `IRepository.Checkout` with `Commands.Checkout`.
repository.Checkout(branchName);
#pragma warning restore 0618
if (repository is Repository repo)
{
LibGit2Sharp.Commands.Checkout(repo, branchName);
}
else
{
log.Error("Couldn't checkout because {Variable} isn't an instance of {Type}", nameof(repository), typeof(Repository));
}
});
}

Expand All @@ -186,7 +188,7 @@ public Task CreateBranch(IRepository repository, string branchName)
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(branchName, nameof(branchName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
repository.CreateBranch(branchName);
});
Expand All @@ -202,7 +204,7 @@ public Task<TreeChanges> Compare(
Guard.ArgumentNotEmptyString(sha1, nameof(sha1));
Guard.ArgumentNotEmptyString(sha2, nameof(sha2));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var options = new CompareOptions
{
Expand Down Expand Up @@ -234,7 +236,7 @@ public Task<Patch> Compare(
Guard.ArgumentNotEmptyString(sha2, nameof(sha2));
Guard.ArgumentNotEmptyString(path, nameof(path));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var commit1 = repository.Lookup<Commit>(sha1);
var commit2 = repository.Lookup<Commit>(sha2);
Expand All @@ -260,7 +262,7 @@ public Task<ContentChanges> CompareWith(IRepository repository, string sha1, str
Guard.ArgumentNotEmptyString(sha2, nameof(sha1));
Guard.ArgumentNotEmptyString(path, nameof(path));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var commit1 = repository.Lookup<Commit>(sha1);
var commit2 = repository.Lookup<Commit>(sha2);
Expand All @@ -287,7 +289,7 @@ public Task<T> GetConfig<T>(IRepository repository, string key)
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(key, nameof(key));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var result = repository.Config.Get<T>(key);
return result != null ? result.Value : default(T);
Expand All @@ -300,7 +302,7 @@ public Task SetConfig(IRepository repository, string key, string value)
Guard.ArgumentNotEmptyString(key, nameof(key));
Guard.ArgumentNotEmptyString(value, nameof(value));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
repository.Config.Set(key, value);
});
Expand All @@ -311,7 +313,7 @@ public Task SetRemote(IRepository repository, string remoteName, Uri url)
Gu EDBE ard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(remoteName, nameof(remoteName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
repository.Config.Set("remote." + remoteName + ".url", url.ToString());
repository.Config.Set("remote." + remoteName + ".fetch", "+refs/heads/*:refs/remotes/" + remoteName + "/*");
Expand All @@ -324,7 +326,7 @@ public Task SetTrackingBranch(IRepository repository, string branchName, string
Guard.ArgumentNotEmptyString(branchName, nameof(branchName));
Guard.ArgumentNotEmptyString(remoteName, nameof(remoteName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var remoteBranchName = IsCanonical(remoteName) ? remoteName : "refs/remotes/" + remoteName + "/" + branchName;
var remoteBranch = repository.Branches[remoteBranchName];
Expand All @@ -342,7 +344,7 @@ public Task UnsetConfig(IRepository repository, string key)
{
Guard.ArgumentNotEmptyString(key, nameof(key));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
repository.Config.Unset(key);
});
Expand All @@ -353,7 +355,7 @@ public Task<Remote> GetHttpRemote(IRepository repo, string remote)
Guard.ArgumentNotNull(repo, nameof(repo));
Guard.ArgumentNotEmptyString(remote, nameof(remote));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var uri = gitService.GetRemoteUri(repo, remote);
var remoteName = uri.IsHypertextTransferProtocol ? remote : remote + "-http";
Expand All @@ -370,7 +372,7 @@ public Task<string> ExtractFile(IRepository repository, string commitSha, string
Guard.ArgumentNotEmptyString(commitSha, nameof(commitSha));
Guard.ArgumentNotEmptyString(fileName, nameof(fileName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var commit = repository.Lookup<Commit>(commitSha);
if (commit == null)
Expand All @@ -389,7 +391,7 @@ public Task<byte[]> ExtractFileBinary(IRepository repository, string commitSha,
Guard.ArgumentNotEmptyString(commitSha, nameof(commitSha));
Guard.ArgumentNotEmptyString(fileName, nameof(fileName));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var commit = repository.Lookup<Commit>(commitSha);
if (commit == null)
Expand Down Expand Up @@ -418,7 +420,7 @@ public Task<bool> IsModified(IRepository repository, string path, byte[] content
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(path, nameof(path));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
if (repository.RetrieveStatus(path) == FileStatus.Unaltered)
{
Expand Down Expand Up @@ -486,7 +488,7 @@ public Task<bool> IsHeadPushed(IRepository repo)
{
Guard.ArgumentNotNull(repo, nameof(repo));

return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
return repo.Head.TrackingDetails.AheadBy == 0;
});
Expand All @@ -498,7 +500,7 @@ public Task<IReadOnlyList<CommitMessage>> GetMessagesForUniqueCommits(
string compareBranch,
int maxCommits)
{
return Task.Factory.StartNew(() =>
return Task.Run(() =>
{
var baseCommit = repo.Lookup<Commit>(baseBranch);
var compareCommit = repo.Lookup<Commit>(compareBranch);
Expand Down
0