Skip to content

Commit

Permalink
Changes compare nodes to ahead/behind structure
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 13, 2020
1 parent 6017c1d commit 2d0d2e6
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 211 deletions.
66 changes: 0 additions & 66 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3501,24 +3501,6 @@
"light": "images/light/icon-copy.svg"
}
},
{
"command": "gitlens.views.setComparisonToTwoDot",
"title": "Toggle Comparison Type (Two-dot)",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-compare-twodot.svg",
"light": "images/light/icon-compare-twodot.svg"
}
},
{
"command": "gitlens.views.setComparisonToThreeDot",
"title": "Toggle Comparison Type (Three-dot)",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-compare-threedot.svg",
"light": "images/light/icon-compare-threedot.svg"
}
},
{
"command": "gitlens.views.cherryPick",
"title": "Cherry Pick Commit...",
Expand Down Expand Up @@ -4918,14 +4900,6 @@
"command": "gitlens.views.copyContributorToClipboard",
"when": "false"
},
{
"command": "gitlens.views.setComparisonToTwoDot",
"when": "false"
},
{
"command": "gitlens.views.setComparisonToThreeDot",
"when": "false"
},
{
"command": "gitlens.views.createBranch",
"when": "false"
Expand Down Expand Up @@ -7187,16 +7161,6 @@
"when": "viewItem =~ /gitlens:(compare:picker:ref|compare:results\\b(?!.*?\\b\\+pinned\\b)|search)\\b(?!:(commits|files))/",
"group": "inline@99"
},
{
"command": "gitlens.views.setComparisonToTwoDot",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+threedot\\b)/",
"group": "inline@1"
},
{
"command": "gitlens.views.setComparisonToThreeDot",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+twodot\\b)/",
"group": "inline@1"
},
{
"command": "gitlens.views.clearNode",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)/",
Expand All @@ -7212,16 +7176,6 @@
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+working\\b)/",
"group": "inline@2"
},
{
"command": "gitlens.views.setComparisonToTwoDot",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+threedot\\b)/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.setComparisonToThreeDot",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+twodot\\b)/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.views.setBranchComparisonToWorking",
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+branch\\b)/",
Expand All @@ -7247,16 +7201,6 @@
"when": "viewItem =~ /gitlens:compare:branch\\b(?=.*?\\b\\+comparing\\b)/",
"group": "9_gitlens@1"
},
{
"command": "gitlens.views.setComparisonToTwoDot",
"when": "viewItem =~ /gitlens:compare:results\\b(?=.*?\\b\\+threedot\\b)/",
"group": "inline@2"
},
{
"command": "gitlens.views.setComparisonToThreeDot",
"when": "viewItem =~ /gitlens:compare:results\\b(?=.*?\\b\\+twodot\\b)/",
"group": "inline@2"
},
{
"command": "gitlens.views.compare.swapComparison",
"when": "viewItem =~ /gitlens:compare:results\\b/",
Expand All @@ -7282,16 +7226,6 @@
"when": "viewItem =~ /gitlens:compare:results\\b/",
"group": "2_gitlens_quickopen@1"
},
{
"command": "gitlens.views.setComparisonToTwoDot",
"when": "viewItem =~ /gitlens:compare:results\\b(?=.*?\\b\\+threedot\\b)/",
"group": "1_gitlens_actions@1"
},
{
"command": "gitlens.views.setComparisonToThreeDot",
"when": "viewItem =~ /gitlens:compare:results\\b(?=.*?\\b\\+twodot\\b)/",
"group": "1_gitlens_actions@1"
},
{
"command": "gitlens.views.compare.swapComparison",
"when": "viewItem =~ /gitlens:compare:results\\b/",
Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const ImageMimetypes: Record<string, string> = {

export interface BranchComparison {
ref: string;
notation: '...' | '..' | undefined;
notation: '..' | '...' | undefined;
type: Exclude<ViewShowBranchComparison, false> | undefined;
}

Expand All @@ -166,7 +166,7 @@ export interface PinnedComparison {
path: string;
ref1: NamedRef;
ref2: NamedRef;
notation: '...' | '..' | undefined;
notation: '..' | '...' | undefined;
}

export interface PinnedComparisons {
Expand Down
2 changes: 1 addition & 1 deletion src/views/compareView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class CompareView extends ViewBase<CompareNode, CompareViewConfig> {
const pinned = Container.context.workspaceState.get<PinnedComparisons>(WorkspaceState.PinnedComparisons);
if (pinned == null) return [];

return Object.values(pinned).map(p => new CompareResultsNode(this, p.path, p.ref1, p.ref2, true, p.notation));
return Object.values(pinned).map(p => new CompareResultsNode(this, p.path, p.ref1, p.ref2, true));
}

async updatePinnedComparison(id: string, pin?: PinnedComparison) {
Expand Down
84 changes: 43 additions & 41 deletions src/views/nodes/compareBranchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | Rep

if (this._children == null) {
const aheadBehind = await Container.git.getAheadBehindCommitCount(this.branch.repoPath, [
GitRevision.createRange(this.branch.ref || 'HEAD', this._compareWith.ref || 'HEAD', '...'),
GitRevision.createRange(this.branch.ref, this._compareWith.ref || 'HEAD', '...'),
]);

this._children = [
new ResultsCommitsNode(
this.view,
this,
this.uri.repoPath!,
'Behind', //`Behind (${aheadBehind?.behind})`,
'Behind',
this.getCommitsQuery(
GitRevision.createRange(this.branch.ref, this._compareWith?.ref ?? 'HEAD', '..'),
GitRevision.createRange(this.branch.ref, this._compareWith.ref || 'HEAD', '..'),
),
{
id: 'behind',
Expand All @@ -83,10 +83,10 @@ export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | Rep
this.view,
this,
this.uri.repoPath!,
'Ahead', //`Ahead (${aheadBehind?.ahead})`,
'Ahead',
this.getCommitsQuery(
GitRevision.createRange(
this._compareWith?.ref ?? 'HEAD',
this._compareWith.ref || 'HEAD',
this.compareWithWorkingTree ? '' : this.branch.ref,
'..',
),
Expand Down Expand Up @@ -209,45 +209,11 @@ export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | Rep
this.view.triggerNodeChange(this);
}

private getCommitsQuery(range: string): (limit: number | undefined) => Promise<CommitsQueryResults> {
const repoPath = this.uri.repoPath!;
return async (limit: number | undefined) => {
const log = await Container.git.getLog(repoPath, {
limit: limit,
ref: range,
});

const results: Mutable<Partial<CommitsQueryResults>> = {
log: log,
hasMore: log?.hasMore ?? true,
};
if (results.hasMore) {
results.more = async (limit: number | undefined) => {
results.log = (await results.log?.more?.(limit)) ?? results.log;
results.hasMore = results.log?.hasMore ?? true;
};
}

return results as CommitsQueryResults;
};
}

private async getBehindFilesQuery(): Promise<FilesQueryResults> {
const diff = await Container.git.getDiffStatus(
this.uri.repoPath!,
GitRevision.createRange(this.branch.ref, this._compareWith?.ref ?? 'HEAD', '...'),
);

return {
label: `${Strings.pluralize('file', diff !== undefined ? diff.length : 0, { zero: 'No' })} changed`,
files: diff,
};
}

private async getAheadFilesQuery(): Promise<FilesQueryResults> {
let files = await Container.git.getDiffStatus(
this.uri.repoPath!,
GitRevision.createRange(this._compareWith?.ref ?? 'HEAD', this.branch.ref, '...'),
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
GitRevision.createRange(this._compareWith?.ref || 'HEAD', this.branch.ref, '...'),
);

if (this.compareWithWorkingTree) {
Expand All @@ -274,6 +240,42 @@ export class CompareBranchNode extends ViewNode<BranchesView | CommitsView | Rep
};
}

private async getBehindFilesQuery(): Promise<FilesQueryResults> {
const files = await Container.git.getDiffStatus(
this.uri.repoPath!,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
GitRevision.createRange(this.branch.ref, this._compareWith?.ref || 'HEAD', '...'),
);

return {
label: `${Strings.pluralize('file', files?.length ?? 0, { zero: 'No' })} changed`,
files: files,
};
}

private getCommitsQuery(range: string): (limit: number | undefined) => Promise<CommitsQueryResults> {
const repoPath = this.uri.repoPath!;
return async (limit: number | undefined) => {
const log = await Container.git.getLog(repoPath, {
limit: limit,
ref: range,
});

const results: Mutable<Partial<CommitsQueryResults>> = {
log: log,
hasMore: log?.hasMore ?? true,
};
if (results.hasMore) {
results.more = async (limit: number | undefined) => {
results.log = (await results.log?.more?.(limit)) ?? results.log;
results.hasMore = results.log?.hasMore ?? true;
};
}

return results as CommitsQueryResults;
};
}

private async updateCompareWith(compareWith: BranchComparison | undefined) {
this._compareWith = compareWith;

Expand Down

0 comments on commit 2d0d2e6

Please sign in to comment.