Skip to content

Commit cd38dd4

Browse files
committed
#304 Override the globally configured commit ordering per repository from the Git Graph View Column Header context menu.
1 parent 5c0c7d4 commit cd38dd4

File tree

5 files changed

+88
-25
lines changed

5 files changed

+88
-25
lines changed

src/dataSource.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,16 @@ export class DataSource implements vscode.Disposable {
140140
* @param showRemoteBranches Are remote branches shown.
141141
* @param includeCommitsMentionedByReflogs Should commits mentioned by reflogs being included.
142142
* @param onlyFollowFirstParent Only follow the first parent of commits.
143+
* @param commitOrdering The order for commits to be returned.
143144
* @param remotes An array of known remotes.
144145
* @param hideRemotes An array of hidden remotes.
145146
* @param stashes An array of all stashes in the repository.
146147
* @returns The commits in the repository.
147148
*/
148-
public getCommits(repo: string, branches: string[] | null, maxCommits: number, showTags: boolean, showRemoteBranches: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, remotes: string[], hideRemotes: string[], stashes: ReadonlyArray<GitStash>): Promise<GitCommitData> {
149+
public getCommits(repo: string, branches: string[] | null, maxCommits: number, showTags: boolean, showRemoteBranches: boolean, includeCommitsMentionedByReflogs: boolean, onlyFollowFirstParent: boolean, commitOrdering: CommitOrdering, remotes: string[], hideRemotes: string[], stashes: ReadonlyArray<GitStash>): Promise<GitCommitData> {
149150
const config = getConfig();
150151
return Promise.all([
151-
this.getLog(repo, branches, maxCommits + 1, showTags && config.showCommitsOnlyReferencedByTags, showRemoteBranches, includeCommitsMentionedByReflogs, onlyFollowFirstParent, config.commitOrdering, remotes, hideRemotes, stashes),
152+
this.getLog(repo, branches, maxCommits + 1, showTags && config.showCommitsOnlyReferencedByTags, showRemoteBranches, includeCommitsMentionedByReflogs, onlyFollowFirstParent, commitOrdering, remotes, hideRemotes, stashes),
152153
this.getRefs(repo, showRemoteBranches, hideRemotes).then((refData: GitRefData) => refData, (errorMessage: string) => errorMessage)
153154
]).then(async (results) => {
154155
let commits: GitCommitRecord[] = results[0], refData: GitRefData | string = results[1], i;

src/extensionState.ts

Lines changed: 2 additions & 1 deletion
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 { Event } from './event';
5-
import { CodeReview, ErrorInfo, FileViewType, GitGraphViewGlobalState, GitRepoSet, GitRepoState, IncludeCommitsMentionedByReflogs, OnlyFollowFirstParent, ShowTags } from './types';
5+
import { CodeReview, ErrorInfo, FileViewType, GitGraphViewGlobalState, GitRepoSet, GitRepoState, IncludeCommitsMentionedByReflogs, OnlyFollowFirstParent, RepoCommitOrdering, ShowTags } from './types';
66
import { getPathFromStr, GitExecutable } from './utils';
77

88
const AVATAR_STORAGE_FOLDER = '/avatars';
@@ -18,6 +18,7 @@ export const DEFAULT_REPO_STATE: GitRepoState = {
1818
columnWidths: null,
1919
cdvDivider: 0.5,
2020
cdvHeight: 250,
21+
commitOrdering: RepoCommitOrdering.Default,
2122
fileViewType: FileViewType.Default,
2223
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
2324
onlyFollowFirstParent: OnlyFollowFirstParent.Default,

src/gitGraphView.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export class GitGraphView implements vscode.Disposable {
372372
command: 'loadCommits',
373373
refreshId: msg.refreshId,
374374
onlyFollowFirstParent: msg.onlyFollowFirstParent,
375-
... await this.dataSource.getCommits(msg.repo, msg.branches, msg.maxCommits, msg.showTags, msg.showRemoteBranches, msg.includeCommitsMentionedByReflogs, msg.onlyFollowFirstParent, msg.remotes, msg.hideRemotes, msg.stashes)
375+
... await this.dataSource.getCommits(msg.repo, msg.branches, msg.maxCommits, msg.showTags, msg.showRemoteBranches, msg.includeCommitsMentionedByReflogs, msg.onlyFollowFirstParent, msg.commitOrdering, msg.remotes, msg.hideRemotes, msg.stashes)
376376
});
377377
break;
378378
case 'loadRepoInfo':
@@ -576,6 +576,7 @@ export class GitGraphView implements vscode.Disposable {
576576
branchLabelsAlignedToGraph: refLabelAlignment === RefLabelAlignment.BranchesAlignedToGraphAndTagsOnRight,
577577
combineLocalAndRemoteBranchLabels: config.combineLocalAndRemoteBranchLabels,
578578
commitDetailsViewLocation: config.commitDetailsViewLocation,
579+
commitOrdering: config.commitOrdering,
579580
contextMenuActionsVisibility: config.contextMenuActionsVisibility,
580581
customBranchGlobPatterns: config.customBranchGlobPatterns,
581582
customEmojiShortcodeMappings: config.customEmojiShortcodeMappings,

src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export interface GitRepoState {
181181
columnWidths: ColumnWidth[] | null;
182182
cdvDivider: number;
183183
cdvHeight: number;
184+
commitOrdering: RepoCommitOrdering;
184185
fileViewType: FileViewType;
185186
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs;
186187
onlyFollowFirstParent: OnlyFollowFirstParent;
@@ -208,6 +209,7 @@ export interface GitGraphViewConfig {
208209
readonly branchLabelsAlignedToGraph: boolean;
209210
readonly combineLocalAndRemoteBranchLabels: boolean;
210211
readonly commitDetailsViewLocation: CommitDetailsViewLocation;
212+
readonly commitOrdering: CommitOrdering;
211213
readonly contextMenuActionsVisibility: ContextMenuActionsVisibility;
212214
readonly customBranchGlobPatterns: CustomBranchGlobPattern[];
213215
readonly customEmojiShortcodeMappings: CustomEmojiShortcodeMapping[];
@@ -424,6 +426,13 @@ export const enum RefLabelAlignment {
424426
BranchesAlignedToGraphAndTagsOnRight
425427
}
426428

429+
export const enum RepoCommitOrdering {
430+
Default = 'default',
431+
Date = 'date',
432+
AuthorDate = 'author-date',
433+
Topological = 'topo'
434+
}
435+
427436
export const enum ShowTags {
428437
Default,
429438
Show,
@@ -788,6 +797,7 @@ export interface RequestLoadCommits extends RepoRequest {
788797
readonly showRemoteBranches: boolean;
789798
readonly includeCommitsMentionedByReflogs: boolean;
790799
readonly onlyFollowFirstParent: boolean;
800+
readonly commitOrdering: CommitOrdering;
791801
readonly remotes: string[];
792802
readonly hideRemotes: string[];
793803
readonly stashes: ReadonlyArray<GitStash>;

web/main.ts

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ class GitGraphView {
520520
showRemoteBranches: repoState.showRemoteBranches,
521521
includeCommitsMentionedByReflogs: getIncludeCommitsMentionedByReflogs(repoState.includeCommitsMentionedByReflogs),
522522
onlyFollowFirstParent: getOnlyFollowFirstParent(repoState.onlyFollowFirstParent),
523+
commitOrdering: getCommitOrdering(repoState.commitOrdering),
523524
remotes: this.gitRemotes,
524525
hideRemotes: repoState.hideRemotes,
525526
stashes: this.gitStashes
@@ -651,6 +652,13 @@ class GitGraphView {
651652
this.saveState();
652653
}
653654

655+
public saveCommitOrdering(repo: string, commitOrdering: GG.RepoCommitOrdering) {
656+
if (repo === this.currentRepo) {
657+
this.gitRepos[this.currentRepo].commitOrdering = commitOrdering;
658+
this.saveRepoState();
659+
}
660+
}
661+
654662
public saveHiddenRemotes(repo: string, hideRemotes: string[]) {
655663
if (repo === this.currentRepo) {
656664
this.gitRepos[this.currentRepo].hideRemotes = hideRemotes;
@@ -1585,32 +1593,61 @@ class GitGraphView {
15851593

15861594
colHeadersElem.addEventListener('contextmenu', (e: MouseEvent) => {
15871595
e.stopPropagation();
1596+
15881597
const toggleColumnState = (col: number, defaultWidth: number) => {
15891598
columnWidths[col] = columnWidths[col] !== COLUMN_HIDDEN ? COLUMN_HIDDEN : columnWidths[0] === COLUMN_AUTO ? COLUMN_AUTO : defaultWidth - COLUMN_LEFT_RIGHT_PADDING;
15901599
this.saveColumnWidths(columnWidths);
1591-
contextMenu.close();
15921600
this.render();
15931601
};
1594-
contextMenu.show([[
1595-
{
1596-
title: 'Date',
1597-
visible: true,
1598-
checked: columnWidths[2] !== COLUMN_HIDDEN,
1599-
onClick: () => toggleColumnState(2, 128)
1600-
},
1601-
{
1602-
title: 'Author',
1603-
visible: true,
1604-
checked: columnWidths[3] !== COLUMN_HIDDEN,
1605-
onClick: () => toggleColumnState(3, 128)
1606-
},
1607-
{
1608-
title: 'Commit',
1609-
visible: true,
1610-
checked: columnWidths[4] !== COLUMN_HIDDEN,
1611-
onClick: () => toggleColumnState(4, 80)
1612-
}
1613-
]], true, null, e);
1602+
1603+
const commitOrdering = getCommitOrdering(this.gitRepos[this.currentRepo].commitOrdering);
1604+
const changeCommitOrdering = (repoCommitOrdering: GG.RepoCommitOrdering) => {
1605+
this.saveCommitOrdering(this.currentRepo, repoCommitOrdering);
1606+
this.refresh(true);
1607+
};
1608+
1609+
contextMenu.show([
1610+
[
1611+
{
1612+
title: 'Date',
1613+
visible: true,
1614+
checked: columnWidths[2] !== COLUMN_HIDDEN,
1615+
onClick: () => toggleColumnState(2, 128)
1616+
},
1617+
{
1618+
title: 'Author',
1619+
visible: true,
1620+
checked: columnWidths[3] !== COLUMN_HIDDEN,
1621+
onClick: () => toggleColumnState(3, 128)
1622+
},
1623+
{
1624+
title: 'Commit',
1625+
visible: true,
1626+
checked: columnWidths[4] !== COLUMN_HIDDEN,
1627+
onClick: () => toggleColumnState(4, 80)
1628+
}
1629+
],
1630+
[
1631+
{
1632+
title: 'Commit Timestamp Order',
1633+
visible: true,
1634+
checked: commitOrdering === GG.CommitOrdering.Date,
1635+
onClick: () => changeCommitOrdering(GG.RepoCommitOrdering.Date)
1636+
},
1637+
{
1638+
title: 'Author Timestamp Order',
1639+
visible: true,
1640+
checked: commitOrdering === GG.CommitOrdering.AuthorDate,
1641+
onClick: () => changeCommitOrdering(GG.RepoCommitOrdering.AuthorDate)
1642+
},
1643+
{
1644+
title: 'Topological Order',
1645+
visible: true,
1646+
checked: commitOrdering === GG.CommitOrdering.Topological,
1647+
onClick: () => changeCommitOrdering(GG.RepoCommitOrdering.Topological)
1648+
}
1649+
]
1650+
], true, null, e);
16141651
});
16151652
}
16161653

@@ -3070,6 +3107,19 @@ function getChildByPathSegment(folder: FileTreeFolder, pathSeg: string) {
30703107

30713108
/* Repository State Helpers */
30723109

3110+
function getCommitOrdering(repoValue: GG.RepoCommitOrdering): GG.CommitOrdering {
3111+
switch (repoValue) {
3112+
case GG.RepoCommitOrdering.Default:
3113+
return initialState.config.commitOrdering;
3114+
case GG.RepoCommitOrdering.Date:
3115+
return GG.CommitOrdering.Date;
3116+
case GG.RepoCommitOrdering.AuthorDate:
3117+
return GG.CommitOrdering.AuthorDate;
3118+
case GG.RepoCommitOrdering.Topological:
3119+
return GG.CommitOrdering.Topological;
3120+
}
3121+
}
3122+
30733123
function getShowTags(repoValue: GG.ShowTags) {
30743124
return repoValue === GG.ShowTags.Default
30753125
? initialState.config.showTags

0 commit comments

Comments
 (0)