Skip to content

Commit f71242b

Browse files
author
Pascal van Buijtene
committed
WIP
1 parent fa09804 commit f71242b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/GitVersion.LibGit2Sharp/Git/GitCache.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@ internal sealed class GitCache
1010
private static readonly ConcurrentDictionary<string, Remote> cachedRemotes = new();
1111
private static readonly ConcurrentDictionary<string, Tag> cachedTags = new();
1212

13-
public Branch GetOrCreate(LibGit2Sharp.Branch innerBranch, LibGit2Sharp.Diff repoDiff) =>
14-
cachedBranches.GetOrAdd(Guid.NewGuid().ToString(), new Branch(innerBranch, repoDiff, this));
13+
public Branch GetOrCreate(LibGit2Sharp.Branch innerBranch, LibGit2Sharp.Diff repoDiff) {
14+
if (innerBranch.Tip is null)
15+
{
16+
return new Branch(innerBranch, repoDiff, this);
17+
}
18+
return cachedBranches.GetOrAdd($"{innerBranch.CanonicalName}|{innerBranch.Tip.Sha}|{innerBranch.RemoteName}", new Branch(innerBranch, repoDiff, this));
19+
}
1520

1621
public Commit GetOrCreate(LibGit2Sharp.Commit innerCommit, LibGit2Sharp.Diff repoDiff) =>
1722
cachedCommits.GetOrAdd(innerCommit.Sha, new Commit(innerCommit, repoDiff, this));
1823

19-
public Reference GetOrCreate(LibGit2Sharp.Reference innerReference) =>
20-
cachedReferences.GetOrAdd(innerReference.CanonicalName, new Reference(innerReference));
24+
public Reference GetOrCreate(LibGit2Sharp.Reference innerReference) => new Reference(innerReference);
2125

22-
public Remote GetOrCreate(LibGit2Sharp.Remote innerRemote) =>
23-
cachedRemotes.GetOrAdd(innerRemote.Name, new Remote(innerRemote));
26+
public Remote GetOrCreate(LibGit2Sharp.Remote innerRemote) => new Remote(innerRemote);
2427

2528
public Tag GetOrCreate(LibGit2Sharp.Tag innerTag, LibGit2Sharp.Diff repoDiff) =>
26-
cachedTags.GetOrAdd(innerTag.CanonicalName, new Tag(innerTag, repoDiff, this));
29+
cachedTags.GetOrAdd($"{innerTag.CanonicalName}|{innerTag.Target.Sha}", new Tag(innerTag, repoDiff, this));
2730
}

0 commit comments

Comments
 (0)