@@ -7,6 +7,7 @@ namespace GitVersion.Git;
7
7
internal sealed partial class GitRepository
8
8
{
9
9
private Lazy < IRepository > ? repositoryLazy ;
10
+ private readonly GitCache gitCache = new ( ) ;
10
11
11
12
private IRepository RepositoryInstance
12
13
{
@@ -16,17 +17,18 @@ private IRepository RepositoryInstance
16
17
return lazy . Value ;
17
18
}
18
19
}
20
+
19
21
public string Path => RepositoryInstance . Info . Path ;
20
22
public string WorkingDirectory => RepositoryInstance . Info . WorkingDirectory ;
21
23
public bool IsHeadDetached => RepositoryInstance . Info . IsHeadDetached ;
22
24
public bool IsShallow => RepositoryInstance . Info . IsShallow ;
23
- public IBranch Head => new Branch ( RepositoryInstance . Head , RepositoryInstance . Diff ) ;
25
+ public IBranch Head => gitCache . GetOrCreate ( RepositoryInstance . Head , RepositoryInstance . Diff ) ;
24
26
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 ) ;
30
32
31
33
public void DiscoverRepository ( string ? gitDirectory )
32
34
{
@@ -48,7 +50,7 @@ public void DiscoverRepository(string? gitDirectory)
48
50
var first = ( Commit ) commit ;
49
51
var second = ( Commit ) otherCommit ;
50
52
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 ) ;
52
54
} ) ;
53
55
}
54
56
0 commit comments