-
Notifications
You must be signed in to change notification settings - Fork 664
Move LibGit2Sharp implementation to separate lib #2525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
arturcic
merged 16 commits into
GitTools:master
from
arturcic:feature/libgit2sharp-separate-implementation
Jan 11, 2021
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7fc863a
added IObjectId and ITag
arturcic be0ada0
added IReference and IRemote
arturcic 272abb6
added IBranch
arturcic cab8f0c
cleanup
arturcic ffaceed
added ICommit
arturcic 9cd32e1
cleanup
arturcic abebcca
cleanup for IReference and IReferenceCollection
arturcic 05f32f8
cleanup IBranchCollection and IBranch
arturcic c1a1f60
cleanup ObjectId and Remote
arturcic 624131e
cleanup ICommitCollection
arturcic 6f530ad
cleanup ICommit
arturcic 6037916
cleanup IGitRepository
arturcic fb20156
cleanup
arturcic 6351fe9
moved some static methods into IGitRepository
arturcic 574bead
moved LibGit2Sharp implementation to separate lib
arturcic d2b32cb
made libgit2sharp implementation classes internal
arturcic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| [assembly: InternalsVisibleTo("GitVersionCore.Tests")] | ||
| [assembly: InternalsVisibleTo("GitVersionExe.Tests")] | ||
| [assembly: InternalsVisibleTo("GitVersion.MsBuild.Tests")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| namespace GitVersion | ||
| { | ||
| internal class Branch : IBranch | ||
| { | ||
| private readonly LibGit2Sharp.Branch innerBranch; | ||
|
|
||
| internal Branch(LibGit2Sharp.Branch branch) | ||
| { | ||
| innerBranch = branch; | ||
| } | ||
|
|
||
| protected Branch() | ||
| { | ||
| } | ||
| public static implicit operator LibGit2Sharp.Branch(Branch d) => d?.innerBranch; | ||
|
|
||
| public virtual string CanonicalName => innerBranch?.CanonicalName; | ||
| public virtual string FriendlyName => innerBranch?.FriendlyName; | ||
| public virtual ICommit Tip | ||
| { | ||
| get | ||
| { | ||
| var commit = innerBranch?.Tip; | ||
| return commit is null ? null : new Commit(commit); | ||
| } | ||
| } | ||
|
|
||
| public virtual ICommitCollection Commits | ||
| { | ||
| get | ||
| { | ||
|
|
||
| var commits = innerBranch?.Commits; | ||
| return commits is null ? null : new CommitCollection(commits); | ||
| } | ||
| } | ||
|
|
||
| public virtual bool IsRemote => innerBranch != null && innerBranch.IsRemote; | ||
| public virtual bool IsTracking => innerBranch != null && innerBranch.IsTracking; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace GitVersion | ||
| { | ||
| internal class BranchCollection : IBranchCollection | ||
| { | ||
| private readonly LibGit2Sharp.BranchCollection innerCollection; | ||
| internal BranchCollection(LibGit2Sharp.BranchCollection collection) => innerCollection = collection; | ||
|
|
||
| protected BranchCollection() | ||
| { | ||
| } | ||
|
|
||
| public virtual IEnumerator<IBranch> GetEnumerator() | ||
| { | ||
| return innerCollection.Select(branch => new Branch(branch)).GetEnumerator(); | ||
| } | ||
| IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
| public virtual IBranch this[string friendlyName] | ||
| { | ||
| get | ||
| { | ||
| var branch = innerCollection?[friendlyName]; | ||
| return branch is null ? null : new Branch(branch); | ||
| } | ||
| } | ||
|
|
||
| public void UpdateTrackedBranch(IBranch branch, string remoteTrackingReferenceName) | ||
| { | ||
| innerCollection.Update((Branch)branch, b => b.TrackedBranch = remoteTrackingReferenceName); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using GitVersion.Helpers; | ||
|
|
||
| namespace GitVersion | ||
| { | ||
| internal class Commit : ICommit | ||
| { | ||
| private static readonly LambdaEqualityHelper<ICommit> equalityHelper = | ||
| new LambdaEqualityHelper<ICommit>(x => x.Id); | ||
|
|
||
| private readonly LibGit2Sharp.Commit innerObjectId; | ||
|
|
||
| internal Commit(LibGit2Sharp.Commit objectId) | ||
| { | ||
| innerObjectId = objectId; | ||
asbjornu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| protected Commit() | ||
| { | ||
| } | ||
|
|
||
| public override bool Equals(object obj) => Equals(obj as ICommit); | ||
| public bool Equals(ICommit other) => equalityHelper.Equals(this, other); | ||
| public override int GetHashCode() => equalityHelper.GetHashCode(this); | ||
|
|
||
| public static implicit operator LibGit2Sharp.Commit(Commit d) => d?.innerObjectId; | ||
|
|
||
| public virtual IEnumerable<ICommit> Parents | ||
| { | ||
| get | ||
| { | ||
| if (innerObjectId == null) yield return null; | ||
| else | ||
| foreach (var parent in innerObjectId.Parents) | ||
| yield return new Commit(parent); | ||
| } | ||
| } | ||
|
|
||
| public virtual string Sha => innerObjectId?.Sha; | ||
|
|
||
| public virtual IObjectId Id | ||
| { | ||
| get | ||
| { | ||
| var objectId = innerObjectId?.Id; | ||
| return objectId is null ? null : new ObjectId(objectId); | ||
| } | ||
| } | ||
|
|
||
| public virtual DateTimeOffset? CommitterWhen => innerObjectId?.Committer.When; | ||
| public virtual string Message => innerObjectId?.Message; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using LibGit2Sharp; | ||
|
|
||
| namespace GitVersion | ||
| { | ||
| internal class CommitCollection : ICommitCollection | ||
| { | ||
| private readonly ICommitLog innerCollection; | ||
| internal CommitCollection(ICommitLog collection) => innerCollection = collection; | ||
|
|
||
| protected CommitCollection() | ||
| { | ||
| } | ||
|
|
||
| public virtual IEnumerator<ICommit> GetEnumerator() | ||
| { | ||
| return innerCollection.Select(commit => new Commit(commit)).GetEnumerator(); | ||
| } | ||
|
|
||
| IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
|
|
||
| public virtual ICommitCollection QueryBy(CommitFilter commitFilter) | ||
| { | ||
| static object GetReacheableFrom(object item) | ||
| { | ||
| return item switch | ||
| { | ||
| Commit c => (LibGit2Sharp.Commit)c, | ||
| Branch b => (LibGit2Sharp.Branch)b, | ||
| _ => null | ||
| }; | ||
| } | ||
|
|
||
| var includeReachableFrom = GetReacheableFrom(commitFilter.IncludeReachableFrom); | ||
| var excludeReachableFrom = GetReacheableFrom(commitFilter.ExcludeReachableFrom); | ||
| var filter = new LibGit2Sharp.CommitFilter | ||
| { | ||
| IncludeReachableFrom = includeReachableFrom, | ||
| ExcludeReachableFrom = excludeReachableFrom, | ||
| FirstParentOnly = commitFilter.FirstParentOnly, | ||
| SortBy = (LibGit2Sharp.CommitSortStrategies)commitFilter.SortBy, | ||
| }; | ||
| var commitLog = ((IQueryableCommitLog)innerCollection).QueryBy(filter); | ||
| return new CommitCollection(commitLog); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.