diff --git a/new-cli/GitVersion.Core.Libgit2Sharp/GitVersion.Core.Libgit2Sharp.csproj b/new-cli/GitVersion.Core.Libgit2Sharp/GitVersion.Core.Libgit2Sharp.csproj
index 4e8f95ddc5..a42d02992f 100644
--- a/new-cli/GitVersion.Core.Libgit2Sharp/GitVersion.Core.Libgit2Sharp.csproj
+++ b/new-cli/GitVersion.Core.Libgit2Sharp/GitVersion.Core.Libgit2Sharp.csproj
@@ -5,61 +5,13 @@
-
+
-
- Git\Branch.cs
-
-
- Git\BranchCollection.cs
-
-
- Git\Commit.cs
-
-
- Git\CommitCollection.cs
-
-
- Git\GitObject.cs
-
-
- Git\GitRepository.cs
-
-
- Git\ObjectId.cs
-
-
- Git\Reference.cs
-
-
- Git\ReferenceCollection.cs
-
-
- Git\RefSpec.cs
-
-
- Git\RefSpecCollection.cs
-
-
- Git\Remote.cs
-
-
- Git\RemoteCollection.cs
-
-
- Git\RepositoryExtensions.cs
-
-
- Git\Tag.cs
-
-
- Git\TagCollection.cs
-
-
- Git\TreeChanges.cs
-
+
+
+
diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs
index 1f03f3a9ea..d38ae71969 100644
--- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs
+++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs
@@ -199,8 +199,6 @@ private class MockCommit : ICommit
{
public bool Equals(ICommit? other) => throw new NotImplementedException();
public int CompareTo(ICommit? other) => throw new NotImplementedException();
- public bool Equals(IGitObject? other) => throw new NotImplementedException();
- public int CompareTo(IGitObject? other) => throw new NotImplementedException();
public IObjectId Id => throw new NotImplementedException();
public string Sha => throw new NotImplementedException();
public IReadOnlyList Parents => throw new NotImplementedException();
diff --git a/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs b/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs
index e3a2f260af..18fc7edd92 100644
--- a/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs
+++ b/src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs
@@ -22,7 +22,7 @@ public interface IRepositoryStore
IReadOnlyList GetCommitLog(ICommit? baseVersionSource, ICommit currentCommit, IIgnoreConfiguration ignore);
IReadOnlyList GetCommitsReacheableFromHead(ICommit? headCommit, IIgnoreConfiguration ignore);
- IReadOnlyList GetCommitsReacheableFrom(IGitObject commit, IBranch branch);
+ IReadOnlyList GetCommitsReacheableFrom(ICommit commit, IBranch branch);
IBranch GetTargetBranch(string? targetBranchName);
IBranch? FindBranch(ReferenceName branchName);
diff --git a/src/GitVersion.Core/Core/BranchesContainingCommitFinder.cs b/src/GitVersion.Core/Core/BranchesContainingCommitFinder.cs
index fb5f8b6d68..d078714e98 100644
--- a/src/GitVersion.Core/Core/BranchesContainingCommitFinder.cs
+++ b/src/GitVersion.Core/Core/BranchesContainingCommitFinder.cs
@@ -21,7 +21,7 @@ public IEnumerable GetBranchesContainingCommit(ICommit commit, IEnumera
return InnerGetBranchesContainingCommit(commit, branches, onlyTrackedBranches);
}
- private IEnumerable InnerGetBranchesContainingCommit(IGitObject commit, IEnumerable branches, bool onlyTrackedBranches)
+ private IEnumerable InnerGetBranchesContainingCommit(ICommit commit, IEnumerable branches, bool onlyTrackedBranches)
{
using (log.IndentLog($"Getting branches containing the commit '{commit.Id}'."))
{
@@ -63,6 +63,6 @@ private IEnumerable InnerGetBranchesContainingCommit(IGitObject commit,
private static bool IncludeTrackedBranches(IBranch branch, bool includeOnlyTracked)
=> (includeOnlyTracked && branch.IsTracking) || !includeOnlyTracked;
- private static bool BranchTipIsNullOrCommit(IBranch branch, IGitObject commit)
+ private static bool BranchTipIsNullOrCommit(IBranch branch, ICommit commit)
=> branch.Tip == null || branch.Tip.Sha == commit.Sha;
}
diff --git a/src/GitVersion.Core/Core/RepositoryStore.cs b/src/GitVersion.Core/Core/RepositoryStore.cs
index ee018444fb..401cae566a 100644
--- a/src/GitVersion.Core/Core/RepositoryStore.cs
+++ b/src/GitVersion.Core/Core/RepositoryStore.cs
@@ -231,7 +231,7 @@ public IReadOnlyList GetCommitsReacheableFromHead(ICommit? headCommit,
return [.. ignore.Filter(commits)];
}
- public IReadOnlyList GetCommitsReacheableFrom(IGitObject commit, IBranch branch)
+ public IReadOnlyList GetCommitsReacheableFrom(ICommit commit, IBranch branch)
{
var filter = new CommitFilter { IncludeReachableFrom = branch };
diff --git a/src/GitVersion.Core/Git/ICommit.cs b/src/GitVersion.Core/Git/ICommit.cs
index 8d3b225655..1a979ca494 100644
--- a/src/GitVersion.Core/Git/ICommit.cs
+++ b/src/GitVersion.Core/Git/ICommit.cs
@@ -1,9 +1,12 @@
namespace GitVersion.Git;
-public interface ICommit : IEquatable, IComparable, IGitObject
+public interface ICommit : IEquatable, IComparable
{
IReadOnlyList Parents { get; }
+ IObjectId Id { get; }
+ string Sha { get; }
+
DateTimeOffset When { get; }
string Message { get; }
diff --git a/src/GitVersion.Core/Git/IGitObject.cs b/src/GitVersion.Core/Git/IGitObject.cs
deleted file mode 100644
index 1965547a30..0000000000
--- a/src/GitVersion.Core/Git/IGitObject.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace GitVersion.Git;
-
-public interface IGitObject : IEquatable, IComparable
-{
- IObjectId Id { get; }
- string Sha { get; }
-}
diff --git a/src/GitVersion.Core/PublicAPI.Shipped.txt b/src/GitVersion.Core/PublicAPI.Shipped.txt
index 53c7d65518..f8cc9b01d7 100644
--- a/src/GitVersion.Core/PublicAPI.Shipped.txt
+++ b/src/GitVersion.Core/PublicAPI.Shipped.txt
@@ -28,7 +28,6 @@ GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.Git.IBranch? branch,
GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.Git.ICommit! commit, GitVersion.Git.ICommit! mainlineTip) -> GitVersion.Git.ICommit?
GitVersion.Common.IRepositoryStore.GetBranchesContainingCommit(GitVersion.Git.ICommit! commit, System.Collections.Generic.IEnumerable? branches = null, bool onlyTrackedBranches = false) -> System.Collections.Generic.IEnumerable!
GitVersion.Common.IRepositoryStore.GetCommitLog(GitVersion.Git.ICommit? baseVersionSource, GitVersion.Git.ICommit! currentCommit, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> System.Collections.Generic.IReadOnlyList!
-GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.IGitObject! commit, GitVersion.Git.IBranch! branch) -> System.Collections.Generic.IReadOnlyList!
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFromHead(GitVersion.Git.ICommit? headCommit, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> System.Collections.Generic.IReadOnlyList!
GitVersion.Common.IRepositoryStore.GetCurrentCommit(GitVersion.Git.IBranch! currentBranch, string? commitId, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> GitVersion.Git.ICommit?
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
GitVersion.Git.ICommitCollection
GitVersion.Git.ICommitCollection.GetCommitsPriorTo(System.DateTimeOffset olderThan) -> System.Collections.Generic.IEnumerable!
GitVersion.Git.ICommitCollection.QueryBy(GitVersion.Git.CommitFilter! commitFilter) -> System.Collections.Generic.IEnumerable!
-GitVersion.Git.IGitObject
-GitVersion.Git.IGitObject.Id.get -> GitVersion.Git.IObjectId!
-GitVersion.Git.IGitObject.Sha.get -> string!
GitVersion.Git.IGitRepository
GitVersion.Git.IGitRepository.Branches.get -> GitVersion.Git.IBranchCollection!
GitVersion.Git.IGitRepository.Commits.get -> GitVersion.Git.ICommitCollection!
diff --git a/src/GitVersion.Core/PublicAPI.Unshipped.txt b/src/GitVersion.Core/PublicAPI.Unshipped.txt
index 7dc5c58110..19cd7e2e08 100644
--- a/src/GitVersion.Core/PublicAPI.Unshipped.txt
+++ b/src/GitVersion.Core/PublicAPI.Unshipped.txt
@@ -1 +1,4 @@
#nullable enable
+GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.ICommit! commit, GitVersion.Git.IBranch! branch) -> System.Collections.Generic.IReadOnlyList!
+GitVersion.Git.ICommit.Id.get -> GitVersion.Git.IObjectId!
+GitVersion.Git.ICommit.Sha.get -> string!
diff --git a/src/GitVersion.LibGit2Sharp/Git/Branch.cs b/src/GitVersion.LibGit2Sharp/Git/Branch.cs
index bfa286cad8..7cd5cce70e 100644
--- a/src/GitVersion.LibGit2Sharp/Git/Branch.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/Branch.cs
@@ -18,7 +18,7 @@ internal Branch(LibGit2Sharp.Branch branch, LibGit2Sharp.Diff diff, GitRepositor
Name = new(branch.CanonicalName);
var commit = this.innerBranch.Tip;
- Tip = commit is null ? null : repo.GetOrCreate(commit, diff);
+ Tip = commit is null ? null : repo.GetOrWrap(commit, diff);
var commits = this.innerBranch.Commits;
Commits = new CommitCollection(commits, diff, repo);
diff --git a/src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs b/src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs
index b8b1df839d..8fd144815d 100644
--- a/src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs
@@ -13,13 +13,12 @@ internal sealed class BranchCollection : IBranchCollection
internal BranchCollection(LibGit2Sharp.BranchCollection collection, Diff diff, GitRepository repo)
{
this.innerCollection = collection.NotNull();
- this.branches = new Lazy>(() => [.. this.innerCollection.Select(branch => repo.GetOrCreate(branch, diff))]);
+ this.branches = new Lazy>(() => [.. this.innerCollection.Select(branch => repo.GetOrWrap(branch, diff))]);
this.diff = diff.NotNull();
this.repo = repo.NotNull();
}
- public IEnumerator GetEnumerator()
- => this.branches.Value.GetEnumerator();
+ public IEnumerator GetEnumerator() => this.branches.Value.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
@@ -29,7 +28,7 @@ public IBranch? this[string name]
{
name = name.NotNull();
var branch = this.innerCollection[name];
- return branch is null ? null : this.repo.GetOrCreate(branch, this.diff);
+ return branch is null ? null : this.repo.GetOrWrap(branch, this.diff);
}
}
diff --git a/src/GitVersion.LibGit2Sharp/Git/Commit.cs b/src/GitVersion.LibGit2Sharp/Git/Commit.cs
index 60bb853dd7..d85fc32a1c 100644
--- a/src/GitVersion.LibGit2Sharp/Git/Commit.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/Commit.cs
@@ -4,7 +4,7 @@
namespace GitVersion.Git;
-internal sealed class Commit : GitObject, ICommit
+internal sealed class Commit : ICommit
{
private static readonly ConcurrentDictionary> pathsCache = new();
private static readonly LambdaEqualityHelper equalityHelper = new(x => x.Id);
@@ -14,12 +14,14 @@ internal sealed class Commit : GitObject, ICommit
private readonly LibGit2Sharp.Commit innerCommit;
private readonly LibGit2Sharp.Diff repoDiff;
- internal Commit(LibGit2Sharp.Commit innerCommit, LibGit2Sharp.Diff repoDiff, GitRepository repo) : base(innerCommit)
+ internal Commit(LibGit2Sharp.Commit innerCommit, LibGit2Sharp.Diff repoDiff, GitRepository repo)
{
repoDiff.NotNull();
repo.NotNull();
this.innerCommit = innerCommit.NotNull();
- this.parentsLazy = new(() => innerCommit.Parents.Select(parent => repo.GetOrCreate(parent, repoDiff)).ToList());
+ this.parentsLazy = new(() => innerCommit.Parents.Select(parent => repo.GetOrWrap(parent, repoDiff)).ToList());
+ Id = new ObjectId(innerCommit.Id);
+ Sha = innerCommit.Sha;
When = innerCommit.Committer.When;
this.repoDiff = repoDiff;
}
@@ -27,6 +29,8 @@ internal Commit(LibGit2Sharp.Commit innerCommit, LibGit2Sharp.Diff repoDiff, Git
public int CompareTo(ICommit? other) => comparerHelper.Compare(this, other);
public bool Equals(ICommit? other) => equalityHelper.Equals(this, other);
public IReadOnlyList Parents => this.parentsLazy.Value;
+ public IObjectId Id { get; }
+ public string Sha { get; }
public DateTimeOffset When { get; }
public string Message => this.innerCommit.Message;
public IReadOnlyList DiffPaths
diff --git a/src/GitVersion.LibGit2Sharp/Git/CommitCollection.cs b/src/GitVersion.LibGit2Sharp/Git/CommitCollection.cs
index 05d9940f94..4c4607815e 100644
--- a/src/GitVersion.LibGit2Sharp/Git/CommitCollection.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/CommitCollection.cs
@@ -13,13 +13,12 @@ internal sealed class CommitCollection : ICommitCollection
internal CommitCollection(ICommitLog collection, Diff diff, GitRepository repo)
{
this.innerCollection = collection.NotNull();
- this.commits = new Lazy>(() => [.. this.innerCollection.Select(commit => repo.GetOrCreate(commit, diff))]);
+ this.commits = new Lazy>(() => [.. this.innerCollection.Select(commit => repo.GetOrWrap(commit, diff))]);
this.diff = diff.NotNull();
this.repo = repo.NotNull();
}
- public IEnumerator GetEnumerator()
- => this.commits.Value.GetEnumerator();
+ public IEnumerator GetEnumerator() => this.commits.Value.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
diff --git a/src/GitVersion.LibGit2Sharp/Git/GitObject.cs b/src/GitVersion.LibGit2Sharp/Git/GitObject.cs
deleted file mode 100644
index 850168393c..0000000000
--- a/src/GitVersion.LibGit2Sharp/Git/GitObject.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using GitVersion.Extensions;
-using GitVersion.Helpers;
-
-namespace GitVersion.Git;
-
-internal class GitObject : IGitObject
-{
- private static readonly LambdaEqualityHelper equalityHelper = new(x => x.Id);
- private static readonly LambdaKeyComparer comparerHelper = new(x => x.Sha);
-
- internal GitObject(LibGit2Sharp.GitObject innerGitObject)
- {
- innerGitObject = innerGitObject.NotNull();
- Id = new ObjectId(innerGitObject.Id);
- Sha = innerGitObject.Sha;
- }
-
- public int CompareTo(IGitObject? other) => comparerHelper.Compare(this, other);
- public bool Equals(IGitObject? other) => equalityHelper.Equals(this, other);
- public override bool Equals(object? obj) => Equals(obj as IGitObject);
- public override int GetHashCode() => equalityHelper.GetHashCode(this);
- public override string ToString() => Id.ToString(7);
-
- public IObjectId Id { get; }
- public string Sha { get; }
-}
diff --git a/src/GitVersion.LibGit2Sharp/Git/GitRepository.cs b/src/GitVersion.LibGit2Sharp/Git/GitRepository.cs
index 115bceb44c..49280c0726 100644
--- a/src/GitVersion.LibGit2Sharp/Git/GitRepository.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/GitRepository.cs
@@ -25,7 +25,7 @@ private IRepository RepositoryInstance
public string WorkingDirectory => RepositoryInstance.Info.WorkingDirectory;
public bool IsHeadDetached => RepositoryInstance.Info.IsHeadDetached;
public bool IsShallow => RepositoryInstance.Info.IsShallow;
- public IBranch Head => GetOrCreate(RepositoryInstance.Head, RepositoryInstance.Diff);
+ public IBranch Head => GetOrWrap(RepositoryInstance.Head, RepositoryInstance.Diff);
public ITagCollection Tags => new TagCollection(RepositoryInstance.Tags, RepositoryInstance.Diff, this);
public IReferenceCollection Refs => new ReferenceCollection(RepositoryInstance.Refs);
@@ -53,7 +53,7 @@ public void DiscoverRepository(string? gitDirectory)
var first = (Commit)commit;
var second = (Commit)otherCommit;
var mergeBase = RepositoryInstance.ObjectDatabase.FindMergeBase(first, second);
- return mergeBase == null ? null : GetOrCreate(mergeBase, RepositoryInstance.Diff);
+ return mergeBase == null ? null : GetOrWrap(mergeBase, RepositoryInstance.Diff);
});
}
@@ -63,24 +63,24 @@ public int UncommittedChangesCount()
return retryAction.Execute(GetUncommittedChangesCountInternal);
}
- public Branch GetOrCreate(LibGit2Sharp.Branch innerBranch, Diff repoDiff)
+ public Branch GetOrWrap(LibGit2Sharp.Branch innerBranch, Diff repoDiff)
{
if (innerBranch.Tip is null)
{
return new Branch(innerBranch, repoDiff, this);
}
- var cacheKey = $"{innerBranch.CanonicalName}|{innerBranch.Tip.Sha}|{innerBranch.RemoteName}";
- return cachedBranches.GetOrAdd(cacheKey, new Branch(innerBranch, repoDiff, this));
+ var cacheKey = $"{innerBranch.RemoteName}/{innerBranch.CanonicalName}@{innerBranch.Tip.Sha}";
+ return cachedBranches.GetOrAdd(cacheKey, _ => new Branch(innerBranch, repoDiff, this));
}
- public Commit GetOrCreate(LibGit2Sharp.Commit innerCommit, Diff repoDiff) =>
- cachedCommits.GetOrAdd(innerCommit.Sha, new Commit(innerCommit, repoDiff, this));
+ public Commit GetOrWrap(LibGit2Sharp.Commit innerCommit, Diff repoDiff) =>
+ cachedCommits.GetOrAdd(innerCommit.Sha, _ => new Commit(innerCommit, repoDiff, this));
- public Tag GetOrCreate(LibGit2Sharp.Tag innerTag, Diff repoDiff)
+ public Tag GetOrWrap(LibGit2Sharp.Tag innerTag, Diff repoDiff)
{
- var cacheKey = $"{innerTag.CanonicalName}|{innerTag.Target.Sha}";
- return cachedTags.GetOrAdd(cacheKey, new Tag(innerTag, repoDiff, this));
+ var cacheKey = $"{innerTag.CanonicalName}@{innerTag.Target.Sha}";
+ return cachedTags.GetOrAdd(cacheKey, _ => new Tag(innerTag, repoDiff, this));
}
public void Dispose()
diff --git a/src/GitVersion.LibGit2Sharp/Git/ReferenceCollection.cs b/src/GitVersion.LibGit2Sharp/Git/ReferenceCollection.cs
index 2aa74a2140..d7031033ce 100644
--- a/src/GitVersion.LibGit2Sharp/Git/ReferenceCollection.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/ReferenceCollection.cs
@@ -15,6 +15,8 @@ public IEnumerator GetEnumerator()
return this.references.GetEnumerator();
}
+ IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
+
public void Add(string name, string canonicalRefNameOrObject, bool allowOverwrite = false) => this.innerCollection.Add(name, canonicalRefNameOrObject, allowOverwrite);
public void UpdateTarget(IReference directRef, IObjectId targetId)
@@ -23,8 +25,6 @@ public void UpdateTarget(IReference directRef, IObjectId targetId)
this.references = null;
}
- IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
-
public IReference? this[string name]
{
get
diff --git a/src/GitVersion.LibGit2Sharp/Git/Tag.cs b/src/GitVersion.LibGit2Sharp/Git/Tag.cs
index 89fb6d777a..0fe66a2c7d 100644
--- a/src/GitVersion.LibGit2Sharp/Git/Tag.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/Tag.cs
@@ -37,7 +37,7 @@ internal Tag(LibGit2Sharp.Tag tag, Diff diff, GitRepository repo)
target = annotation.Target;
}
- return target is LibGit2Sharp.Commit commit ? this.repo.GetOrCreate(commit, this.diff) : null;
+ return target is LibGit2Sharp.Commit commit ? this.repo.GetOrWrap(commit, this.diff) : null;
}
public override bool Equals(object? obj) => Equals(obj as ITag);
diff --git a/src/GitVersion.LibGit2Sharp/Git/TagCollection.cs b/src/GitVersion.LibGit2Sharp/Git/TagCollection.cs
index ec339e28b3..64ce7d7c1c 100644
--- a/src/GitVersion.LibGit2Sharp/Git/TagCollection.cs
+++ b/src/GitVersion.LibGit2Sharp/Git/TagCollection.cs
@@ -11,11 +11,10 @@ internal TagCollection(LibGit2Sharp.TagCollection collection, LibGit2Sharp.Diff
collection.NotNull();
diff.NotNull();
repo.NotNull();
- this.tags = new Lazy>(() => [.. collection.Select(tag => repo.GetOrCreate(tag, diff))]);
+ this.tags = new Lazy>(() => [.. collection.Select(tag => repo.GetOrWrap(tag, diff))]);
}
- public IEnumerator GetEnumerator()
- => this.tags.Value.GetEnumerator();
+ public IEnumerator GetEnumerator() => this.tags.Value.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}