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
Show file tree
Hide file tree
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
b348527
Add failing test for GitService.Compare
jcansdale Jan 9, 2019
cc43965
Change to use / separator for Git path
jcansdale Jan 9, 2019
7362f56
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Jan 9, 2019
f685a22
Throw ArgumentException if path contains \
jcansdale Jan 9, 2019
346bfe1
Factor out Guard.ArgumentIsGitPath
jcansdale Jan 9, 2019
7d87a40
Add Guard.ArgumentIsGitPath to appropriate methods
jcansdale Jan 9, 2019
7006897
Fix issue where a Windows path is being used
jcansdale Jan 9, 2019
8c5d1f7
Add guards to HasChangesInWorkingDirectory
jcansdale Jan 9, 2019
6fa16e8
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Mar 19, 2019
f9c9cce
Updatre to use LibGit2Sharp 0.26.0 final
jcansdale Mar 19, 2019
f14b646
Merge branch 'master' into fixes/1469-indent-heuristic
jcansdale Mar 22, 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
Prev Previous commit
Next Next commit
Move IGitClient.Compare method to IGitService
  • Loading branch information
jcansdale committed Jan 8, 2019
commit d95149d57f40a195aaee494e3e0680cbdc9f8546
1 change: 1 addition & 0 deletions src/GitHub.App/SampleData/GitServiceDesigner.cs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class GitServiceDesigner : IGitService
public UriString GetUri(IRepository repository, string remote = "origin") => null;
public Task<Patch> Compare(IRepository repository, string sha1, string sha2, string path) => null;
public Task<ContentChanges> CompareWith(IRepository repository, string sha1, string sha2, string path, byte[] contents) => null;
public Task<TreeChanges> Compare(IRepository repository, string sha1, string sha2, bool detectRenames = false) => null;
}
}
40 changes: 1 addition & 39 deletions src/GitHub.App/Services/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class GitClient : IGitClient
readonly PullOptions pullOptions;
readonly PushOptions pushOptions;
readonly FetchOptions fetchOptions;
readonly CompareOptions compareOptions;

[ImportingConstructor]
public GitClient(IGitHubCredentialProvider credentialProvider, IGitService gitService)
Expand All @@ -39,11 +38,6 @@ public GitClient(IGitHubCredentialProvider credentialProvider, IGitService gitSe
FetchOptions = fetchOptions,
MergeOptions = new MergeOptions(),
};

compareOptions = new CompareOptions
{
IndentHeuristic = true
};
}

public Task Pull(IRepository repository)
Expand Down Expand Up @@ -199,38 +193,6 @@ public Task CreateBranch(IRepository repository, string branchName)
});
}

public Task<TreeChanges> Compare(
IRepository repository,
string sha1,
string sha2,
bool detectRenames)
{
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(sha1, nameof(sha1));
Guard.ArgumentNotEmptyString(sha2, nameof(sha2));

return Task.Run(() =>
{
var options = new CompareOptions
{
Similarity = detectRenames ? SimilarityOptions.Renames : SimilarityOptions.None,
IndentHeuristic = compareOptions.IndentHeuristic
};

var commit1 = repository.Lookup<Commit>(sha1);
var commit2 = repository.Lookup<Commit>(sha2);

if (commit1 != null && commit2 != null)
{
return repository.Diff.Compare<TreeChanges>(commit1.Tree, commit2.Tree, options);
}
else
{
return null;
}
});
}

public Task<T> GetConfig<T>(IRepository repository, string key)
{
Guard.ArgumentNotNull(repository, nameof(repository));
Expand Down Expand Up @@ -381,7 +343,7 @@ public Task<bool> IsModified(IRepository repository, string path, byte[] content
using (var s = contents != null ? new MemoryStream(contents) : new MemoryStream())
{
var blob2 = repository.ObjectDatabase.CreateBlob(s, path);
var diff = repository.Diff.Compare(blob1, blob2, compareOptions);
var diff = repository.Diff.Compare(blob1, blob2);
return diff.LinesAdded != 0 || diff.LinesDeleted != 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.App/Services/PullRequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public IObservable<TreeChanges> GetTreeChanges(LocalRepositoryModel repository,
{
var remote = await gitClient.GetHttpRemote(repo, "origin");
await gitClient.Fetch(repo, remote.Name);
var changes = await gitClient.Compare(repo, pullRequest.BaseRefSha, pullRequest.HeadRefSha, detectRenames: true);
var changes = await gitService.Compare(repo, pullRequest.BaseRefSha, pullRequest.HeadRefSha, detectRenames: true);
return Observable.Return(changes);
}
});
Expand Down
13 changes: 0 additions & 13 deletions src/GitHub.Exports.Reactive/Services/IGitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,6 @@ public interface IGitClient
/// <returns></returns>
Task CreateBranch(IRepository repository, string branchName);

/// <summary>
/// Compares two commits.
/// </summary>
/// <param name="repository">The repository</param>
/// <param name="sha1">The SHA of the first commit.</param>
/// <param name="sha2">The SHA of the second commit.</param>
/// <param name="detectRenames">Whether to detect renames</param>
/// <returns>
/// A <see cref="TreeChanges"/> object or null if one of the commits could not be found in the repository,
/// (e.g. it is from a fork).
/// </returns>
Task<TreeChanges> Compare(IRepository repository, string sha1, string sha2, bool detectRenames = false);

/// <summary>
/// Gets the value of a configuration key.
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions src/GitHub.Exports/Services/GitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,5 +289,37 @@ public Task<ContentChanges> CompareWith(IRepository repository, string sha1, str
return null;
});
}

public Task<TreeChanges> Compare(
IRepository repository,
string sha1,
string sha2,
bool detectRenames)
{
Guard.ArgumentNotNull(repository, nameof(repository));
Guard.ArgumentNotEmptyString(sha1, nameof(sha1));
Guard.ArgumentNotEmptyString(sha2, nameof(sha2));

return Task.Run(() =>
{
var options = new CompareOptions
{
Similarity = detectRenames ? SimilarityOptions.Renames : SimilarityOptions.None,
IndentHeuristic = defaultCompareOptions.IndentHeuristic
};

var commit1 = repository.Lookup<Commit>(sha1);
var commit2 = repository.Lookup<Commit>(sha2);

if (commit1 != null && commit2 != null)
{
return repository.Diff.Compare<TreeChanges>(commit1.Tree, commit2.Tree, options);
}
else
{
return null;
}
});
}
}
} A93C
13 changes: 13 additions & 0 deletions src/GitHub.Exports/Services/IGitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,18 @@ public interface IGitService
/// A <see cref="Patch"/> object or null if the commit could not be found in the repository.
/// </returns>
Task<ContentChanges> CompareWith(IRepository repository, string sha1, string sha2, string path, byte[] contents);

/// <summary>
/// Compares two commits.
/// </summary>
/// <param name="repository">The repository</param>
/// <param name="sha1">The SHA of the first commit.</param>
/// <param name="sha2">The SHA of the second commit.</param>
/// <param name="detectRenames">Whether to detect renames</param>
/// <returns>
/// A <see cref="TreeChanges"/> object or null if one of the commits could not be found in the repository,
/// (e.g. it is from a fork).
/// </returns>
Task<TreeChanges> Compare(IRepository repository, string sha1, string sha2, bool detectRenames = false);
}
}
2 changes: 1 addition & 1 deletion test/GitHub.App.UnitTests/Services/GitClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task ContentChangesAsync(int linesAdded, int linesDeleted, bool exp
var changes = Substitute.For<ContentChanges>();
changes.LinesAdded.Returns(linesAdded);
changes.LinesDeleted.Returns(linesDeleted);
repo.Diff.Compare(null as Blob, null as Blob, null as CompareOptions).ReturnsForAnyArgs(changes);
repo.Diff.Compare(null as Blob, null as Blob).ReturnsForAnyArgs(changes);
var gitClient = CreateGitClient();

var modified = await gitClient.IsModified(repo, path, null);
Expand Down
1 change: 1 addition & 0 deletions test/GitHub.TeamFoundation.UnitTests/VSGitExtTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,6 @@ public LocalRepositoryModel CreateLocalRepositoryModel(string localPath)
public UriString GetUri(string path, string remote = "origin") => throw new NotImplementedException();
public Task<Patch> Compare(IRepository repository, string sha1, string sha2, string path) => throw new NotImplementedException();
public Task<ContentChanges> CompareWith(IRepository repository, string sha1, string sha2, string path, byte[] contents) => throw new NotImplementedException();
public Task<TreeChanges> Compare(IRepository repository, string sha1, string sha2, bool detectRenames = false) => throw new NotImplementedException();
}
}
0