Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,13 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GitVersion.Common\GitVersion.Common.csproj" />
<ProjectReference Include="..\GitVersion.Common\GitVersion.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Branch.cs">
<Link>Git\Branch.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\BranchCollection.cs">
<Link>Git\BranchCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Commit.cs">
<Link>Git\Commit.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\CommitCollection.cs">
<Link>Git\CommitCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\GitObject.cs">
<Link>Git\GitObject.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs">
<Link>Git\GitRepository.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\ObjectId.cs">
<Link>Git\ObjectId.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Reference.cs">
<Link>Git\Reference.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\ReferenceCollection.cs">
<Link>Git\ReferenceCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RefSpec.cs">
<Link>Git\RefSpec.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RefSpecCollection.cs">
<Link>Git\RefSpecCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Remote.cs">
<Link>Git\Remote.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RemoteCollection.cs">
<Link>Git\RemoteCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RepositoryExtensions.cs">
<Link>Git\RepositoryExtensions.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Tag.cs">
<Link>Git\Tag.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\TagCollection.cs">
<Link>Git\TagCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\TreeChanges.cs">
<Link>Git\TreeChanges.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\*.cs" Link="Git\%(Filename)%(Extension)" />
<Compile Remove="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepositoryInfo.cs" />
<Compile Remove="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepository.mutating.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICommit> Parents => throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IRepositoryStore

IReadOnlyList<ICommit> GetCommitLog(ICommit? baseVersionSource, ICommit currentCommit, IIgnoreConfiguration ignore);
IReadOnlyList<ICommit> GetCommitsReacheableFromHead(ICommit? headCommit, IIgnoreConfiguration ignore);
IReadOnlyList<ICommit> GetCommitsReacheableFrom(IGitObject commit, IBranch branch);
IReadOnlyList<ICommit> GetCommitsReacheableFrom(ICommit commit, IBranch branch);

IBranch GetTargetBranch(string? targetBranchName);
IBranch? FindBranch(ReferenceName branchName);
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.Core/Core/BranchesContainingCommitFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IEnumerable<IBranch> GetBranchesContainingCommit(ICommit commit, IEnumera
return InnerGetBranchesContainingCommit(commit, branches, onlyTrackedBranches);
}

private IEnumerable<IBranch> InnerGetBranchesContainingCommit(IGitObject commit, IEnumerable<IBranch> branches, bool onlyTrackedBranches)
private IEnumerable<IBranch> InnerGetBranchesContainingCommit(ICommit commit, IEnumerable<IBranch> branches, bool onlyTrackedBranches)
{
using (log.IndentLog($"Getting branches containing the commit '{commit.Id}'."))
{
Expand Down Expand Up @@ -63,6 +63,6 @@ private IEnumerable<IBranch> 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;
}
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Core/RepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public IReadOnlyList<ICommit> GetCommitsReacheableFromHead(ICommit? headCommit,
return [.. ignore.Filter(commits)];
}

public IReadOnlyList<ICommit> GetCommitsReacheableFrom(IGitObject commit, IBranch branch)
public IReadOnlyList<ICommit> GetCommitsReacheableFrom(ICommit commit, IBranch branch)
{
var filter = new CommitFilter { IncludeReachableFrom = branch };

Expand Down
5 changes: 4 additions & 1 deletion src/GitVersion.Core/Git/ICommit.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace GitVersion.Git;

public interface ICommit : IEquatable<ICommit?>, IComparable<ICommit>, IGitObject
public interface ICommit : IEquatable<ICommit?>, IComparable<ICommit>
{
IReadOnlyList<ICommit> Parents { get; }

IObjectId Id { get; }
string Sha { get; }

DateTimeOffset When { get; }

string Message { get; }
Expand Down
7 changes: 0 additions & 7 deletions src/GitVersion.Core/Git/IGitObject.cs

This file was deleted.

4 changes: 0 additions & 4 deletions src/GitVersion.Core/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<GitVersion.Git.IBranch!>? branches = null, bool onlyTrackedBranches = false) -> System.Collections.Generic.IEnumerable<GitVersion.Git.IBranch!>!
GitVersion.Common.IRepositoryStore.GetCommitLog(GitVersion.Git.ICommit? baseVersionSource, GitVersion.Git.ICommit! currentCommit, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.IGitObject! commit, GitVersion.Git.IBranch! branch) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFromHead(GitVersion.Git.ICommit? headCommit, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
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?
Expand Down Expand Up @@ -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.ICommit!>!
GitVersion.Git.ICommitCollection.QueryBy(GitVersion.Git.CommitFilter! commitFilter) -> System.Collections.Generic.IEnumerable<GitVersion.Git.ICommit!>!
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!
Expand Down
3 changes: 3 additions & 0 deletions src/GitVersion.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
#nullable enable
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.ICommit! commit, GitVersion.Git.IBranch! branch) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
GitVersion.Git.ICommit.Id.get -> GitVersion.Git.IObjectId!
GitVersion.Git.ICommit.Sha.get -> string!
2 changes: 1 addition & 1 deletion src/GitVersion.LibGit2Sharp/Git/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IReadOnlyCollection<IBranch>>(() => [.. this.innerCollection.Select(branch => repo.GetOrCreate(branch, diff))]);
this.branches = new Lazy<IReadOnlyCollection<IBranch>>(() => [.. this.innerCollection.Select(branch => repo.GetOrWrap(branch, diff))]);
this.diff = diff.NotNull();
this.repo = repo.NotNull();
}

public IEnumerator<IBranch> GetEnumerator()
=> this.branches.Value.GetEnumerator();
public IEnumerator<IBranch> GetEnumerator() => this.branches.Value.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

Expand All @@ -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);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/GitVersion.LibGit2Sharp/Git/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace GitVersion.Git;

internal sealed class Commit : GitObject, ICommit
internal sealed class Commit : ICommit
{
private static readonly ConcurrentDictionary<string, IReadOnlyList<string>> pathsCache = new();
private static readonly LambdaEqualityHelper<ICommit> equalityHelper = new(x => x.Id);
Expand All @@ -14,19 +14,23 @@ 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;
}

public int CompareTo(ICommit? other) => comparerHelper.Compare(this, other);
public bool Equals(ICommit? other) => equalityHelper.Equals(this, other);
public IReadOnlyList<ICommit> Parents => this.parentsLazy.Value;
public IObjectId Id { get; }
public string Sha { get; }
public DateTimeOffset When { get; }
public string Message => this.innerCommit.Message;
public IReadOnlyList<string> DiffPaths
Expand Down
5 changes: 2 additions & 3 deletions src/GitVersion.LibGit2Sharp/Git/CommitCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IReadOnlyCollection<ICommit>>(() => [.. this.innerCollection.Select(commit => repo.GetOrCreate(commit, diff))]);
this.commits = new Lazy<IReadOnlyCollection<ICommit>>(() => [.. this.innerCollection.Select(commit => repo.GetOrWrap(commit, diff))]);
this.diff = diff.NotNull();
this.repo = repo.NotNull();
}

public IEnumerator<ICommit> GetEnumerator()
=> this.commits.Value.GetEnumerator();
public IEnumerator<ICommit> GetEnumerator() => this.commits.Value.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

Expand Down
26 changes: 0 additions & 26 deletions src/GitVersion.LibGit2Sharp/Git/GitObject.cs

This file was deleted.

20 changes: 10 additions & 10 deletions src/GitVersion.LibGit2Sharp/Git/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
}

Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/ReferenceCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public IEnumerator<IReference> 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)
Expand All @@ -23,8 +25,6 @@ public void UpdateTarget(IReference directRef, IObjectId targetId)
this.references = null;
}

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

public IReference? this[string name]
{
get
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.LibGit2Sharp/Git/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/GitVersion.LibGit2Sharp/Git/TagCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ internal TagCollection(LibGit2Sharp.TagCollection collection, LibGit2Sharp.Diff
collection.NotNull();
diff.NotNull();
repo.NotNull();
this.tags = new Lazy<IReadOnlyCollection<ITag>>(() => [.. collection.Select(tag => repo.GetOrCreate(tag, diff))]);
this.tags = new Lazy<IReadOnlyCollection<ITag>>(() => [.. collection.Select(tag => repo.GetOrWrap(tag, diff))]);
}

public IEnumerator<ITag> GetEnumerator()
=> this.tags.Value.GetEnumerator();
public IEnumerator<ITag> GetEnumerator() => this.tags.Value.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}