Skip to content
Merged
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
360 changes: 166 additions & 194 deletions src/GitVersion.Core/Core/RepositoryStore.cs

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions src/GitVersion.LibGit2Sharp/Git/Branch.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Extensions;
using GitVersion.Helpers;

namespace GitVersion;
Expand All @@ -11,7 +12,7 @@ internal sealed class Branch : IBranch

internal Branch(LibGit2Sharp.Branch branch)
{
this.innerBranch = branch;
this.innerBranch = branch.NotNull();
Name = new ReferenceName(branch.CanonicalName);

var commit = this.innerBranch.Tip;
Expand All @@ -20,19 +21,17 @@ internal Branch(LibGit2Sharp.Branch branch)
var commits = this.innerBranch.Commits;
Commits = commits is null ? null : new CommitCollection(commits);
}

public ReferenceName Name { get; }
public ICommit? Tip { get; }
public ICommitCollection? Commits { get; }

public int CompareTo(IBranch other) => comparerHelper.Compare(this, other);
public bool Equals(IBranch? other) => equalityHelper.Equals(this, other);
public bool IsDetachedHead => Name.Canonical.Equals("(no branch)", StringComparison.OrdinalIgnoreCase);
public bool IsRemote => this.innerBranch.IsRemote;
public bool IsTracking => this.innerBranch.IsTracking;
public override bool Equals(object obj) => Equals((obj as IBranch));
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => Name.ToString();
public static implicit operator LibGit2Sharp.Branch(Branch d) => d.innerBranch;

public bool IsDetachedHead => Name.Canonical.Equals("(no branch)", StringComparison.OrdinalIgnoreCase);

public bool IsRemote => this.innerBranch.IsRemote;
public bool IsTracking => this.innerBranch.IsTracking;
}
36 changes: 30 additions & 6 deletions src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
using GitVersion.Extensions;
using LibGit2Sharp;

namespace GitVersion;

internal sealed class BranchCollection : IBranchCollection
{
private readonly LibGit2Sharp.BranchCollection innerCollection;
internal BranchCollection(LibGit2Sharp.BranchCollection collection) => this.innerCollection = collection;

public IEnumerator<IBranch> GetEnumerator() => this.innerCollection.Select(branch => new Branch(branch)).GetEnumerator();
internal BranchCollection(LibGit2Sharp.BranchCollection collection)
=> this.innerCollection = collection.NotNull();

public IEnumerator<IBranch> GetEnumerator()
=> this.innerCollection.Select(branch => new Branch(branch)).GetEnumerator();

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

public IBranch? this[string name]
{
get
{
name = name.NotNull();
var branch = this.innerCollection[name];
return branch is null ? null : new Branch(branch);
}
}

public IEnumerable<IBranch> ExcludeBranches(IEnumerable<IBranch> branchesToExclude) =>
this.Where(b => branchesToExclude.All(bte => !b.Equals(bte)));
public void UpdateTrackedBranch(IBranch branch, string remoteTrackingReferenceName) =>
this.innerCollection.Update((Branch)branch, b => b.TrackedBranch = remoteTrackingReferenceName);
public IEnumerable<IBranch> ExcludeBranches(IEnumerable<IBranch> branchesToExclude)
{
branchesToExclude = branchesToExclude.NotNull();

bool BranchIsNotExcluded(IBranch branch)
=> branchesToExclude.All(branchToExclude => !branch.Equals(branchToExclude));

return this.Where(BranchIsNotExcluded);
}

public void UpdateTrackedBranch(IBranch branch, string remoteTrackingReferenceName)
{
var branchToUpdate = (Branch)branch.NotNull();

void Updater(BranchUpdater branchUpdater) =>
branchUpdater.TrackedBranch = remoteTrackingReferenceName;

this.innerCollection.Update(branchToUpdate, Updater);
}
}
11 changes: 5 additions & 6 deletions src/GitVersion.LibGit2Sharp/Git/Commit.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Extensions;
using GitVersion.Helpers;

namespace GitVersion;
Expand All @@ -11,20 +12,18 @@ internal sealed class Commit : GitObject, ICommit

internal Commit(LibGit2Sharp.Commit innerCommit) : base(innerCommit)
{
this.innerCommit = innerCommit;
this.innerCommit = innerCommit.NotNull();
Parents = innerCommit.Parents.Select(parent => new Commit(parent));
When = innerCommit.Committer.When;
}

public int CompareTo(ICommit other) => comparerHelper.Compare(this, other);
public bool Equals(ICommit? other) => equalityHelper.Equals(this, other);
public IEnumerable<ICommit> Parents { get; }
public DateTimeOffset When { get; }
public string Message => this.innerCommit.Message;
public override bool Equals(object obj) => Equals((obj as ICommit));
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => $"{Id.ToString(7)} {this.innerCommit.MessageShort}";
public static implicit operator LibGit2Sharp.Commit(Commit d) => d.innerCommit;

public IEnumerable<ICommit> Parents { get; }
public DateTimeOffset When { get; }

public string Message => this.innerCommit.Message;
}
19 changes: 9 additions & 10 deletions src/GitVersion.LibGit2Sharp/Git/CommitCollection.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
using GitVersion.Extensions;
using LibGit2Sharp;

namespace GitVersion;

internal sealed class CommitCollection : ICommitCollection
{
private readonly ICommitLog innerCollection;
internal CommitCollection(ICommitLog collection) => this.innerCollection = collection;

public IEnumerator<ICommit> GetEnumerator() => this.innerCollection.Select(commit => new Commit(commit)).GetEnumerator();
internal CommitCollection(ICommitLog collection) => this.innerCollection = collection.NotNull();

public IEnumerator<ICommit> GetEnumerator()
=> this.innerCollection.Select(commit => new Commit(commit)).GetEnumerator();

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

public IEnumerable<ICommit> GetCommitsPriorTo(DateTimeOffset olderThan) => this.SkipWhile(c => c.When > olderThan);
public IEnumerable<ICommit> GetCommitsPriorTo(DateTimeOffset olderThan)
=> this.SkipWhile(c => c.When > olderThan);

public IEnumerable<ICommit> QueryBy(CommitFilter commitFilter)
{
static object? GetReacheableFrom(object? item) =>
Expand All @@ -24,13 +29,7 @@ public IEnumerable<ICommit> QueryBy(CommitFilter commitFilter)

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 filter = new LibGit2Sharp.CommitFilter { IncludeReachableFrom = includeReachableFrom, ExcludeReachableFrom = excludeReachableFrom, FirstParentOnly = commitFilter.FirstParentOnly, SortBy = (LibGit2Sharp.CommitSortStrategies)commitFilter.SortBy };
var commitLog = ((IQueryableCommitLog)this.innerCollection).QueryBy(filter);
return new CommitCollection(commitLog);
}
Expand Down
2 changes: 2 additions & 0 deletions src/GitVersion.LibGit2Sharp/Git/GitObject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GitVersion.Extensions;
using GitVersion.Helpers;

namespace GitVersion;
Expand All @@ -9,6 +10,7 @@ internal class GitObject : IGitObject

internal GitObject(LibGit2Sharp.GitObject innerGitObject)
{
innerGitObject = innerGitObject.NotNull();
Id = new ObjectId(innerGitObject.Id);
Sha = innerGitObject.Sha;
}
Expand Down
Loading