Skip to content

Commit 3e5eda4

Browse files
committed
Adds type for clarity on usage
1 parent d0ffd63 commit 3e5eda4

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

src/git/cache.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import type { GitUser } from './models/user';
1515
import type { GitWorktree } from './models/worktree';
1616
import type { RemoteProvider } from './remotes/remoteProvider';
1717

18+
type RepoPath = string;
19+
1820
interface RepositoryInfo {
1921
gitDir?: GitDir;
2022
user?: GitUser | null;
@@ -56,65 +58,67 @@ export class GitCache implements Disposable {
5658
return this._useCaching;
5759
}
5860

59-
private _bestRemotesCache: Map<string, Promise<GitRemote<RemoteProvider>[]>> | undefined;
60-
get bestRemotes(): Map<string, Promise<GitRemote<RemoteProvider>[]>> {
61-
return (this._bestRemotesCache ??= new Map<string, Promise<GitRemote<RemoteProvider>[]>>());
61+
private _bestRemotesCache: Map<RepoPath, Promise<GitRemote<RemoteProvider>[]>> | undefined;
62+
get bestRemotes(): Map<RepoPath, Promise<GitRemote<RemoteProvider>[]>> {
63+
return (this._bestRemotesCache ??= new Map<RepoPath, Promise<GitRemote<RemoteProvider>[]>>());
6264
}
6365

64-
private _branchCache: Map<string, Promise<GitBranch | undefined>> | undefined;
65-
get branch(): Map<string, Promise<GitBranch | undefined>> | undefined {
66-
return this.useCaching ? (this._branchCache ??= new Map<string, Promise<GitBranch | undefined>>()) : undefined;
66+
private _branchCache: Map<RepoPath, Promise<GitBranch | undefined>> | undefined;
67+
get branch(): Map<RepoPath, Promise<GitBranch | undefined>> | undefined {
68+
return this.useCaching
69+
? (this._branchCache ??= new Map<RepoPath, Promise<GitBranch | undefined>>())
70+
: undefined;
6771
}
6872

69-
private _branchesCache: Map<string, Promise<PagedResult<GitBranch>>> | undefined;
70-
get branches(): Map<string, Promise<PagedResult<GitBranch>>> | undefined {
73+
private _branchesCache: Map<RepoPath, Promise<PagedResult<GitBranch>>> | undefined;
74+
get branches(): Map<RepoPath, Promise<PagedResult<GitBranch>>> | undefined {
7175
return this.useCaching
72-
? (this._branchesCache ??= new Map<string, Promise<PagedResult<GitBranch>>>())
76+
? (this._branchesCache ??= new Map<RepoPath, Promise<PagedResult<GitBranch>>>())
7377
: undefined;
7478
}
7579

76-
private _contributorsCache: Map<string, Map<string, Promise<GitContributor[]>>> | undefined;
77-
get contributors(): Map<string, Map<string, Promise<GitContributor[]>>> | undefined {
80+
private _contributorsCache: Map<RepoPath, Map<string, Promise<GitContributor[]>>> | undefined;
81+
get contributors(): Map<RepoPath, Map<string, Promise<GitContributor[]>>> | undefined {
7882
return this.useCaching
79-
? (this._contributorsCache ??= new Map<string, Map<string, Promise<GitContributor[]>>>())
83+
? (this._contributorsCache ??= new Map<RepoPath, Map<string, Promise<GitContributor[]>>>())
8084
: undefined;
8185
}
8286

83-
private _pausedOperationStatusCache: Map<string, Promise<GitPausedOperationStatus | undefined>> | undefined;
84-
get pausedOperationStatus(): Map<string, Promise<GitPausedOperationStatus | undefined>> | undefined {
87+
private _pausedOperationStatusCache: Map<RepoPath, Promise<GitPausedOperationStatus | undefined>> | undefined;
88+
get pausedOperationStatus(): Map<RepoPath, Promise<GitPausedOperationStatus | undefined>> | undefined {
8589
return this.useCaching
86-
? (this._pausedOperationStatusCache ??= new Map<string, Promise<GitPausedOperationStatus | undefined>>())
90+
? (this._pausedOperationStatusCache ??= new Map<RepoPath, Promise<GitPausedOperationStatus | undefined>>())
8791
: undefined;
8892
}
8993

90-
private _remotesCache: Map<string, Promise<GitRemote[]>> | undefined;
91-
get remotes(): Map<string, Promise<GitRemote[]>> | undefined {
92-
return this.useCaching ? (this._remotesCache ??= new Map<string, Promise<GitRemote[]>>()) : undefined;
94+
private _remotesCache: Map<RepoPath, Promise<GitRemote[]>> | undefined;
95+
get remotes(): Map<RepoPath, Promise<GitRemote[]>> | undefined {
96+
return this.useCaching ? (this._remotesCache ??= new Map<RepoPath, Promise<GitRemote[]>>()) : undefined;
9397
}
9498

95-
private _repoInfoCache: Map<string, RepositoryInfo> | undefined;
96-
get repoInfo(): Map<string, RepositoryInfo> {
97-
return (this._repoInfoCache ??= new Map<string, RepositoryInfo>());
99+
private _repoInfoCache: Map<RepoPath, RepositoryInfo> | undefined;
100+
get repoInfo(): Map<RepoPath, RepositoryInfo> {
101+
return (this._repoInfoCache ??= new Map<RepoPath, RepositoryInfo>());
98102
}
99103

100-
private _stashesCache: Map<string, GitStash | null> | undefined;
101-
get stashes(): Map<string, GitStash | null> | undefined {
102-
return this.useCaching ? (this._stashesCache ??= new Map<string, GitStash | null>()) : undefined;
104+
private _stashesCache: Map<RepoPath, GitStash | null> | undefined;
105+
get stashes(): Map<RepoPath, GitStash | null> | undefined {
106+
return this.useCaching ? (this._stashesCache ??= new Map<RepoPath, GitStash | null>()) : undefined;
103107
}
104108

105-
private _tagsCache: Map<string, Promise<PagedResult<GitTag>>> | undefined;
106-
get tags(): Map<string, Promise<PagedResult<GitTag>>> | undefined {
107-
return this.useCaching ? (this._tagsCache ??= new Map<string, Promise<PagedResult<GitTag>>>()) : undefined;
109+
private _tagsCache: Map<RepoPath, Promise<PagedResult<GitTag>>> | undefined;
110+
get tags(): Map<RepoPath, Promise<PagedResult<GitTag>>> | undefined {
111+
return this.useCaching ? (this._tagsCache ??= new Map<RepoPath, Promise<PagedResult<GitTag>>>()) : undefined;
108112
}
109113

110114
private _trackedPaths = new PathTrie<PromiseOrValue<[string, string] | undefined>>();
111115
get trackedPaths(): PathTrie<PromiseOrValue<[string, string] | undefined>> {
112116
return this._trackedPaths;
113117
}
114118

115-
private _worktreesCache: Map<string, Promise<GitWorktree[]>> | undefined;
116-
get worktrees(): Map<string, Promise<GitWorktree[]>> | undefined {
117-
return this.useCaching ? (this._worktreesCache ??= new Map<string, Promise<GitWorktree[]>>()) : undefined;
119+
private _worktreesCache: Map<RepoPath, Promise<GitWorktree[]>> | undefined;
120+
get worktrees(): Map<RepoPath, Promise<GitWorktree[]>> | undefined {
121+
return this.useCaching ? (this._worktreesCache ??= new Map<RepoPath, Promise<GitWorktree[]>>()) : undefined;
118122
}
119123

120124
@log({ singleLine: true })

0 commit comments

Comments
 (0)