Skip to content

Commit 501a75f

Browse files
committed
caches git objects
Renames `GetOrCreate` to `GetOrWrap` to better reflect its caching behavior.
1 parent f9e44b0 commit 501a75f

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

src/GitVersion.LibGit2Sharp/Git/Branch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal Branch(LibGit2Sharp.Branch branch, LibGit2Sharp.Diff diff, GitRepositor
1818
Name = new(branch.CanonicalName);
1919

2020
var commit = this.innerBranch.Tip;
21-
Tip = commit is null ? null : repo.GetOrCreate(commit, diff);
21+
Tip = commit is null ? null : repo.GetOrWrap(commit, diff);
2222

2323
var commits = this.innerBranch.Commits;
2424
Commits = new CommitCollection(commits, diff, repo);

src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal sealed class BranchCollection : IBranchCollection
1313
internal BranchCollection(LibGit2Sharp.BranchCollection collection, Diff diff, GitRepository repo)
1414
{
1515
this.innerCollection = collection.NotNull();
16-
this.branches = new Lazy<IReadOnlyCollection<IBranch>>(() => [.. this.innerCollection.Select(branch => repo.GetOrCreate(branch, diff))]);
16+
this.branches = new Lazy<IReadOnlyCollection<IBranch>>(() => [.. this.innerCollection.Select(branch => repo.GetOrWrap(branch, diff))]);
1717
this.diff = diff.NotNull();
1818
this.repo = repo.NotNull();
1919
}
@@ -28,7 +28,7 @@ public IBranch? this[string name]
2828
{
2929
name = name.NotNull();
3030
var branch = this.innerCollection[name];
31-
return branch is null ? null : this.repo.GetOrCreate(branch, this.diff);
31+
return branch is null ? null : this.repo.GetOrWrap(branch, this.diff);
3232
}
3333
}
3434

src/GitVersion.LibGit2Sharp/Git/Commit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal Commit(LibGit2Sharp.Commit innerCommit, LibGit2Sharp.Diff repoDiff, Git
1919
repoDiff.NotNull();
2020
repo.NotNull();
2121
this.innerCommit = innerCommit.NotNull();
22-
this.parentsLazy = new(() => innerCommit.Parents.Select(parent => repo.GetOrCreate(parent, repoDiff)).ToList());
22+
this.parentsLazy = new(() => innerCommit.Parents.Select(parent => repo.GetOrWrap(parent, repoDiff)).ToList());
2323
When = innerCommit.Committer.When;
2424
this.repoDiff = repoDiff;
2525
}

src/GitVersion.LibGit2Sharp/Git/CommitCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal sealed class CommitCollection : ICommitCollection
1313
internal CommitCollection(ICommitLog collection, Diff diff, GitRepository repo)
1414
{
1515
this.innerCollection = collection.NotNull();
16-
this.commits = new Lazy<IReadOnlyCollection<ICommit>>(() => [.. this.innerCollection.Select(commit => repo.GetOrCreate(commit, diff))]);
16+
this.commits = new Lazy<IReadOnlyCollection<ICommit>>(() => [.. this.innerCollection.Select(commit => repo.GetOrWrap(commit, diff))]);
1717
this.diff = diff.NotNull();
1818
this.repo = repo.NotNull();
1919
}

src/GitVersion.LibGit2Sharp/Git/GitRepository.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private IRepository RepositoryInstance
2525
public string WorkingDirectory => RepositoryInstance.Info.WorkingDirectory;
2626
public bool IsHeadDetached => RepositoryInstance.Info.IsHeadDetached;
2727
public bool IsShallow => RepositoryInstance.Info.IsShallow;
28-
public IBranch Head => GetOrCreate(RepositoryInstance.Head, RepositoryInstance.Diff);
28+
public IBranch Head => GetOrWrap(RepositoryInstance.Head, RepositoryInstance.Diff);
2929

3030
public ITagCollection Tags => new TagCollection(RepositoryInstance.Tags, RepositoryInstance.Diff, this);
3131
public IReferenceCollection Refs => new ReferenceCollection(RepositoryInstance.Refs);
@@ -53,7 +53,7 @@ public void DiscoverRepository(string? gitDirectory)
5353
var first = (Commit)commit;
5454
var second = (Commit)otherCommit;
5555
var mergeBase = RepositoryInstance.ObjectDatabase.FindMergeBase(first, second);
56-
return mergeBase == null ? null : GetOrCreate(mergeBase, RepositoryInstance.Diff);
56+
return mergeBase == null ? null : GetOrWrap(mergeBase, RepositoryInstance.Diff);
5757
});
5858
}
5959

@@ -63,7 +63,7 @@ public int UncommittedChangesCount()
6363
return retryAction.Execute(GetUncommittedChangesCountInternal);
6464
}
6565

66-
public Branch GetOrCreate(LibGit2Sharp.Branch innerBranch, Diff repoDiff)
66+
public Branch GetOrWrap(LibGit2Sharp.Branch innerBranch, Diff repoDiff)
6767
{
6868
if (innerBranch.Tip is null)
6969
{
@@ -74,10 +74,10 @@ public Branch GetOrCreate(LibGit2Sharp.Branch innerBranch, Diff repoDiff)
7474
return cachedBranches.GetOrAdd(cacheKey, _ => new Branch(innerBranch, repoDiff, this));
7575
}
7676

77-
public Commit GetOrCreate(LibGit2Sharp.Commit innerCommit, Diff repoDiff) =>
77+
public Commit GetOrWrap(LibGit2Sharp.Commit innerCommit, Diff repoDiff) =>
7878
cachedCommits.GetOrAdd(innerCommit.Sha, _ => new Commit(innerCommit, repoDiff, this));
7979

80-
public Tag GetOrCreate(LibGit2Sharp.Tag innerTag, Diff repoDiff)
80+
public Tag GetOrWrap(LibGit2Sharp.Tag innerTag, Diff repoDiff)
8181
{
8282
var cacheKey = $"{innerTag.CanonicalName}@{innerTag.Target.Sha}";
8383
return cachedTags.GetOrAdd(cacheKey, _ => new Tag(innerTag, repoDiff, this));

src/GitVersion.LibGit2Sharp/Git/Tag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal Tag(LibGit2Sharp.Tag tag, Diff diff, GitRepository repo)
3737
target = annotation.Target;
3838
}
3939

40-
return target is LibGit2Sharp.Commit commit ? this.repo.GetOrCreate(commit, this.diff) : null;
40+
return target is LibGit2Sharp.Commit commit ? this.repo.GetOrWrap(commit, this.diff) : null;
4141
}
4242

4343
public override bool Equals(object? obj) => Equals(obj as ITag);

src/GitVersion.LibGit2Sharp/Git/TagCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal TagCollection(LibGit2Sharp.TagCollection collection, LibGit2Sharp.Diff
1111
collection.NotNull();
1212
diff.NotNull();
1313
repo.NotNull();
14-
this.tags = new Lazy<IReadOnlyCollection<ITag>>(() => [.. collection.Select(tag => repo.GetOrCreate(tag, diff))]);
14+
this.tags = new Lazy<IReadOnlyCollection<ITag>>(() => [.. collection.Select(tag => repo.GetOrWrap(tag, diff))]);
1515
}
1616

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

0 commit comments

Comments
 (0)