@@ -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 {
@@ -16,17 +17,18 @@ private IRepository RepositoryInstance
1617 return lazy . Value ;
1718 }
1819 }
20+
1921 public string Path => RepositoryInstance . Info . Path ;
2022 public string WorkingDirectory => RepositoryInstance . Info . WorkingDirectory ;
2123 public bool IsHeadDetached => RepositoryInstance . Info . IsHeadDetached ;
2224 public bool IsShallow => RepositoryInstance . Info . IsShallow ;
23- public IBranch Head => new Branch ( RepositoryInstance . Head , RepositoryInstance . Diff ) ;
25+ public IBranch Head => this . gitCache . GetOrCreate ( RepositoryInstance . Head , RepositoryInstance . Diff ) ;
2426
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 ) ;
27+ public ITagCollection Tags => new TagCollection ( RepositoryInstance . Tags , RepositoryInstance . Diff , this . gitCache ) ;
28+ public IReferenceCollection Refs => new ReferenceCollection ( RepositoryInstance . Refs , this . gitCache ) ;
29+ public IBranchCollection Branches => new BranchCollection ( RepositoryInstance . Branches , RepositoryInstance . Diff , this . gitCache ) ;
30+ public ICommitCollection Commits => new CommitCollection ( RepositoryInstance . Commits , RepositoryInstance . Diff , this . gitCache ) ;
31+ public IRemoteCollection Remotes => new RemoteCollection ( RepositoryInstance . Network . Remotes , this . gitCache ) ;
3032
3133 public void DiscoverRepository ( string ? gitDirectory )
3234 {
@@ -48,7 +50,7 @@ public void DiscoverRepository(string? gitDirectory)
4850 var first = ( Commit ) commit ;
4951 var second = ( Commit ) otherCommit ;
5052 var mergeBase = RepositoryInstance . ObjectDatabase . FindMergeBase ( first , second ) ;
51- return mergeBase == null ? null : new Commit ( mergeBase , RepositoryInstance . Diff ) ;
53+ return mergeBase == null ? null : this . gitCache . GetOrCreate ( mergeBase , RepositoryInstance . Diff ) ;
5254 } ) ;
5355 }
5456
0 commit comments