Skip to content

Commit 3dfffdb

Browse files
authored
Merge pull request #23 from XUJINKAI/master
add simplifyByDecoration checkbox
2 parents 7cd4740 + 94021d0 commit 3dfffdb

File tree

8 files changed

+46
-7
lines changed

8 files changed

+46
-7
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,11 @@
10771077
"default": true,
10781078
"description": "Show Remote Branches in Git Graph by default. This can be overridden per repository from the Git Graph View's Control Bar."
10791079
},
1080+
"git-graph.repository.simplifyByDecoration": {
1081+
"type": "boolean",
1082+
"default": false,
1083+
"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."
1084+
},
10801085
"git-graph.repository.showRemoteHeads": {
10811086
"type": "boolean",
10821087
"default": true,

src/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,13 @@ class Config {
464464
return !!this.config.get('repository.showRemoteBranches', true);
465465
}
466466

467+
/**
468+
* Get the value of the `git-graph.repository.simplifyByDecoration` Extension Setting.
469+
*/
470+
get simplifyByDecoration() {
471+
return !!this.config.get('repository.simplifyByDecoration', false);
472+
}
473+
467474
/**
468475
* Get the value of the `git-graph.repository.showRemoteHeads` Extension Setting.
469476
*/

src/dataSource.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ export class DataSource extends Disposable {
161161
* @param stashes An array of all stashes in the repository.
162162
* @returns The commits in the repository.
163163
*/
164-
public getCommits(repo: string, branches: ReadonlyArray<string> | null, authors: ReadonlyArray<string> | null, maxCommits: number, showTags: boolean, showRemoteBranches: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, commitOrdering: CommitOrdering, remotes: ReadonlyArray<string>, hideRemotes: ReadonlyArray<string>, stashes: ReadonlyArray<GitStash>): Promise<GitCommitData> {
164+
public getCommits(repo: string, branches: ReadonlyArray<string> | null, authors: ReadonlyArray<string> | null, maxCommits: number, showTags: boolean, showRemoteBranches: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, commitOrdering: CommitOrdering, remotes: ReadonlyArray<string>, hideRemotes: ReadonlyArray<string>, stashes: ReadonlyArray<GitStash>, simplifyByDecoration: boolean): Promise<GitCommitData> {
165165
const config = getConfig();
166166
return Promise.all([
167-
this.getLog(repo, branches, authors, maxCommits + 1, showTags && config.showCommitsOnlyReferencedByTags, showRemoteBranches, includeCommitsMentionedByReflogs, onlyFollowFirstParent, commitOrdering, remotes, hideRemotes, stashes),
167+
this.getLog(repo, branches, authors, maxCommits + 1, showTags && config.showCommitsOnlyReferencedByTags, showRemoteBranches, includeCommitsMentionedByReflogs, onlyFollowFirstParent, commitOrdering, remotes, hideRemotes, stashes, simplifyByDecoration),
168168
this.getRefs(repo, showRemoteBranches, config.showRemoteHeads, hideRemotes).then((refData: GitRefData) => refData, (errorMessage: string) => errorMessage)
169169
]).then(async (results) => {
170170
let commits: GitCommitRecord[] = results[0], refData: GitRefData | string = results[1], i;
@@ -1543,8 +1543,11 @@ export class DataSource extends Disposable {
15431543
* @param stashes An array of all stashes in the repository.
15441544
* @returns An array of commits.
15451545
*/
1546-
private getLog(repo: string, branches: ReadonlyArray<string> | null, authors: ReadonlyArray<string> | null, num: number, includeTags: boolean, includeRemotes: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, order: CommitOrdering, remotes: ReadonlyArray<string>, hideRemotes: ReadonlyArray<string>, stashes: ReadonlyArray<GitStash>) {
1546+
private getLog(repo: string, branches: ReadonlyArray<string> | null, authors: ReadonlyArray<string> | null, num: number, includeTags: boolean, includeRemotes: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, order: CommitOrdering, remotes: ReadonlyArray<string>, hideRemotes: ReadonlyArray<string>, stashes: ReadonlyArray<GitStash>, simplifyByDecoration: boolean) {
15471547
const args = ['-c', 'log.showSignature=false', 'log', '--max-count=' + num, '--format=' + this.gitFormatLog, '--' + order + '-order'];
1548+
if (simplifyByDecoration) {
1549+
args.push('--simplify-by-decoration');
1550+
}
15481551
if (onlyFollowFirstParent) {
15491552
args.push('--first-parent');
15501553
}
@@ -1561,6 +1564,7 @@ export class DataSource extends Disposable {
15611564
// Show All
15621565
args.push('--branches');
15631566
if (includeTags) args.push('--tags');
1567+
else if(simplifyByDecoration) args.push('--decorate-refs-exclude=refs/tags/');
15641568
if (includeCommitsMentionedByReflogs) args.push('--reflog');
15651569
if (includeRemotes) {
15661570
if (hideRemotes.length === 0) {

src/extensionState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const DEFAULT_REPO_STATE: GitRepoState = {
3434
pullRequestConfig: null,
3535
showRemoteBranches: true,
3636
showRemoteBranchesV2: BooleanOverride.Default,
37+
simplifyByDecoration: BooleanOverride.Default,
3738
showStashes: BooleanOverride.Default,
3839
showTags: BooleanOverride.Default,
3940
workspaceFolderIndex: null

src/gitGraphView.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ export class GitGraphView extends Disposable {
409409
command: 'loadCommits',
410410
refreshId: msg.refreshId,
411411
onlyFollowFirstParent: msg.onlyFollowFirstParent,
412-
...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)
412+
...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)
413413
});
414414
break;
415415
case 'loadConfig':
@@ -692,6 +692,7 @@ export class GitGraphView extends Disposable {
692692
referenceLabels: config.referenceLabels,
693693
repoDropdownOrder: config.repoDropdownOrder,
694694
showRemoteBranches: config.showRemoteBranches,
695+
simplifyByDecoration: config.simplifyByDecoration,
695696
showStashes: config.showStashes,
696697
showTags: config.showTags
697698
},
@@ -724,7 +725,8 @@ export class GitGraphView extends Disposable {
724725
<span id="branchControl"><span class="unselectable">Branches: </span><div id="branchDropdown" class="dropdown"></div></span>
725726
<span id="authorControl"><span class="unselectable">Authors: </span><div id="authorDropdown" class="dropdown"></div></span>
726727
727-
<label id="showRemoteBranchesControl"><input type="checkbox" id="showRemoteBranchesCheckbox" tabindex="-1"><span class="customCheckbox"></span>Show Remote Branches</label>
728+
<label id="showRemoteBranchesControl" title="Show Remote Branches"><input type="checkbox" id="showRemoteBranchesCheckbox" tabindex="-1"><span class="customCheckbox"></span>Remotes</label>
729+
<label id="simplifyByDecorationControl" title="Simplify By Decoration"><input type="checkbox" id="simplifyByDecorationCheckbox" tabindex="-1"><span class="customCheckbox"></span>Simplify</label>
728730
<div id="currentBtn" title="Current"></div>
729731
<div id="findBtn" title="Find"></div>
730732
<div id="terminalBtn" title="Open a Terminal for this Repository"></div>

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export interface GitRepoState {
218218
pullRequestConfig: PullRequestConfig | null;
219219
showRemoteBranches: boolean;
220220
showRemoteBranchesV2: BooleanOverride;
221+
simplifyByDecoration: BooleanOverride;
221222
showStashes: BooleanOverride;
222223
showTags: BooleanOverride;
223224
workspaceFolderIndex: number | null;
@@ -262,6 +263,7 @@ export interface GitGraphViewConfig {
262263
readonly referenceLabels: ReferenceLabelsConfig;
263264
readonly repoDropdownOrder: RepoDropdownOrder;
264265
readonly showRemoteBranches: boolean;
266+
readonly simplifyByDecoration: boolean;
265267
readonly showStashes: boolean;
266268
readonly showTags: boolean;
267269
readonly stickyHeader: boolean;
@@ -911,6 +913,7 @@ export interface RequestLoadCommits extends RepoRequest {
911913
readonly maxCommits: number;
912914
readonly showTags: boolean;
913915
readonly showRemoteBranches: boolean;
916+
readonly simplifyByDecoration: boolean;
914917
readonly includeCommitsMentionedByReflogs: boolean;
915918
readonly onlyFollowFirstParent: boolean;
916919
readonly commitOrdering: CommitOrdering;
@@ -942,6 +945,7 @@ export interface RequestLoadRepoInfo extends RepoRequest {
942945
readonly command: 'loadRepoInfo';
943946
readonly refreshId: number;
944947
readonly showRemoteBranches: boolean;
948+
readonly simplifyByDecoration: boolean;
945949
readonly showStashes: boolean;
946950
readonly hideRemotes: ReadonlyArray<string>;
947951
}

web/main.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class GitGraphView {
5555
private tableColHeadersElem: HTMLElement | null;
5656
private readonly footerElem: HTMLElement;
5757
private readonly showRemoteBranchesElem: HTMLInputElement;
58+
private readonly simplifyByDecorationElem: HTMLInputElement;
5859
private readonly refreshBtnElem: HTMLElement;
5960

6061
constructor(viewElem: HTMLElement, prevState: WebViewState | null) {
@@ -105,6 +106,11 @@ class GitGraphView {
105106
this.saveRepoStateValue(this.currentRepo, 'showRemoteBranchesV2', this.showRemoteBranchesElem.checked ? GG.BooleanOverride.Enabled : GG.BooleanOverride.Disabled);
106107
this.refresh(true);
107108
});
109+
this.simplifyByDecorationElem = <HTMLInputElement>document.getElementById('simplifyByDecorationCheckbox')!;
110+
this.simplifyByDecorationElem.addEventListener('change', () => {
111+
this.saveRepoStateValue(this.currentRepo, 'simplifyByDecoration', this.simplifyByDecorationElem.checked ? GG.BooleanOverride.Enabled : GG.BooleanOverride.Disabled);
112+
this.refresh(true);
113+
});
108114

109115
this.refreshBtnElem = document.getElementById('refreshBtn')!;
110116
this.refreshBtnElem.addEventListener('click', () => {
@@ -140,6 +146,7 @@ class GitGraphView {
140146
this.findWidget.restoreState(prevState.findWidget);
141147
this.settingsWidget.restoreState(prevState.settingsWidget);
142148
this.showRemoteBranchesElem.checked = getShowRemoteBranches(this.gitRepos[prevState.currentRepo].showRemoteBranchesV2);
149+
this.simplifyByDecorationElem.checked = getSimplifyByDecoration(this.gitRepos[prevState.currentRepo].simplifyByDecoration);
143150
}
144151

145152
let loadViewTo = initialState.loadViewTo;
@@ -224,6 +231,7 @@ class GitGraphView {
224231
this.currentRepo = repo;
225232
this.currentRepoLoading = true;
226233
this.showRemoteBranchesElem.checked = getShowRemoteBranches(this.gitRepos[this.currentRepo].showRemoteBranchesV2);
234+
this.simplifyByDecorationElem.checked = getSimplifyByDecoration(this.gitRepos[this.currentRepo].simplifyByDecoration);
227235
this.maxCommits = this.config.initialLoadCommits;
228236
this.gitConfig = null;
229237
this.gitRemotes = [];
@@ -634,6 +642,7 @@ class GitGraphView {
634642
repo: this.currentRepo,
635643
refreshId: ++this.currentRepoRefreshState.loadRepoInfoRefreshId,
636644
showRemoteBranches: getShowRemoteBranches(repoState.showRemoteBranchesV2),
645+
simplifyByDecoration: getSimplifyByDecoration(repoState.simplifyByDecoration),
637646
showStashes: getShowStashes(repoState.showStashes),
638647
hideRemotes: repoState.hideRemotes
639648
});
@@ -650,6 +659,7 @@ class GitGraphView {
650659
maxCommits: this.maxCommits,
651660
showTags: getShowTags(repoState.showTags),
652661
showRemoteBranches: getShowRemoteBranches(repoState.showRemoteBranchesV2),
662+
simplifyByDecoration: getSimplifyByDecoration(repoState.simplifyByDecoration),
653663
includeCommitsMentionedByReflogs: getIncludeCommitsMentionedByReflogs(repoState.includeCommitsMentionedByReflogs),
654664
onlyFollowFirstParent: getOnlyFollowFirstParent(repoState.onlyFollowFirstParent),
655665
commitOrdering: getCommitOrdering(repoState.commitOrdering),
@@ -3867,6 +3877,12 @@ function getShowRemoteBranches(repoValue: GG.BooleanOverride) {
38673877
: repoValue === GG.BooleanOverride.Enabled;
38683878
}
38693879

3880+
function getSimplifyByDecoration(repoValue: GG.BooleanOverride) {
3881+
return repoValue === GG.BooleanOverride.Default
3882+
? initialState.config.simplifyByDecoration
3883+
: repoValue === GG.BooleanOverride.Enabled;
3884+
}
3885+
38703886
function getShowStashes(repoValue: GG.BooleanOverride) {
38713887
return repoValue === GG.BooleanOverride.Default
38723888
? initialState.config.showStashes

web/styles/main.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,15 @@ body.tagLabelsRightAligned .gitRef.tag{
805805
z-index:12;
806806
}
807807

808-
#repoControl, #branchControl, #showRemoteBranchesControl{
808+
#repoControl, #branchControl, #showRemoteBranchesControl, #simplifyByDecorationControl{
809809
display:inline-block;
810810
white-space:nowrap;
811811
margin:0 10px;
812812
}
813813
#repoDropdown, #branchDropdown #authorDropdown{
814814
margin-left:3px;
815815
}
816-
#showRemoteBranchesControl > .customCheckbox{
816+
#showRemoteBranchesControl > .customCheckbox, #simplifyByDecorationControl > .customCheckbox{
817817
margin-right:6px;
818818
}
819819

0 commit comments

Comments
 (0)