Skip to content

Commit

Permalink
#304 Override the globally configured commit ordering per repository …
Browse files Browse the repository at this point in the history
…from the Git Graph View Column Header context menu.
  • Loading branch information
mhutchie committed May 30, 2020
1 parent 5c0c7d4 commit cd38dd4
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ export class DataSource implements vscode.Disposable {
* @param showRemoteBranches Are remote branches shown.
* @param includeCommitsMentionedByReflogs Should commits mentioned by reflogs being included.
* @param onlyFollowFirstParent Only follow the first parent of commits.
* @param commitOrdering The order for commits to be returned.
* @param remotes An array of known remotes.
* @param hideRemotes An array of hidden remotes.
* @param stashes An array of all stashes in the repository.
* @returns The commits in the repository.
*/
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> {
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> {
const config = getConfig();
return Promise.all([
this.getLog(repo, branches, maxCommits + 1, showTags && config.showCommitsOnlyReferencedByTags, showRemoteBranches, includeCommitsMentionedByReflogs, onlyFollowFirstParent, config.commitOrdering, remotes, hideRemotes, stashes),
this.getLog(repo, branches, maxCommits + 1, showTags && config.showCommitsOnlyReferencedByTags, showRemoteBranches, includeCommitsMentionedByReflogs, onlyFollowFirstParent, commitOrdering, remotes, hideRemotes, stashes),
this.getRefs(repo, showRemoteBranches, hideRemotes).then((refData: GitRefData) => refData, (errorMessage: string) => errorMessage)
]).then(async (results) => {
let commits: GitCommitRecord[] = results[0], refData: GitRefData | string = results[1], i;
Expand Down
3 changes: 2 additions & 1 deletion src/extensionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs';
import * as vscode from 'vscode';
import { Avatar, AvatarCache } from './avatarManager';
import { Event } from './event';
import { CodeReview, ErrorInfo, FileViewType, GitGraphViewGlobalState, GitRepoSet, GitRepoState, IncludeCommitsMentionedByReflogs, OnlyFollowFirstParent, ShowTags } from './types';
import { CodeReview, ErrorInfo, FileViewType, GitGraphViewGlobalState, GitRepoSet, GitRepoState, IncludeCommitsMentionedByReflogs, OnlyFollowFirstParent, RepoCommitOrdering, ShowTags } from './types';
import { getPathFromStr, GitExecutable } from './utils';

const AVATAR_STORAGE_FOLDER = '/avatars';
Expand All @@ -18,6 +18,7 @@ export const DEFAULT_REPO_STATE: GitRepoState = {
columnWidths: null,
cdvDivider: 0.5,
cdvHeight: 250,
commitOrdering: RepoCommitOrdering.Default,
fileViewType: FileViewType.Default,
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs.Default,
onlyFollowFirstParent: OnlyFollowFirstParent.Default,
Expand Down
3 changes: 2 additions & 1 deletion src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class GitGraphView implements vscode.Disposable {
command: 'loadCommits',
refreshId: msg.refreshId,
onlyFollowFirstParent: msg.onlyFollowFirstParent,
... await this.dataSource.getCommits(msg.repo, msg.branches, msg.maxCommits, msg.showTags, msg.showRemoteBranches, msg.includeCommitsMentionedByReflogs, msg.onlyFollowFirstParent, msg.remotes, msg.hideRemotes, msg.stashes)
... 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)
});
break;
case 'loadRepoInfo':
Expand Down Expand Up @@ -576,6 +576,7 @@ export class GitGraphView implements vscode.Disposable {
branchLabelsAlignedToGraph: refLabelAlignment === RefLabelAlignment.BranchesAlignedToGraphAndTagsOnRight,
combineLocalAndRemoteBranchLabels: config.combineLocalAndRemoteBranchLabels,
commitDetailsViewLocation: config.commitDetailsViewLocation,
commitOrdering: config.commitOrdering,
contextMenuActionsVisibility: config.contextMenuActionsVisibility,
customBranchGlobPatterns: config.customBranchGlobPatterns,
customEmojiShortcodeMappings: config.customEmojiShortcodeMappings,
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export interface GitRepoState {
columnWidths: ColumnWidth[] | null;
cdvDivider: number;
cdvHeight: number;
commitOrdering: RepoCommitOrdering;
fileViewType: FileViewType;
includeCommitsMentionedByReflogs: IncludeCommitsMentionedByReflogs;
onlyFollowFirstParent: OnlyFollowFirstParent;
Expand Down Expand Up @@ -208,6 +209,7 @@ export interface GitGraphViewConfig {
readonly branchLabelsAlignedToGraph: boolean;
readonly combineLocalAndRemoteBranchLabels: boolean;
readonly commitDetailsViewLocation: CommitDetailsViewLocation;
readonly commitOrdering: CommitOrdering;
readonly contextMenuActionsVisibility: ContextMenuActionsVisibility;
readonly customBranchGlobPatterns: CustomBranchGlobPattern[];
readonly customEmojiShortcodeMappings: CustomEmojiShortcodeMapping[];
Expand Down Expand Up @@ -424,6 +426,13 @@ export const enum RefLabelAlignment {
BranchesAlignedToGraphAndTagsOnRight
}

export const enum RepoCommitOrdering {
Default = 'default',
Date = 'date',
AuthorDate = 'author-date',
Topological = 'topo'
}

export const enum ShowTags {
Default,
Show,
Expand Down Expand Up @@ -788,6 +797,7 @@ export interface RequestLoadCommits extends RepoRequest {
readonly showRemoteBranches: boolean;
readonly includeCommitsMentionedByReflogs: boolean;
readonly onlyFollowFirstParent: boolean;
readonly commitOrdering: CommitOrdering;
readonly remotes: string[];
readonly hideRemotes: string[];
readonly stashes: ReadonlyArray<GitStash>;
Expand Down
92 changes: 71 additions & 21 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ class GitGraphView {
showRemoteBranches: repoState.showRemoteBranches,
includeCommitsMentionedByReflogs: getIncludeCommitsMentionedByReflogs(repoState.includeCommitsMentionedByReflogs),
onlyFollowFirstParent: getOnlyFollowFirstParent(repoState.onlyFollowFirstParent),
commitOrdering: getCommitOrdering(repoState.commitOrdering),
remotes: this.gitRemotes,
hideRemotes: repoState.hideRemotes,
stashes: this.gitStashes
Expand Down Expand Up @@ -651,6 +652,13 @@ class GitGraphView {
this.saveState();
}

public saveCommitOrdering(repo: string, commitOrdering: GG.RepoCommitOrdering) {
if (repo === this.currentRepo) {
this.gitRepos[this.currentRepo].commitOrdering = commitOrdering;
this.saveRepoState();
}
}

public saveHiddenRemotes(repo: string, hideRemotes: string[]) {
if (repo === this.currentRepo) {
this.gitRepos[this.currentRepo].hideRemotes = hideRemotes;
Expand Down Expand Up @@ -1585,32 +1593,61 @@ class GitGraphView {

colHeadersElem.addEventListener('contextmenu', (e: MouseEvent) => {
e.stopPropagation();

const toggleColumnState = (col: number, defaultWidth: number) => {
columnWidths[col] = columnWidths[col] !== COLUMN_HIDDEN ? COLUMN_HIDDEN : columnWidths[0] === COLUMN_AUTO ? COLUMN_AUTO : defaultWidth - COLUMN_LEFT_RIGHT_PADDING;
this.saveColumnWidths(columnWidths);
contextMenu.close();
this.render();
};
contextMenu.show([[
{
title: 'Date',
visible: true,
checked: columnWidths[2] !== COLUMN_HIDDEN,
onClick: () => toggleColumnState(2, 128)
},
{
title: 'Author',
visible: true,
checked: columnWidths[3] !== COLUMN_HIDDEN,
onClick: () => toggleColumnState(3, 128)
},
{
title: 'Commit',
visible: true,
checked: columnWidths[4] !== COLUMN_HIDDEN,
onClick: () => toggleColumnState(4, 80)
}
]], true, null, e);

const commitOrdering = getCommitOrdering(this.gitRepos[this.currentRepo].commitOrdering);
const changeCommitOrdering = (repoCommitOrdering: GG.RepoCommitOrdering) => {
this.saveCommitOrdering(this.currentRepo, repoCommitOrdering);
this.refresh(true);
};

contextMenu.show([
[
{
title: 'Date',
visible: true,
checked: columnWidths[2] !== COLUMN_HIDDEN,
onClick: () => toggleColumnState(2, 128)
},
{
title: 'Author',
visible: true,
checked: columnWidths[3] !== COLUMN_HIDDEN,
onClick: () => toggleColumnState(3, 128)
},
{
title: 'Commit',
visible: true,
checked: columnWidths[4] !== COLUMN_HIDDEN,
onClick: () => toggleColumnState(4, 80)
}
],
[
{
title: 'Commit Timestamp Order',
visible: true,
checked: commitOrdering === GG.CommitOrdering.Date,
onClick: () => changeCommitOrdering(GG.RepoCommitOrdering.Date)
},
{
title: 'Author Timestamp Order',
visible: true,
checked: commitOrdering === GG.CommitOrdering.AuthorDate,
onClick: () => changeCommitOrdering(GG.RepoCommitOrdering.AuthorDate)
},
{
title: 'Topological Order',
visible: true,
checked: commitOrdering === GG.CommitOrdering.Topological,
onClick: () => changeCommitOrdering(GG.RepoCommitOrdering.Topological)
}
]
], true, null, e);
});
}

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

/* Repository State Helpers */

function getCommitOrdering(repoValue: GG.RepoCommitOrdering): GG.CommitOrdering {
switch (repoValue) {
case GG.RepoCommitOrdering.Default:
return initialState.config.commitOrdering;
case GG.RepoCommitOrdering.Date:
return GG.CommitOrdering.Date;
case GG.RepoCommitOrdering.AuthorDate:
return GG.CommitOrdering.AuthorDate;
case GG.RepoCommitOrdering.Topological:
return GG.CommitOrdering.Topological;
}
}

function getShowTags(repoValue: GG.ShowTags) {
return repoValue === GG.ShowTags.Default
? initialState.config.showTags
Expand Down

0 comments on commit cd38dd4

Please sign in to comment.