Skip to content

Commit d0ffd63

Browse files
committed
Renames caches to types in git cache events
1 parent 8b99b7f commit d0ffd63

File tree

9 files changed

+30
-32
lines changed

9 files changed

+30
-32
lines changed

src/env/node/git/localGitProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
982982

983983
try {
984984
await this.git.checkout(repoPath, ref, options);
985-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['branches', 'status'] });
985+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['branches', 'status'] });
986986
} catch (ex) {
987987
const msg: string = ex?.toString() ?? '';
988988
if (/overwritten by checkout/i.test(msg)) {

src/env/node/git/sub-providers/remotes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class RemotesGitSubProvider extends RemotesGitProviderBase implements Git
8080
@log()
8181
async addRemote(repoPath: string, name: string, url: string, options?: { fetch?: boolean }): Promise<void> {
8282
await this.git.exec({ cwd: repoPath }, 'remote', 'add', options?.fetch ? '-f' : undefined, name, url);
83-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['remotes'] });
83+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['remotes'] });
8484
}
8585

8686
@gate()
@@ -100,13 +100,13 @@ export class RemotesGitSubProvider extends RemotesGitProviderBase implements Git
100100
@log()
101101
async pruneRemote(repoPath: string, name: string): Promise<void> {
102102
await this.git.exec({ cwd: repoPath }, 'remote', 'prune', name);
103-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['remotes'] });
103+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['remotes'] });
104104
}
105105

106106
@gate()
107107
@log()
108108
async removeRemote(repoPath: string, name: string): Promise<void> {
109109
await this.git.exec({ cwd: repoPath }, 'remote', 'remove', name);
110-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['remotes'] });
110+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['remotes'] });
111111
}
112112
}

src/env/node/git/sub-providers/stash.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export class StashGitSubProvider implements GitStashSubProvider {
309309
async deleteStash(repoPath: string, stashName: string, sha?: string): Promise<void> {
310310
await this.deleteStashCore(repoPath, stashName, sha);
311311
this.container.events.fire('git:repo:change', { repoPath: repoPath, changes: [RepositoryChange.Stash] });
312-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['stashes'] });
312+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['stashes'] });
313313
}
314314

315315
private async deleteStashCore(repoPath: string, stashName: string, sha?: string): Promise<string | undefined> {
@@ -351,7 +351,7 @@ export class StashGitSubProvider implements GitStashSubProvider {
351351
);
352352

353353
this.container.events.fire('git:repo:change', { repoPath: repoPath, changes: [RepositoryChange.Stash] });
354-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['stashes'] });
354+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['stashes'] });
355355
}
356356

357357
@log<StashGitSubProvider['saveStash']>({ args: { 2: uris => uris?.length } })
@@ -364,7 +364,7 @@ export class StashGitSubProvider implements GitStashSubProvider {
364364
if (!uris?.length) {
365365
await this.git.stash__push(repoPath, message, options);
366366
this.container.events.fire('git:repo:change', { repoPath: repoPath, changes: [RepositoryChange.Stash] });
367-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['stashes', 'status'] });
367+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['stashes', 'status'] });
368368
return;
369369
}
370370

@@ -397,7 +397,7 @@ export class StashGitSubProvider implements GitStashSubProvider {
397397
pathspecs: pathspecs,
398398
stdin: stdin,
399399
});
400-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['stashes', 'status'] });
400+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['stashes', 'status'] });
401401
}
402402

403403
@gate()
@@ -414,6 +414,6 @@ export class StashGitSubProvider implements GitStashSubProvider {
414414
await this.git.exec({ cwd: repoPath }, 'stash', 'store', ...args, id);
415415

416416
this.container.events.fire('git:repo:change', { repoPath: repoPath, changes: [RepositoryChange.Stash] });
417-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['stashes'] });
417+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['stashes'] });
418418
}
419419
}

src/env/node/git/sub-providers/worktrees.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class WorktreesGitSubProvider implements GitWorktreesSubProvider {
5555

5656
this.container.events.fire('git:cache:reset', {
5757
repoPath: repoPath,
58-
caches: options?.createBranch ? ['branches', 'worktrees'] : ['worktrees'],
58+
types: options?.createBranch ? ['branches', 'worktrees'] : ['worktrees'],
5959
});
6060
} catch (ex) {
6161
Logger.error(ex, scope);
@@ -241,7 +241,7 @@ export class WorktreesGitSubProvider implements GitWorktreesSubProvider {
241241

242242
throw new WorktreeDeleteError(undefined, ex);
243243
} finally {
244-
this.container.events.fire('git:cache:reset', { repoPath: repoPath, caches: ['worktrees'] });
244+
this.container.events.fire('git:cache:reset', { repoPath: repoPath, types: ['worktrees'] });
245245
}
246246
}
247247
}

src/eventBus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Disposable, Uri } from 'vscode';
22
import { EventEmitter } from 'vscode';
33
import type { CustomEditorIds, ViewIds, WebviewIds } from './constants.views';
4-
import type { GitCaches } from './git/gitProvider';
4+
import type { CachedGitTypes } from './git/gitProvider';
55
import type { GitCommit } from './git/models/commit';
66
import type { GitRevisionReference } from './git/models/reference';
77
import type { RepositoryChange } from './git/models/repository';
@@ -33,7 +33,7 @@ interface FileSelectedEventArgs {
3333
export type GitCacheResetEvent = EventBusEvent<'git:cache:reset'>;
3434
interface GitCacheResetEventArgs {
3535
readonly repoPath?: string;
36-
readonly caches?: GitCaches[];
36+
readonly types?: CachedGitTypes[];
3737
}
3838

3939
/**

src/git/cache.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { configuration } from '../system/-webview/configuration';
44
import { log } from '../system/decorators/log';
55
import type { PromiseOrValue } from '../system/promise';
66
import { PathTrie } from '../system/trie';
7-
import type { GitCaches, GitDir, PagedResult } from './gitProvider';
7+
import type { CachedGitTypes, GitDir, PagedResult } from './gitProvider';
88
import type { GitBranch } from './models/branch';
99
import type { GitContributor } from './models/contributor';
1010
import type { GitPausedOperationStatus } from './models/pausedOperationStatus';
@@ -41,7 +41,7 @@ export class GitCache implements Disposable {
4141
}
4242
}),
4343
container.events.on('git:cache:reset', e =>
44-
this.clearCaches(e.data.repoPath, ...(e.data.caches ?? emptyArray)),
44+
this.clearCaches(e.data.repoPath, ...(e.data.types ?? emptyArray)),
4545
),
4646
);
4747
}
@@ -118,44 +118,44 @@ export class GitCache implements Disposable {
118118
}
119119

120120
@log({ singleLine: true })
121-
clearCaches(repoPath: string | undefined, ...caches: GitCaches[]): void {
121+
clearCaches(repoPath: string | undefined, ...types: CachedGitTypes[]): void {
122122
const cachesToClear = new Set<Map<string, unknown> | PathTrie<unknown> | undefined>();
123123

124-
if (!caches.length || caches.includes('branches')) {
124+
if (!types.length || types.includes('branches')) {
125125
cachesToClear.add(this._branchCache);
126126
cachesToClear.add(this._branchesCache);
127127
}
128128

129-
if (!caches.length || caches.includes('contributors')) {
129+
if (!types.length || types.includes('contributors')) {
130130
cachesToClear.add(this._contributorsCache);
131131
}
132132

133-
if (!caches.length || caches.includes('remotes')) {
133+
if (!types.length || types.includes('remotes')) {
134134
cachesToClear.add(this._remotesCache);
135135
cachesToClear.add(this._bestRemotesCache);
136136
}
137137

138-
if (!caches.length || caches.includes('providers')) {
138+
if (!types.length || types.includes('providers')) {
139139
cachesToClear.add(this._bestRemotesCache);
140140
}
141141

142-
if (!caches.length || caches.includes('stashes')) {
142+
if (!types.length || types.includes('stashes')) {
143143
cachesToClear.add(this._stashesCache);
144144
}
145145

146-
if (!caches.length || caches.includes('status')) {
146+
if (!types.length || types.includes('status')) {
147147
cachesToClear.add(this._pausedOperationStatusCache);
148148
}
149149

150-
if (!caches.length || caches.includes('tags')) {
150+
if (!types.length || types.includes('tags')) {
151151
cachesToClear.add(this._tagsCache);
152152
}
153153

154-
if (!caches.length || caches.includes('worktrees')) {
154+
if (!types.length || types.includes('worktrees')) {
155155
cachesToClear.add(this._worktreesCache);
156156
}
157157

158-
if (!caches.length) {
158+
if (!types.length) {
159159
cachesToClear.add(this._repoInfoCache);
160160
cachesToClear.add(this._trackedPaths);
161161
}

src/git/gitProvider.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type { RemoteProvider } from './remotes/remoteProvider';
3434
import type { GitGraphSearch } from './search';
3535
import type { BranchSortOptions, TagSortOptions } from './utils/-webview/sorting';
3636

37-
export type GitCaches =
37+
export type CachedGitTypes =
3838
| 'branches'
3939
| 'contributors'
4040
| 'providers'
@@ -43,8 +43,6 @@ export type GitCaches =
4343
| 'status'
4444
| 'tags'
4545
| 'worktrees';
46-
export type GitRepositoryCaches = Extract<GitCaches, 'branches' | 'remotes'>;
47-
export const gitRepositoryCacheKeys = new Set<GitRepositoryCaches>(['branches', 'remotes']);
4846

4947
export interface GitDir {
5048
readonly uri: Uri;

src/git/gitProviderService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import type { Deferred } from '../system/promise';
3939
import { asSettled, defer, getDeferredPromiseIfPending, getSettledValue } from '../system/promise';
4040
import { VisitedPathsTrie } from '../system/trie';
4141
import type {
42+
CachedGitTypes,
4243
GitBranchesSubProvider,
43-
GitCaches,
4444
GitCommitsSubProvider,
4545
GitConfigSubProvider,
4646
GitContributorsSubProvider,
@@ -1352,8 +1352,8 @@ export class GitProviderService implements Disposable {
13521352
}
13531353

13541354
@log({ singleLine: true })
1355-
resetCaches(...caches: GitCaches[]): void {
1356-
this.container.events.fire('git:cache:reset', { caches: caches });
1355+
resetCaches(...types: CachedGitTypes[]): void {
1356+
this.container.events.fire('git:cache:reset', { types: types });
13571357
}
13581358

13591359
@log<GitProviderService['excludeIgnoredUris']>({ args: { 1: uris => uris.length } })

src/git/models/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class Repository implements Disposable {
291291
disposables.push(
292292
this.container.events.on('git:cache:reset', e => {
293293
if (!e.data.repoPath || e.data.repoPath === this.path) {
294-
if (e.data.caches?.includes('providers')) {
294+
if (e.data.types?.includes('providers')) {
295295
this.fireChange(RepositoryChange.RemoteProviders);
296296
}
297297
}

0 commit comments

Comments
 (0)