Skip to content

Commit b20bb3e

Browse files
committed
Introduced a new reusable BooleanOverride Enum for GitRepoState, instead of having individual enums with identical semantics.
1 parent 103530b commit b20bb3e

File tree

6 files changed

+88
-112
lines changed

6 files changed

+88
-112
lines changed

src/extensionState.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs';
22
import * as vscode from 'vscode';
33
import { Avatar, AvatarCache } from './avatarManager';
44
import { getConfig } from './config';
5-
import { CodeReview, ErrorInfo, FileViewType, GitGraphViewGlobalState, GitRepoSet, GitRepoState, IncludeCommitsMentionedByReflogs, OnlyFollowFirstParent, RepoCommitOrdering, ShowCheckedOutBranch, ShowRemoteBranches, ShowTags } from './types';
5+
import { BooleanOverride, CodeReview, ErrorInfo, FileViewType, GitGraphViewGlobalState, GitRepoSet, GitRepoState, RepoCommitOrdering } from './types';
66
import { GitExecutable, getPathFromStr } from './utils';
77
import { Disposable } from './utils/disposable';
88
import { Event } from './utils/event';
@@ -23,16 +23,16 @@ export const DEFAULT_REPO_STATE: GitRepoState = {
2323
commitOrdering: RepoCommitOrdering.Default,
2424
fileViewType: FileViewType.Default,
2525
hideRemotes: [],
26-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
26+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
2727
issueLinkingConfig: null,
2828
name: null,
29-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
30-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
29+
onlyFollowFirstParent: BooleanOverride.Default,
30+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
3131
onRepoLoadShowSpecificBranches: null,
3232
pullRequestConfig: null,
3333
showRemoteBranches: true,
34-
showRemoteBranchesV2: ShowRemoteBranches.Default,
35-
showTags: ShowTags.Default
34+
showRemoteBranchesV2: BooleanOverride.Default,
35+
showTags: BooleanOverride.Default
3636
};
3737

3838
const DEFAULT_GLOBAL_VIEW_STATE: GitGraphViewGlobalState = {
@@ -107,7 +107,7 @@ export class ExtensionState extends Disposable {
107107
showRemoteBranchesDefaultValue = getConfig().showRemoteBranches;
108108
}
109109
if (repoSet[repo].showRemoteBranches !== showRemoteBranchesDefaultValue) {
110-
outputSet[repo].showRemoteBranchesV2 = repoSet[repo].showRemoteBranches ? ShowRemoteBranches.Show : ShowRemoteBranches.Hide;
110+
outputSet[repo].showRemoteBranchesV2 = repoSet[repo].showRemoteBranches ? BooleanOverride.Enabled : BooleanOverride.Disabled;
111111
}
112112
}
113113
});

src/types.ts

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,16 @@ export interface GitRepoState {
184184
commitOrdering: RepoCommitOrdering;
185185
fileViewType: FileViewType;
186186
hideRemotes: string[];
187-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs;
187+
includeCommitsMentionedByReflogs: BooleanOverride;
188188
issueLinkingConfig: IssueLinkingConfig | null;
189189
name: string | null;
190-
onlyFollowFirstParent: OnlyFollowFirstParent;
191-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch;
190+
onlyFollowFirstParent: BooleanOverride;
191+
onRepoLoadShowCheckedOutBranch: BooleanOverride;
192192
onRepoLoadShowSpecificBranches: string[] | null;
193193
pullRequestConfig: PullRequestConfig | null;
194194
showRemoteBranches: boolean;
195-
showRemoteBranchesV2: ShowRemoteBranches;
196-
showTags: ShowTags;
195+
showRemoteBranchesV2: BooleanOverride;
196+
showTags: BooleanOverride;
197197
}
198198

199199

@@ -293,6 +293,12 @@ export interface ReferenceLabelsConfig {
293293

294294
/* Extension Settings Types */
295295

296+
export const enum BooleanOverride {
297+
Default,
298+
Enabled,
299+
Disabled
300+
}
301+
296302
export const enum CommitDetailsViewLocation {
297303
Inline,
298304
DockedToBottom
@@ -464,24 +470,6 @@ export const enum GraphUncommittedChangesStyle {
464470
OpenCircleAtTheCheckedOutCommit
465471
}
466472

467-
export const enum IncludeCommitsMentionedByReflogs {
468-
Default,
469-
Enabled,
470-
Disabled
471-
}
472-
473-
export const enum OnlyFollowFirstParent {
474-
Default,
475-
Enabled,
476-
Disabled
477-
}
478-
479-
export const enum ShowCheckedOutBranch {
480-
Default,
481-
Enabled,
482-
Disabled
483-
}
484-
485473
export const enum RefLabelAlignment {
486474
Normal,
487475
BranchesOnLeftAndTagsOnRight,
@@ -500,18 +488,6 @@ export const enum RepoDropdownOrder {
500488
Name
501489
}
502490

503-
export const enum ShowRemoteBranches {
504-
Default,
505-
Show,
506-
Hide
507-
}
508-
509-
export const enum ShowTags {
510-
Default,
511-
Show,
512-
Hide
513-
}
514-
515491
export const enum SquashMessageFormat {
516492
Default,
517493
GitSquashMsg

tests/extensionState.test.ts

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jest.mock('fs');
55

66
import * as fs from 'fs';
77
import { ExtensionState } from '../src/extensionState';
8-
import { FileViewType, GitGraphViewGlobalState, IncludeCommitsMentionedByReflogs, OnlyFollowFirstParent, RepoCommitOrdering, ShowCheckedOutBranch, ShowRemoteBranches, ShowTags } from '../src/types';
8+
import { BooleanOverride, FileViewType, GitGraphViewGlobalState, RepoCommitOrdering } from '../src/types';
99
import { GitExecutable } from '../src/utils';
1010
import { EventEmitter } from '../src/utils/event';
1111

@@ -63,16 +63,16 @@ describe('ExtensionState', () => {
6363
commitOrdering: RepoCommitOrdering.AuthorDate,
6464
fileViewType: FileViewType.List,
6565
hideRemotes: [],
66-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Enabled,
66+
includeCommitsMentionedByReflogs: BooleanOverride.Enabled,
6767
issueLinkingConfig: null,
6868
name: 'Custom Name',
69-
onlyFollowFirstParent: OnlyFollowFirstParent.Disabled,
70-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Enabled,
69+
onlyFollowFirstParent: BooleanOverride.Disabled,
70+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Enabled,
7171
onRepoLoadShowSpecificBranches: ['master'],
7272
pullRequestConfig: null,
7373
showRemoteBranches: true,
74-
showRemoteBranchesV2: ShowRemoteBranches.Show,
75-
showTags: ShowTags.Show
74+
showRemoteBranchesV2: BooleanOverride.Enabled,
75+
showTags: BooleanOverride.Enabled
7676
};
7777
extensionContext.workspaceState.get.mockReturnValueOnce({
7878
'/path/to/repo': repoState
@@ -108,16 +108,16 @@ describe('ExtensionState', () => {
108108
commitOrdering: RepoCommitOrdering.Default,
109109
fileViewType: FileViewType.Default,
110110
hideRemotes: [],
111-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
111+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
112112
issueLinkingConfig: null,
113113
name: null,
114-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
115-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
114+
onlyFollowFirstParent: BooleanOverride.Default,
115+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
116116
onRepoLoadShowSpecificBranches: null,
117117
pullRequestConfig: null,
118118
showRemoteBranches: true,
119-
showRemoteBranchesV2: ShowRemoteBranches.Default,
120-
showTags: ShowTags.Default
119+
showRemoteBranchesV2: BooleanOverride.Default,
120+
showTags: BooleanOverride.Default
121121
}
122122
});
123123
});
@@ -143,16 +143,16 @@ describe('ExtensionState', () => {
143143
commitOrdering: RepoCommitOrdering.Default,
144144
fileViewType: FileViewType.Default,
145145
hideRemotes: [],
146-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
146+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
147147
issueLinkingConfig: null,
148148
name: null,
149-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
150-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
149+
onlyFollowFirstParent: BooleanOverride.Default,
150+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
151151
onRepoLoadShowSpecificBranches: null,
152152
pullRequestConfig: null,
153153
showRemoteBranches: true,
154-
showRemoteBranchesV2: ShowRemoteBranches.Default,
155-
showTags: ShowTags.Default
154+
showRemoteBranchesV2: BooleanOverride.Default,
155+
showTags: BooleanOverride.Default
156156
}
157157
});
158158
});
@@ -178,16 +178,16 @@ describe('ExtensionState', () => {
178178
commitOrdering: RepoCommitOrdering.Default,
179179
fileViewType: FileViewType.Default,
180180
hideRemotes: [],
181-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
181+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
182182
issueLinkingConfig: null,
183183
name: null,
184-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
185-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
184+
onlyFollowFirstParent: BooleanOverride.Default,
185+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
186186
onRepoLoadShowSpecificBranches: null,
187187
pullRequestConfig: null,
188188
showRemoteBranches: false,
189-
showRemoteBranchesV2: ShowRemoteBranches.Hide,
190-
showTags: ShowTags.Default
189+
showRemoteBranchesV2: BooleanOverride.Disabled,
190+
showTags: BooleanOverride.Default
191191
}
192192
});
193193
});
@@ -213,16 +213,16 @@ describe('ExtensionState', () => {
213213
commitOrdering: RepoCommitOrdering.Default,
214214
fileViewType: FileViewType.Default,
215215
hideRemotes: [],
216-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
216+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
217217
issueLinkingConfig: null,
218218
name: null,
219-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
220-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
219+
onlyFollowFirstParent: BooleanOverride.Default,
220+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
221221
onRepoLoadShowSpecificBranches: null,
222222
pullRequestConfig: null,
223223
showRemoteBranches: false,
224-
showRemoteBranchesV2: ShowRemoteBranches.Default,
225-
showTags: ShowTags.Default
224+
showRemoteBranchesV2: BooleanOverride.Default,
225+
showTags: BooleanOverride.Default
226226
}
227227
});
228228
});
@@ -248,16 +248,16 @@ describe('ExtensionState', () => {
248248
commitOrdering: RepoCommitOrdering.Default,
249249
fileViewType: FileViewType.Default,
250250
hideRemotes: [],
251-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
251+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
252252
issueLinkingConfig: null,
253253
name: null,
254-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
255-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
254+
onlyFollowFirstParent: BooleanOverride.Default,
255+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
256256
onRepoLoadShowSpecificBranches: null,
257257
pullRequestConfig: null,
258258
showRemoteBranches: true,
259-
showRemoteBranchesV2: ShowRemoteBranches.Show,
260-
showTags: ShowTags.Default
259+
showRemoteBranchesV2: BooleanOverride.Enabled,
260+
showTags: BooleanOverride.Default
261261
}
262262
});
263263
});
@@ -286,16 +286,16 @@ describe('ExtensionState', () => {
286286
commitOrdering: RepoCommitOrdering.Default,
287287
fileViewType: FileViewType.Default,
288288
hideRemotes: [],
289-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
289+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
290290
issueLinkingConfig: null,
291291
name: null,
292-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
293-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
292+
onlyFollowFirstParent: BooleanOverride.Default,
293+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
294294
onRepoLoadShowSpecificBranches: null,
295295
pullRequestConfig: null,
296296
showRemoteBranches: true,
297-
showRemoteBranchesV2: ShowRemoteBranches.Default,
298-
showTags: ShowTags.Default
297+
showRemoteBranchesV2: BooleanOverride.Default,
298+
showTags: BooleanOverride.Default
299299
},
300300
'/path/to/repo-2': {
301301
cdvDivider: 0.5,
@@ -304,16 +304,16 @@ describe('ExtensionState', () => {
304304
commitOrdering: RepoCommitOrdering.Default,
305305
fileViewType: FileViewType.Default,
306306
hideRemotes: [],
307-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
307+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
308308
issueLinkingConfig: null,
309309
name: null,
310-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
311-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
310+
onlyFollowFirstParent: BooleanOverride.Default,
311+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
312312
onRepoLoadShowSpecificBranches: null,
313313
pullRequestConfig: null,
314314
showRemoteBranches: false,
315-
showRemoteBranchesV2: ShowRemoteBranches.Hide,
316-
showTags: ShowTags.Default
315+
showRemoteBranchesV2: BooleanOverride.Disabled,
316+
showTags: BooleanOverride.Default
317317
}
318318
});
319319
expect(workspaceConfiguration.get).toHaveBeenCalledTimes(1);

tests/repoManager.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Logger } from '../src/logger';
1313
import { RepoChangeEvent, RepoManager } from '../src/repoManager';
1414
import * as utils from '../src/utils';
1515
import { EventEmitter } from '../src/utils/event';
16-
import { FileViewType, GitRepoSet, IncludeCommitsMentionedByReflogs, OnlyFollowFirstParent, RepoCommitOrdering, ShowCheckedOutBranch, ShowRemoteBranches, ShowTags } from '../src/types';
16+
import { BooleanOverride, FileViewType, GitRepoSet, RepoCommitOrdering } from '../src/types';
1717

1818
let onDidChangeConfiguration: EventEmitter<ConfigurationChangeEvent>;
1919
let onDidChangeGitExecutable: EventEmitter<utils.GitExecutable>;
@@ -907,16 +907,16 @@ describe('RepoManager', () => {
907907
commitOrdering: RepoCommitOrdering.Default,
908908
fileViewType: FileViewType.Default,
909909
hideRemotes: [],
910-
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
910+
includeCommitsMentionedByReflogs: BooleanOverride.Default,
911911
issueLinkingConfig: null,
912912
name: null,
913-
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
914-
onRepoLoadShowCheckedOutBranch: ShowCheckedOutBranch.Default,
913+
onlyFollowFirstParent: BooleanOverride.Default,
914+
onRepoLoadShowCheckedOutBranch: BooleanOverride.Default,
915915
onRepoLoadShowSpecificBranches: null,
916916
pullRequestConfig: null,
917917
showRemoteBranches: true,
918-
showRemoteBranchesV2: ShowRemoteBranches.Default,
919-
showTags: ShowTags.Default
918+
showRemoteBranchesV2: BooleanOverride.Default,
919+
showTags: BooleanOverride.Default
920920
};
921921

922922
// Run

web/main.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class GitGraphView {
8787

8888
this.showRemoteBranchesElem = <HTMLInputElement>document.getElementById('showRemoteBranchesCheckbox')!;
8989
this.showRemoteBranchesElem.addEventListener('change', () => {
90-
this.saveRepoStateValue(this.currentRepo, 'showRemoteBranchesV2', this.showRemoteBranchesElem.checked ? GG.ShowRemoteBranches.Show : GG.ShowRemoteBranches.Hide);
90+
this.saveRepoStateValue(this.currentRepo, 'showRemoteBranchesV2', this.showRemoteBranchesElem.checked ? GG.BooleanOverride.Enabled : GG.BooleanOverride.Disabled);
9191
this.refresh(true);
9292
});
9393

@@ -3300,34 +3300,34 @@ function getCommitOrdering(repoValue: GG.RepoCommitOrdering): GG.CommitOrdering
33003300
}
33013301
}
33023302

3303-
function getShowRemoteBranches(repoValue: GG.ShowRemoteBranches) {
3304-
return repoValue === GG.ShowRemoteBranches.Default
3303+
function getShowRemoteBranches(repoValue: GG.BooleanOverride) {
3304+
return repoValue === GG.BooleanOverride.Default
33053305
? initialState.config.showRemoteBranches
3306-
: repoValue === GG.ShowRemoteBranches.Show;
3306+
: repoValue === GG.BooleanOverride.Enabled;
33073307
}
33083308

3309-
function getShowTags(repoValue: GG.ShowTags) {
3310-
return repoValue === GG.ShowTags.Default
3309+
function getShowTags(repoValue: GG.BooleanOverride) {
3310+
return repoValue === GG.BooleanOverride.Default
33113311
? initialState.config.showTags
3312-
: repoValue === GG.ShowTags.Show;
3312+
: repoValue === GG.BooleanOverride.Enabled;
33133313
}
33143314

3315-
function getIncludeCommitsMentionedByReflogs(repoValue: GG.IncludeCommitsMentionedByReflogs) {
3316-
return repoValue === GG.IncludeCommitsMentionedByReflogs.Default
3315+
function getIncludeCommitsMentionedByReflogs(repoValue: GG.BooleanOverride) {
3316+
return repoValue === GG.BooleanOverride.Default
33173317
? initialState.config.includeCommitsMentionedByReflogs
3318-
: repoValue === GG.IncludeCommitsMentionedByReflogs.Enabled;
3318+
: repoValue === GG.BooleanOverride.Enabled;
33193319
}
33203320

3321-
function getOnlyFollowFirstParent(repoValue: GG.OnlyFollowFirstParent) {
3322-
return repoValue === GG.OnlyFollowFirstParent.Default
3321+
function getOnlyFollowFirstParent(repoValue: GG.BooleanOverride) {
3322+
return repoValue === GG.BooleanOverride.Default
33233323
? initialState.config.onlyFollowFirstParent
3324-
: repoValue === GG.OnlyFollowFirstParent.Enabled;
3324+
: repoValue === GG.BooleanOverride.Enabled;
33253325
}
33263326

3327-
function getOnRepoLoadShowCheckedOutBranch(repoValue: GG.ShowCheckedOutBranch) {
3328-
return repoValue === GG.ShowCheckedOutBranch.Default
3327+
function getOnRepoLoadShowCheckedOutBranch(repoValue: GG.BooleanOverride) {
3328+
return repoValue === GG.BooleanOverride.Default
33293329
? initialState.config.onRepoLoad.showCheckedOutBranch
3330-
: repoValue === GG.ShowCheckedOutBranch.Enabled;
3330+
: repoValue === GG.BooleanOverride.Enabled;
33313331
}
33323332

33333333
function getOnRepoLoadShowSpecificBranches(repoValue: string[] | null) {

0 commit comments

Comments
 (0)