Skip to content

Commit ad9ee06

Browse files
committed
Replace IGitObject with ICommit and remove IGitObject
Refactors code to use `ICommit` directly, removing the redundant `IGitObject` interface. Updates method signatures and implementations accordingly. Deletes the `GitObject` class and streamlines related methods.
1 parent f480080 commit ad9ee06

File tree

10 files changed

+18
-46
lines changed

10 files changed

+18
-46
lines changed

src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ private class MockCommit : ICommit
199199
{
200200
public bool Equals(ICommit? other) => throw new NotImplementedException();
201201
public int CompareTo(ICommit? other) => throw new NotImplementedException();
202-
public bool Equals(IGitObject? other) => throw new NotImplementedException();
203-
public int CompareTo(IGitObject? other) => throw new NotImplementedException();
204202
public IObjectId Id => throw new NotImplementedException();
205203
public string Sha => throw new NotImplementedException();
206204
public IReadOnlyList<ICommit> Parents => throw new NotImplementedException();

src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public interface IRepositoryStore
2222

2323
IReadOnlyList<ICommit> GetCommitLog(ICommit? baseVersionSource, ICommit currentCommit, IIgnoreConfiguration ignore);
2424
IReadOnlyList<ICommit> GetCommitsReacheableFromHead(ICommit? headCommit, IIgnoreConfiguration ignore);
25-
IReadOnlyList<ICommit> GetCommitsReacheableFrom(IGitObject commit, IBranch branch);
25+
IReadOnlyList<ICommit> GetCommitsReacheableFrom(ICommit commit, IBranch branch);
2626

2727
IBranch GetTargetBranch(string? targetBranchName);
2828
IBranch? FindBranch(ReferenceName branchName);

src/GitVersion.Core/Core/BranchesContainingCommitFinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public IEnumerable<IBranch> GetBranchesContainingCommit(ICommit commit, IEnumera
2121
return InnerGetBranchesContainingCommit(commit, branches, onlyTrackedBranches);
2222
}
2323

24-
private IEnumerable<IBranch> InnerGetBranchesContainingCommit(IGitObject commit, IEnumerable<IBranch> branches, bool onlyTrackedBranches)
24+
private IEnumerable<IBranch> InnerGetBranchesContainingCommit(ICommit commit, IEnumerable<IBranch> branches, bool onlyTrackedBranches)
2525
{
2626
using (log.IndentLog($"Getting branches containing the commit '{commit.Id}'."))
2727
{
@@ -63,6 +63,6 @@ private IEnumerable<IBranch> InnerGetBranchesContainingCommit(IGitObject commit,
6363
private static bool IncludeTrackedBranches(IBranch branch, bool includeOnlyTracked)
6464
=> (includeOnlyTracked && branch.IsTracking) || !includeOnlyTracked;
6565

66-
private static bool BranchTipIsNullOrCommit(IBranch branch, IGitObject commit)
66+
private static bool BranchTipIsNullOrCommit(IBranch branch, ICommit commit)
6767
=> branch.Tip == null || branch.Tip.Sha == commit.Sha;
6868
}

src/GitVersion.Core/Core/RepositoryStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public IReadOnlyList<ICommit> GetCommitsReacheableFromHead(ICommit? headCommit,
231231
return [.. ignore.Filter(commits)];
232232
}
233233

234-
public IReadOnlyList<ICommit> GetCommitsReacheableFrom(IGitObject commit, IBranch branch)
234+
public IReadOnlyList<ICommit> GetCommitsReacheableFrom(ICommit commit, IBranch branch)
235235
{
236236
var filter = new CommitFilter { IncludeReachableFrom = branch };
237237

src/GitVersion.Core/Git/ICommit.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
namespace GitVersion.Git;
22

3-
public interface ICommit : IEquatable<ICommit?>, IComparable<ICommit>, IGitObject
3+
public interface ICommit : IEquatable<ICommit?>, IComparable<ICommit>
44
{
55
IReadOnlyList<ICommit> Parents { get; }
66

7+
IObjectId Id { get; }
8+
9+
string Sha { get; }
10+
711
DateTimeOffset When { get; }
812

913
string Message { get; }

src/GitVersion.Core/Git/IGitObject.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/GitVersion.Core/PublicAPI.Shipped.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.Git.IBranch? branch,
2828
GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.Git.ICommit! commit, GitVersion.Git.ICommit! mainlineTip) -> GitVersion.Git.ICommit?
2929
GitVersion.Common.IRepositoryStore.GetBranchesContainingCommit(GitVersion.Git.ICommit! commit, System.Collections.Generic.IEnumerable<GitVersion.Git.IBranch!>? branches = null, bool onlyTrackedBranches = false) -> System.Collections.Generic.IEnumerable<GitVersion.Git.IBranch!>!
3030
GitVersion.Common.IRepositoryStore.GetCommitLog(GitVersion.Git.ICommit? baseVersionSource, GitVersion.Git.ICommit! currentCommit, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
31-
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.IGitObject! commit, GitVersion.Git.IBranch! branch) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
3231
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFromHead(GitVersion.Git.ICommit? headCommit, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
3332
GitVersion.Common.IRepositoryStore.GetCurrentCommit(GitVersion.Git.IBranch! currentBranch, string? commitId, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> GitVersion.Git.ICommit?
3433
GitVersion.Common.IRepositoryStore.GetForwardMerge(GitVersion.Git.ICommit? commitToFindCommonBase, GitVersion.Git.ICommit? findMergeBase) -> GitVersion.Git.ICommit?
@@ -227,9 +226,6 @@ GitVersion.Git.ICommit.When.get -> System.DateTimeOffset
227226
GitVersion.Git.ICommitCollection
228227
GitVersion.Git.ICommitCollection.GetCommitsPriorTo(System.DateTimeOffset olderThan) -> System.Collections.Generic.IEnumerable<GitVersion.Git.ICommit!>!
229228
GitVersion.Git.ICommitCollection.QueryBy(GitVersion.Git.CommitFilter! commitFilter) -> System.Collections.Generic.IEnumerable<GitVersion.Git.ICommit!>!
230-
GitVersion.Git.IGitObject
231-
GitVersion.Git.IGitObject.Id.get -> GitVersion.Git.IObjectId!
232-
GitVersion.Git.IGitObject.Sha.get -> string!
233229
GitVersion.Git.IGitRepository
234230
GitVersion.Git.IGitRepository.Branches.get -> GitVersion.Git.IBranchCollection!
235231
GitVersion.Git.IGitRepository.Commits.get -> GitVersion.Git.ICommitCollection!
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
#nullable enable
2+
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.ICommit! commit, GitVersion.Git.IBranch! branch) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
3+
GitVersion.Git.ICommit.Id.get -> GitVersion.Git.IObjectId!
4+
GitVersion.Git.ICommit.Sha.get -> string!

src/GitVersion.LibGit2Sharp/Git/Commit.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace GitVersion.Git;
66

7-
internal sealed class Commit : GitObject, ICommit
7+
internal sealed class Commit : ICommit
88
{
99
private static readonly ConcurrentDictionary<string, IReadOnlyList<string>> pathsCache = new();
1010
private static readonly LambdaEqualityHelper<ICommit> equalityHelper = new(x => x.Id);
@@ -14,19 +14,23 @@ internal sealed class Commit : GitObject, ICommit
1414
private readonly LibGit2Sharp.Commit innerCommit;
1515
private readonly LibGit2Sharp.Diff repoDiff;
1616

17-
internal Commit(LibGit2Sharp.Commit innerCommit, LibGit2Sharp.Diff repoDiff, GitRepository repo) : base(innerCommit)
17+
internal Commit(LibGit2Sharp.Commit innerCommit, LibGit2Sharp.Diff repoDiff, GitRepository repo)
1818
{
1919
repoDiff.NotNull();
2020
repo.NotNull();
2121
this.innerCommit = innerCommit.NotNull();
2222
this.parentsLazy = new(() => innerCommit.Parents.Select(parent => repo.GetOrCreate(parent, repoDiff)).ToList());
23+
Id = new ObjectId(innerCommit.Id);
24+
Sha = innerCommit.Sha;
2325
When = innerCommit.Committer.When;
2426
this.repoDiff = repoDiff;
2527
}
2628

2729
public int CompareTo(ICommit? other) => comparerHelper.Compare(this, other);
2830
public bool Equals(ICommit? other) => equalityHelper.Equals(this, other);
2931
public IReadOnlyList<ICommit> Parents => this.parentsLazy.Value;
32+
public IObjectId Id { get; }
33+
public string Sha { get; }
3034
public DateTimeOffset When { get; }
3135
public string Message => this.innerCommit.Message;
3236
public IReadOnlyList<string> DiffPaths

src/GitVersion.LibGit2Sharp/Git/GitObject.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)