diff --git a/package.json b/package.json index 52be0fd..93bc35c 100644 --- a/package.json +++ b/package.json @@ -1077,6 +1077,11 @@ "default": true, "description": "Show Remote Branches in Git Graph by default. This can be overridden per repository from the Git Graph View's Control Bar." }, + "git-graph.repository.simplifyByDecoration": { + "type": "boolean", + "default": false, + "description": "Show branch topology by omitting commits that are not referenced by tags. This can be overridden per repository from the Git Graph View's Control Bar." + }, "git-graph.repository.showRemoteHeads": { "type": "boolean", "default": true, diff --git a/src/config.ts b/src/config.ts index 76570ba..858ba87 100644 --- a/src/config.ts +++ b/src/config.ts @@ -464,6 +464,13 @@ class Config { return !!this.config.get('repository.showRemoteBranches', true); } + /** + * Get the value of the `git-graph.repository.simplifyByDecoration` Extension Setting. + */ + get simplifyByDecoration() { + return !!this.config.get('repository.simplifyByDecoration', false); + } + /** * Get the value of the `git-graph.repository.showRemoteHeads` Extension Setting. */ diff --git a/src/dataSource.ts b/src/dataSource.ts index 09294b1..a6524c3 100644 --- a/src/dataSource.ts +++ b/src/dataSource.ts @@ -161,10 +161,10 @@ export class DataSource extends Disposable { * @param stashes An array of all stashes in the repository. * @returns The commits in the repository. */ - public getCommits(repo: string, branches: ReadonlyArray | null, authors: ReadonlyArray | null, maxCommits: number, showTags: boolean, showRemoteBranches: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, commitOrdering: CommitOrdering, remotes: ReadonlyArray, hideRemotes: ReadonlyArray, stashes: ReadonlyArray): Promise { + public getCommits(repo: string, branches: ReadonlyArray | null, authors: ReadonlyArray | null, maxCommits: number, showTags: boolean, showRemoteBranches: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, commitOrdering: CommitOrdering, remotes: ReadonlyArray, hideRemotes: ReadonlyArray, stashes: ReadonlyArray, simplifyByDecoration: boolean): Promise { const config = getConfig(); return Promise.all([ - this.getLog(repo, branches, authors, maxCommits + 1, showTags && config.showCommitsOnlyReferencedByTags, showRemoteBranches, includeCommitsMentionedByReflogs, onlyFollowFirstParent, commitOrdering, remotes, hideRemotes, stashes), + this.getLog(repo, branches, authors, maxCommits + 1, showTags && config.showCommitsOnlyReferencedByTags, showRemoteBranches, includeCommitsMentionedByReflogs, onlyFollowFirstParent, commitOrdering, remotes, hideRemotes, stashes, simplifyByDecoration), this.getRefs(repo, showRemoteBranches, config.showRemoteHeads, hideRemotes).then((refData: GitRefData) => refData, (errorMessage: string) => errorMessage) ]).then(async (results) => { let commits: GitCommitRecord[] = results[0], refData: GitRefData | string = results[1], i; @@ -1543,8 +1543,11 @@ export class DataSource extends Disposable { * @param stashes An array of all stashes in the repository. * @returns An array of commits. */ - private getLog(repo: string, branches: ReadonlyArray | null, authors: ReadonlyArray | null, num: number, includeTags: boolean, includeRemotes: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, order: CommitOrdering, remotes: ReadonlyArray, hideRemotes: ReadonlyArray, stashes: ReadonlyArray) { + private getLog(repo: string, branches: ReadonlyArray | null, authors: ReadonlyArray | null, num: number, includeTags: boolean, includeRemotes: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, order: CommitOrdering, remotes: ReadonlyArray, hideRemotes: ReadonlyArray, stashes: ReadonlyArray, simplifyByDecoration: boolean) { const args = ['-c', 'log.showSignature=false', 'log', '--max-count=' + num, '--format=' + this.gitFormatLog, '--' + order + '-order']; + if (simplifyByDecoration) { + args.push('--simplify-by-decoration'); + } if (onlyFollowFirstParent) { args.push('--first-parent'); } @@ -1561,6 +1564,7 @@ export class DataSource extends Disposable { // Show All args.push('--branches'); if (includeTags) args.push('--tags'); + else if(simplifyByDecoration) args.push('--decorate-refs-exclude=refs/tags/'); if (includeCommitsMentionedByReflogs) args.push('--reflog'); if (includeRemotes) { if (hideRemotes.length === 0) { diff --git a/src/extensionState.ts b/src/extensionState.ts index 721857a..c38ad00 100644 --- a/src/extensionState.ts +++ b/src/extensionState.ts @@ -34,6 +34,7 @@ export const DEFAULT_REPO_STATE: GitRepoState = { pullRequestConfig: null, showRemoteBranches: true, showRemoteBranchesV2: BooleanOverride.Default, + simplifyByDecoration: BooleanOverride.Default, showStashes: BooleanOverride.Default, showTags: BooleanOverride.Default, workspaceFolderIndex: null diff --git a/src/gitGraphView.ts b/src/gitGraphView.ts index 23431df..aff732c 100644 --- a/src/gitGraphView.ts +++ b/src/gitGraphView.ts @@ -409,7 +409,7 @@ export class GitGraphView extends Disposable { command: 'loadCommits', refreshId: msg.refreshId, onlyFollowFirstParent: msg.onlyFollowFirstParent, - ...await this.dataSource.getCommits(msg.repo, msg.branches, msg.authors, msg.maxCommits, msg.showTags, msg.showRemoteBranches, msg.includeCommitsMentionedByReflogs, msg.onlyFollowFirstParent, msg.commitOrdering, msg.remotes, msg.hideRemotes, msg.stashes) + ...await this.dataSource.getCommits(msg.repo, msg.branches, msg.authors, msg.maxCommits, msg.showTags, msg.showRemoteBranches, msg.includeCommitsMentionedByReflogs, msg.onlyFollowFirstParent, msg.commitOrdering, msg.remotes, msg.hideRemotes, msg.stashes, msg.simplifyByDecoration) }); break; case 'loadConfig': @@ -692,6 +692,7 @@ export class GitGraphView extends Disposable { referenceLabels: config.referenceLabels, repoDropdownOrder: config.repoDropdownOrder, showRemoteBranches: config.showRemoteBranches, + simplifyByDecoration: config.simplifyByDecoration, showStashes: config.showStashes, showTags: config.showTags }, @@ -724,7 +725,8 @@ export class GitGraphView extends Disposable { Branches: Authors: - + +
diff --git a/src/types.ts b/src/types.ts index 8c9458f..e403bd2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -218,6 +218,7 @@ export interface GitRepoState { pullRequestConfig: PullRequestConfig | null; showRemoteBranches: boolean; showRemoteBranchesV2: BooleanOverride; + simplifyByDecoration: BooleanOverride; showStashes: BooleanOverride; showTags: BooleanOverride; workspaceFolderIndex: number | null; @@ -262,6 +263,7 @@ export interface GitGraphViewConfig { readonly referenceLabels: ReferenceLabelsConfig; readonly repoDropdownOrder: RepoDropdownOrder; readonly showRemoteBranches: boolean; + readonly simplifyByDecoration: boolean; readonly showStashes: boolean; readonly showTags: boolean; readonly stickyHeader: boolean; @@ -911,6 +913,7 @@ export interface RequestLoadCommits extends RepoRequest { readonly maxCommits: number; readonly showTags: boolean; readonly showRemoteBranches: boolean; + readonly simplifyByDecoration: boolean; readonly includeCommitsMentionedByReflogs: boolean; readonly onlyFollowFirstParent: boolean; readonly commitOrdering: CommitOrdering; @@ -942,6 +945,7 @@ export interface RequestLoadRepoInfo extends RepoRequest { readonly command: 'loadRepoInfo'; readonly refreshId: number; readonly showRemoteBranches: boolean; + readonly simplifyByDecoration: boolean; readonly showStashes: boolean; readonly hideRemotes: ReadonlyArray; } diff --git a/web/main.ts b/web/main.ts index 12dfa6e..2045c74 100644 --- a/web/main.ts +++ b/web/main.ts @@ -55,6 +55,7 @@ class GitGraphView { private tableColHeadersElem: HTMLElement | null; private readonly footerElem: HTMLElement; private readonly showRemoteBranchesElem: HTMLInputElement; + private readonly simplifyByDecorationElem: HTMLInputElement; private readonly refreshBtnElem: HTMLElement; constructor(viewElem: HTMLElement, prevState: WebViewState | null) { @@ -105,6 +106,11 @@ class GitGraphView { this.saveRepoStateValue(this.currentRepo, 'showRemoteBranchesV2', this.showRemoteBranchesElem.checked ? GG.BooleanOverride.Enabled : GG.BooleanOverride.Disabled); this.refresh(true); }); + this.simplifyByDecorationElem = document.getElementById('simplifyByDecorationCheckbox')!; + this.simplifyByDecorationElem.addEventListener('change', () => { + this.saveRepoStateValue(this.currentRepo, 'simplifyByDecoration', this.simplifyByDecorationElem.checked ? GG.BooleanOverride.Enabled : GG.BooleanOverride.Disabled); + this.refresh(true); + }); this.refreshBtnElem = document.getElementById('refreshBtn')!; this.refreshBtnElem.addEventListener('click', () => { @@ -140,6 +146,7 @@ class GitGraphView { this.findWidget.restoreState(prevState.findWidget); this.settingsWidget.restoreState(prevState.settingsWidget); this.showRemoteBranchesElem.checked = getShowRemoteBranches(this.gitRepos[prevState.currentRepo].showRemoteBranchesV2); + this.simplifyByDecorationElem.checked = getSimplifyByDecoration(this.gitRepos[prevState.currentRepo].simplifyByDecoration); } let loadViewTo = initialState.loadViewTo; @@ -224,6 +231,7 @@ class GitGraphView { this.currentRepo = repo; this.currentRepoLoading = true; this.showRemoteBranchesElem.checked = getShowRemoteBranches(this.gitRepos[this.currentRepo].showRemoteBranchesV2); + this.simplifyByDecorationElem.checked = getSimplifyByDecoration(this.gitRepos[this.currentRepo].simplifyByDecoration); this.maxCommits = this.config.initialLoadCommits; this.gitConfig = null; this.gitRemotes = []; @@ -636,6 +644,7 @@ class GitGraphView { repo: this.currentRepo, refreshId: ++this.currentRepoRefreshState.loadRepoInfoRefreshId, showRemoteBranches: getShowRemoteBranches(repoState.showRemoteBranchesV2), + simplifyByDecoration: getSimplifyByDecoration(repoState.simplifyByDecoration), showStashes: getShowStashes(repoState.showStashes), hideRemotes: repoState.hideRemotes }); @@ -652,6 +661,7 @@ class GitGraphView { maxCommits: this.maxCommits, showTags: getShowTags(repoState.showTags), showRemoteBranches: getShowRemoteBranches(repoState.showRemoteBranchesV2), + simplifyByDecoration: getSimplifyByDecoration(repoState.simplifyByDecoration), includeCommitsMentionedByReflogs: getIncludeCommitsMentionedByReflogs(repoState.includeCommitsMentionedByReflogs), onlyFollowFirstParent: getOnlyFollowFirstParent(repoState.onlyFollowFirstParent), commitOrdering: getCommitOrdering(repoState.commitOrdering), @@ -3869,6 +3879,12 @@ function getShowRemoteBranches(repoValue: GG.BooleanOverride) { : repoValue === GG.BooleanOverride.Enabled; } +function getSimplifyByDecoration(repoValue: GG.BooleanOverride) { + return repoValue === GG.BooleanOverride.Default + ? initialState.config.simplifyByDecoration + : repoValue === GG.BooleanOverride.Enabled; +} + function getShowStashes(repoValue: GG.BooleanOverride) { return repoValue === GG.BooleanOverride.Default ? initialState.config.showStashes diff --git a/web/styles/main.css b/web/styles/main.css index f300e57..88c3543 100644 --- a/web/styles/main.css +++ b/web/styles/main.css @@ -805,7 +805,7 @@ body.tagLabelsRightAligned .gitRef.tag{ z-index:12; } -#repoControl, #branchControl, #showRemoteBranchesControl{ +#repoControl, #branchControl, #showRemoteBranchesControl, #simplifyByDecorationControl{ display:inline-block; white-space:nowrap; margin:0 10px; @@ -813,7 +813,7 @@ body.tagLabelsRightAligned .gitRef.tag{ #repoDropdown, #branchDropdown #authorDropdown{ margin-left:3px; } -#showRemoteBranchesControl > .customCheckbox{ +#showRemoteBranchesControl > .customCheckbox, #simplifyByDecorationControl > .customCheckbox{ margin-right:6px; }