Skip to content

Commit 3316a64

Browse files
committed
Apply memory patch
1 parent 74ac886 commit 3316a64

File tree

6 files changed

+122
-34
lines changed

6 files changed

+122
-34
lines changed

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"src"
66
],
77
"sdk": {
8-
"version": "9.0.203"
8+
"version": "9.0.300"
99
}
1010
}

src/GitVersion.App/GitVersion.App.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<AssemblyName>gitversion</AssemblyName>
77
<PlatformTarget>AnyCPU</PlatformTarget>
88
<PackageLicenseExpression>MIT</PackageLicenseExpression>
9+
<PublishSingleFile>true</PublishSingleFile>
10+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
911
</PropertyGroup>
1012

1113
<PropertyGroup Condition=" '$(PackAsTool)' == 'true' ">

src/GitVersion.Core/Core/RepositoryStore.cs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,52 +116,67 @@ public IEnumerable<IBranch> GetSourceBranches(
116116
var commitBranches = FindCommitBranchesBranchedFrom(branch, configuration, excludedBranches).ToHashSet();
117117

118118
var ignore = new HashSet<BranchCommit>();
119-
foreach (var commitBranch in commitBranches)
119+
using (this.log.IndentLog($"Finding ignore branches"))
120120
{
121-
foreach (var commit in branch.Commits.Where(element => element.When > commitBranch.Commit.When))
121+
foreach (var commitBranch in commitBranches)
122122
{
123-
var parents = commit.Parents.ToArray();
124-
if (parents.Length > 1 && parents.Any(element => element.Equals(commitBranch.Commit)))
123+
foreach (var commit in branch.Commits.Where(element => element.When > commitBranch.Commit.When))
125124
{
126-
ignore.Add(commitBranch);
125+
var parents = commit.Parents.ToArray();
126+
if (parents.Length > 1 && parents.Any(element => element.Equals(commitBranch.Commit)))
127+
{
128+
ignore.Add(commitBranch);
129+
}
127130
}
128131
}
129132
}
130133

131-
foreach (var item in commitBranches.Skip(1).Reverse())
134+
using (this.log.IndentLog($"Filtering out branches"))
132135
{
133-
if (ignore.Contains(item)) continue;
136+
IEnumerable<BranchCommit> commitBranchesReversed = new List<BranchCommit>();
137+
using (this.log.IndentLog($"Reverse commit branches"))
138+
{
139+
commitBranchesReversed = commitBranches.Skip(1).Reverse();
140+
}
134141

135-
foreach (var commitBranch in commitBranches)
142+
foreach (var item in commitBranchesReversed)
136143
{
137-
if (item.Commit.Equals(commitBranch.Commit)) break;
144+
if (ignore.Contains(item)) continue;
138145

139-
foreach (var commit in commitBranch.Branch.Commits.Where(element => element.When >= item.Commit.When))
146+
foreach (var commitBranch in commitBranches)
140147
{
141-
if (commit.Equals(item.Commit))
148+
if (item.Commit.Equals(commitBranch.Commit)) break;
149+
150+
foreach (var commit in commitBranch.Branch.Commits.Where(element => element.When >= item.Commit.When))
142151
{
143-
commitBranches.Remove(item);
152+
if (commit.Equals(item.Commit))
153+
{
154+
commitBranches.Remove(item);
155+
}
144156
}
145157
}
146158
}
147159
}
148160

149-
foreach (var branchGrouping in commitBranches.GroupBy(element => element.Commit, element => element.Branch))
161+
using (this.log.IndentLog($"Iterate grouped branches by commit"))
150162
{
151-
var referenceMatchFound = false;
152-
var referenceNames = referenceLookup[branchGrouping.Key.Sha].Select(element => element.Name).ToHashSet();
153-
154-
foreach (var item in branchGrouping)
163+
foreach (var branchGrouping in commitBranches.GroupBy(element => element.Commit, element => element.Branch))
155164
{
156-
if (!referenceNames.Contains(item.Name)) continue;
157-
if (returnedBranches.Add(item)) yield return item;
158-
referenceMatchFound = true;
159-
}
165+
var referenceMatchFound = false;
166+
var referenceNames = referenceLookup[branchGrouping.Key.Sha].Select(element => element.Name).ToHashSet();
160167

161-
if (referenceMatchFound) continue;
162-
foreach (var item in branchGrouping)
163-
{
164-
if (returnedBranches.Add(item)) yield return item;
168+
foreach (var item in branchGrouping)
169+
{
170+
if (!referenceNames.Contains(item.Name)) continue;
171+
if (returnedBranches.Add(item)) yield return item;
172+
referenceMatchFound = true;
173+
}
174+
175+
if (referenceMatchFound) continue;
176+
foreach (var item in branchGrouping)
177+
{
178+
if (returnedBranches.Add(item)) yield return item;
179+
}
165180
}
166181
}
167182
}

src/GitVersion.LibGit2Sharp/Git/Commit.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using GitVersion.Extensions;
22
using GitVersion.Helpers;
3+
using LibGit2Sharp;
34

45
namespace GitVersion.Git;
56

@@ -14,7 +15,16 @@ internal sealed class Commit : GitObject, ICommit
1415
internal Commit(LibGit2Sharp.Commit innerCommit) : base(innerCommit)
1516
{
1617
this.innerCommit = innerCommit.NotNull();
17-
this.parentsLazy = new(() => innerCommit.Parents.Select(parent => new Commit(parent)).ToList());
18+
this.parentsLazy = new Lazy<IReadOnlyList<ICommit>>(() => innerCommit.Parents.Select(parent =>
19+
{
20+
ICommit gvCommit;
21+
if (!CommitCollection.s_commits.TryGetValue(parent, out gvCommit))
22+
{
23+
gvCommit = new Commit(parent);
24+
CommitCollection.s_commits.Add(parent, gvCommit);
25+
}
26+
return gvCommit;
27+
}).ToList());
1828
When = innerCommit.Committer.When;
1929
}
2030

src/GitVersion.LibGit2Sharp/Git/CommitCollection.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,31 @@ namespace GitVersion.Git;
55

66
internal sealed class CommitCollection : ICommitCollection
77
{
8+
public static Dictionary<LibGit2Sharp.Commit, ICommit> s_commits = new Dictionary<LibGit2Sharp.Commit, ICommit>();
9+
810
private readonly ICommitLog innerCollection;
911
private readonly Lazy<IReadOnlyCollection<ICommit>> commits;
1012

1113
internal CommitCollection(ICommitLog collection)
1214
{
1315
this.innerCollection = collection.NotNull();
14-
this.commits = new Lazy<IReadOnlyCollection<ICommit>>(() => [.. this.innerCollection.Select(commit => new Commit(commit))]);
16+
this.commits = new Lazy<IReadOnlyCollection<ICommit>>(() => {
17+
List<ICommit> commits = new List<ICommit>();
18+
foreach (var c in this.innerCollection) {
19+
ICommit gvCommit;
20+
if (s_commits.TryGetValue(c, out gvCommit))
21+
{
22+
commits.Add(gvCommit);
23+
}
24+
else
25+
{
26+
gvCommit = new Commit(c);
27+
commits.Add(gvCommit);
28+
s_commits[c] = gvCommit;
29+
}
30+
}
31+
return commits;
32+
});
1533
}
1634

1735
public IEnumerator<ICommit> GetEnumerator()

src/GitVersion.LibGit2Sharp/Git/GitRepository.cs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,56 @@ private IRepository RepositoryInstance
2121
public string WorkingDirectory => RepositoryInstance.Info.WorkingDirectory;
2222
public bool IsHeadDetached => RepositoryInstance.Info.IsHeadDetached;
2323
public bool IsShallow => RepositoryInstance.Info.IsShallow;
24-
public IBranch Head => new Branch(RepositoryInstance.Head);
2524

26-
public ITagCollection Tags => new TagCollection(RepositoryInstance.Tags);
27-
public IReferenceCollection Refs => new ReferenceCollection(RepositoryInstance.Refs);
28-
public IBranchCollection Branches => new BranchCollection(RepositoryInstance.Branches);
29-
public ICommitCollection Commits => new CommitCollection(RepositoryInstance.Commits);
30-
public IRemoteCollection Remotes => new RemoteCollection(RepositoryInstance.Network.Remotes);
25+
private IBranch _head = null;
26+
public IBranch Head {
27+
get {
28+
_head ??= new Branch(RepositoryInstance.Head);
29+
return _head;
30+
}
31+
}
32+
33+
private ITagCollection _tags = null;
34+
public ITagCollection Tags {
35+
get {
36+
_tags ??= new TagCollection(RepositoryInstance.Tags);
37+
return _tags;
38+
}
39+
}
40+
41+
private IReferenceCollection _refs = null;
42+
public IReferenceCollection Refs {
43+
get {
44+
_refs ??= new ReferenceCollection(RepositoryInstance.Refs);
45+
return _refs;
46+
}
47+
}
48+
49+
private IBranchCollection _branches = null;
50+
public IBranchCollection Branches {
51+
get {
52+
_branches ??= new BranchCollection(RepositoryInstance.Branches);
53+
return _branches;
54+
}
55+
}
56+
57+
private ICommitCollection _commits = null;
58+
public ICommitCollection Commits
59+
{
60+
get
61+
{
62+
_commits ??= new CommitCollection(RepositoryInstance.Commits);
63+
return _commits;
64+
}
65+
}
66+
67+
public IRemoteCollection _remotes = null;
68+
public IRemoteCollection Remotes {
69+
get {
70+
_remotes ??= new RemoteCollection(RepositoryInstance.Network.Remotes);
71+
return _remotes;
72+
}
73+
}
3174

3275
public void DiscoverRepository(string? gitDirectory)
3376
{

0 commit comments

Comments
 (0)