-
Notifications
You must be signed in to change notification settings - Fork 662
Expand file tree
/
Copy pathCommit.cs
More file actions
40 lines (35 loc) · 1.7 KB
/
Commit.cs
File metadata and controls
40 lines (35 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using GitVersion.Extensions;
using GitVersion.Helpers;
using LibGit2Sharp;
namespace GitVersion.Git;
internal sealed class Commit : GitObject, ICommit
{
private static readonly LambdaEqualityHelper<ICommit> equalityHelper = new(x => x.Id);
private static readonly LambdaKeyComparer<ICommit, string> comparerHelper = new(x => x.Sha);
private readonly Lazy<IReadOnlyList<ICommit>> parentsLazy;
private readonly LibGit2Sharp.Commit innerCommit;
internal Commit(LibGit2Sharp.Commit innerCommit) : base(innerCommit)
{
this.innerCommit = innerCommit.NotNull();
this.parentsLazy = new Lazy<IReadOnlyList<ICommit>>(() => innerCommit.Parents.Select(parent =>
{
ICommit gvCommit;
if (!CommitCollection.s_commits.TryGetValue(parent, out gvCommit))
{
gvCommit = new Commit(parent);
CommitCollection.s_commits.Add(parent, gvCommit);
}
return gvCommit;
}).ToList());
When = innerCommit.Committer.When;
}
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 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;
}