Skip to content

Commit 457d0a8

Browse files
committed
improves branch/tag cache keys
1 parent 468b70f commit 457d0a8

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/GitVersion.LibGit2Sharp/Git/GitRepository.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,17 @@ public int UncommittedChangesCount()
6565

6666
public Branch GetOrCreate(LibGit2Sharp.Branch innerBranch, Diff repoDiff)
6767
{
68-
if (innerBranch.Tip is null)
69-
{
70-
return new Branch(innerBranch, repoDiff, this);
71-
}
72-
73-
var cacheKey = $"{innerBranch.CanonicalName}|{innerBranch.Tip.Sha}|{innerBranch.RemoteName}";
74-
return cachedBranches.GetOrAdd(cacheKey, new Branch(innerBranch, repoDiff, this));
68+
var cacheKey = innerBranch.Tip is null
69+
? $"{innerBranch.RemoteName}/{innerBranch.CanonicalName}"
70+
: $"{innerBranch.RemoteName}/{innerBranch.CanonicalName}@{innerBranch.Tip.Sha}";
71+
return cachedBranches.GetOrAdd(cacheKey, _ => new Branch(innerBranch, repoDiff, this));
7572
}
7673

77-
public Commit GetOrCreate(LibGit2Sharp.Commit innerCommit, Diff repoDiff) =>
78-
cachedCommits.GetOrAdd(innerCommit.Sha, new Commit(innerCommit, repoDiff, this));
74+
public Commit GetOrCreate(LibGit2Sharp.Commit innerCommit, Diff repoDiff)
75+
=> cachedCommits.GetOrAdd(innerCommit.Sha, _ => new Commit(innerCommit, repoDiff, this));
7976

8077
public Tag GetOrCreate(LibGit2Sharp.Tag innerTag, Diff repoDiff)
81-
{
82-
var cacheKey = $"{innerTag.CanonicalName}|{innerTag.Target.Sha}";
83-
return cachedTags.GetOrAdd(cacheKey, new Tag(innerTag, repoDiff, this));
84-
}
78+
=> cachedTags.GetOrAdd(innerTag.CanonicalName, _ => new Tag(innerTag, repoDiff, this));
8579

8680
public void Dispose()
8781
{

0 commit comments

Comments
 (0)