@@ -7,6 +7,7 @@ namespace GitVersion.Git;
77internal sealed partial class GitRepository
88{
99 private Lazy < IRepository > ? repositoryLazy ;
10+ private readonly GitCache gitCache = new ( ) ;
1011
1112 private IRepository RepositoryInstance
1213 {
@@ -20,13 +21,13 @@ private IRepository RepositoryInstance
2021 public string WorkingDirectory => RepositoryInstance . Info . WorkingDirectory ;
2122 public bool IsHeadDetached => RepositoryInstance . Info . IsHeadDetached ;
2223 public bool IsShallow => RepositoryInstance . Info . IsShallow ;
23- public IBranch Head => new Branch ( RepositoryInstance . Head , RepositoryInstance . Diff ) ;
24+ public IBranch Head => this . gitCache . GetOrCreate ( RepositoryInstance . Head , RepositoryInstance . Diff ) ;
2425
25- public ITagCollection Tags => new TagCollection ( RepositoryInstance . Tags , RepositoryInstance . Diff ) ;
26- public IReferenceCollection Refs => new ReferenceCollection ( RepositoryInstance . Refs ) ;
27- public IBranchCollection Branches => new BranchCollection ( RepositoryInstance . Branches , RepositoryInstance . Diff ) ;
28- public ICommitCollection Commits => new CommitCollection ( RepositoryInstance . Commits , RepositoryInstance . Diff ) ;
29- public IRemoteCollection Remotes => new RemoteCollection ( RepositoryInstance . Network . Remotes ) ;
26+ public ITagCollection Tags => new TagCollection ( RepositoryInstance . Tags , RepositoryInstance . Diff , this . gitCache ) ;
27+ public IReferenceCollection Refs => new ReferenceCollection ( RepositoryInstance . Refs , this . gitCache ) ;
28+ public IBranchCollection Branches => new BranchCollection ( RepositoryInstance . Branches , RepositoryInstance . Diff , this . gitCache ) ;
29+ public ICommitCollection Commits => new CommitCollection ( RepositoryInstance . Commits , RepositoryInstance . Diff , this . gitCache ) ;
30+ public IRemoteCollection Remotes => new RemoteCollection ( RepositoryInstance . Network . Remotes , this . gitCache ) ;
3031
3132 public void DiscoverRepository ( string ? gitDirectory )
3233 {
@@ -48,7 +49,7 @@ public void DiscoverRepository(string? gitDirectory)
4849 var first = ( Commit ) commit ;
4950 var second = ( Commit ) otherCommit ;
5051 var mergeBase = RepositoryInstance . ObjectDatabase . FindMergeBase ( first , second ) ;
51- return mergeBase == null ? null : new Commit ( mergeBase , RepositoryInstance . Diff ) ;
52+ return mergeBase == null ? null : this . gitCache . GetOrCreate ( mergeBase , RepositoryInstance . Diff ) ;
5253 } ) ;
5354 }
5455
0 commit comments