Browse Source

Polishes stats in comparisons

main
Eric Amodio 2 years ago
parent
commit
3cf118fe95
3 changed files with 77 additions and 22 deletions
  1. +34
    -10
      src/views/nodes/compareBranchNode.ts
  2. +26
    -9
      src/views/nodes/compareResultsNode.ts
  3. +17
    -3
      src/views/nodes/resultsFilesNode.ts

+ 34
- 10
src/views/nodes/compareBranchNode.ts View File

@ -252,12 +252,17 @@ export class CompareBranchNode extends ViewNode
private async getAheadFilesQuery(): Promise<FilesQueryResults> { private async getAheadFilesQuery(): Promise<FilesQueryResults> {
const comparison = GitRevision.createRange(this._compareWith?.ref || 'HEAD', this.branch.ref || 'HEAD', '...'); const comparison = GitRevision.createRange(this._compareWith?.ref || 'HEAD', this.branch.ref || 'HEAD', '...');
const [filesResult, workingFilesResult] = await Promise.allSettled([
const [filesResult, workingFilesResult, statsResult, workingStatsResult] = await Promise.allSettled([
this.view.container.git.getDiffStatus(this.repoPath, comparison), this.view.container.git.getDiffStatus(this.repoPath, comparison),
this.compareWithWorkingTree ? this.view.container.git.getDiffStatus(this.repoPath, 'HEAD') : undefined, this.compareWithWorkingTree ? this.view.container.git.getDiffStatus(this.repoPath, 'HEAD') : undefined,
this.view.container.git.getChangedFilesCount(this.repoPath, comparison),
this.compareWithWorkingTree
? this.view.container.git.getChangedFilesCount(this.repoPath, 'HEAD')
: undefined,
]); ]);
let files = getSettledValue(filesResult) ?? []; let files = getSettledValue(filesResult) ?? [];
let stats: FilesQueryResults['stats'] = getSettledValue(statsResult);
if (this.compareWithWorkingTree) { if (this.compareWithWorkingTree) {
const workingFiles = getSettledValue(workingFilesResult); const workingFiles = getSettledValue(workingFilesResult);
@ -275,22 +280,42 @@ export class CompareBranchNode extends ViewNode
} }
} }
} }
const workingStats = getSettledValue(workingStatsResult);
if (workingStats != null) {
if (stats == null) {
stats = workingStats;
} else {
stats = {
additions: stats.additions + workingStats.additions,
deletions: stats.deletions + workingStats.deletions,
changedFiles: files.length,
approximated: true,
};
}
}
} }
return { return {
label: `${pluralize('file', files.length, { zero: 'No' })} changed`, label: `${pluralize('file', files.length, { zero: 'No' })} changed`,
files: files, files: files,
stats: stats,
}; };
} }
private async getBehindFilesQuery(): Promise<FilesQueryResults> { private async getBehindFilesQuery(): Promise<FilesQueryResults> {
const comparison = GitRevision.createRange(this.branch.ref, this._compareWith?.ref || 'HEAD', '...'); const comparison = GitRevision.createRange(this.branch.ref, this._compareWith?.ref || 'HEAD', '...');
const files = (await this.view.container.git.getDiffStatus(this.repoPath, comparison)) ?? [];
const [filesResult, statsResult] = await Promise.allSettled([
this.view.container.git.getDiffStatus(this.repoPath, comparison),
this.view.container.git.getChangedFilesCount(this.repoPath, comparison),
]);
const files = getSettledValue(filesResult) ?? [];
return { return {
label: `${pluralize('file', files.length, { zero: 'No' })} changed`, label: `${pluralize('file', files.length, { zero: 'No' })} changed`,
files: files, files: files,
stats: getSettledValue(statsResult),
}; };
} }
@ -327,17 +352,16 @@ export class CompareBranchNode extends ViewNode
comparison = `${this._compareWith.ref}..${this.branch.ref}`; comparison = `${this._compareWith.ref}..${this.branch.ref}`;
} }
const files = (await this.view.container.git.getDiffStatus(this.repoPath, comparison)) ?? [];
const shortstat = await this.view.container.git.getChangedFilesCount(this.uri.repoPath!, comparison);
const [filesResult, statsResult] = await Promise.allSettled([
this.view.container.git.getDiffStatus(this.repoPath, comparison),
this.view.container.git.getChangedFilesCount(this.repoPath, comparison),
]);
const files = getSettledValue(filesResult) ?? [];
return { return {
label:
`${pluralize('file', files.length, { zero: 'No' })} changed` +
` with ${pluralize('addition', shortstat?.additions ?? 0)} and ${pluralize(
'deletion',
shortstat?.deletions ?? 0,
)}`,
label: `${pluralize('file', files.length, { zero: 'No' })} changed`,
files: files, files: files,
stats: getSettledValue(statsResult),
}; };
} }

+ 26
- 9
src/views/nodes/compareResultsNode.ts View File

@ -252,12 +252,15 @@ export class CompareResultsNode extends ViewNode {
comparison: string, comparison: string,
compareWithWorkingTree: boolean, compareWithWorkingTree: boolean,
): Promise<FilesQueryResults> { ): Promise<FilesQueryResults> {
const [filesResult, workingFilesResult] = await Promise.allSettled([
const [filesResult, workingFilesResult, statsResult, workingStatsResult] = await Promise.allSettled([
this.view.container.git.getDiffStatus(this.repoPath, comparison), this.view.container.git.getDiffStatus(this.repoPath, comparison),
compareWithWorkingTree ? this.view.container.git.getDiffStatus(this.repoPath, 'HEAD') : undefined, compareWithWorkingTree ? this.view.container.git.getDiffStatus(this.repoPath, 'HEAD') : undefined,
this.view.container.git.getChangedFilesCount(this.repoPath, comparison),
compareWithWorkingTree ? this.view.container.git.getChangedFilesCount(this.repoPath, 'HEAD') : undefined,
]); ]);
let files = getSettledValue(filesResult) ?? []; let files = getSettledValue(filesResult) ?? [];
let stats: FilesQueryResults['stats'] = getSettledValue(statsResult);
if (compareWithWorkingTree) { if (compareWithWorkingTree) {
const workingFiles = getSettledValue(workingFilesResult); const workingFiles = getSettledValue(workingFilesResult);
@ -275,11 +278,26 @@ export class CompareResultsNode extends ViewNode {
} }
} }
} }
const workingStats = getSettledValue(workingStatsResult);
if (workingStats != null) {
if (stats == null) {
stats = workingStats;
} else {
stats = {
additions: stats.additions + workingStats.additions,
deletions: stats.deletions + workingStats.deletions,
changedFiles: files.length,
approximated: true,
};
}
}
} }
return { return {
label: `${pluralize('file', files.length, { zero: 'No' })} changed`, label: `${pluralize('file', files.length, { zero: 'No' })} changed`,
files: files, files: files,
stats: stats,
}; };
} }
@ -317,17 +335,16 @@ export class CompareResultsNode extends ViewNode {
comparison = `${this._compareWith.ref}..${this._ref.ref}`; comparison = `${this._compareWith.ref}..${this._ref.ref}`;
} }
const files = (await this.view.container.git.getDiffStatus(this.repoPath, comparison)) ?? [];
const shortstat = await this.view.container.git.getChangedFilesCount(this.uri.repoPath!, comparison);
const [filesResult, statsResult] = await Promise.allSettled([
this.view.container.git.getDiffStatus(this.repoPath, comparison),
this.view.container.git.getChangedFilesCount(this.repoPath, comparison),
]);
const files = getSettledValue(filesResult) ?? [];
return { return {
label:
`${pluralize('file', files.length, { zero: 'No' })} changed` +
` with ${pluralize('addition', shortstat?.additions ?? 0)} and ${pluralize(
'deletion',
shortstat?.deletions ?? 0,
)}`,
label: `${pluralize('file', files.length, { zero: 'No' })} changed`,
files: files, files: files,
stats: getSettledValue(statsResult),
}; };
} }

+ 17
- 3
src/views/nodes/resultsFilesNode.ts View File

@ -1,14 +1,14 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../configuration'; import { ViewFilesLayout } from '../../configuration';
import { GitUri } from '../../git/gitUri'; import { GitUri } from '../../git/gitUri';
import { GitFile } from '../../git/models';
import { GitDiffShortStat, GitFile } from '../../git/models';
import { makeHierarchical } from '../../system/array'; import { makeHierarchical } from '../../system/array';
import { gate } from '../../system/decorators/gate'; import { gate } from '../../system/decorators/gate';
import { debug } from '../../system/decorators/log'; import { debug } from '../../system/decorators/log';
import { map } from '../../system/iterable'; import { map } from '../../system/iterable';
import { joinPaths, normalizePath } from '../../system/path'; import { joinPaths, normalizePath } from '../../system/path';
import { cancellable, PromiseCancelledError } from '../../system/promise'; import { cancellable, PromiseCancelledError } from '../../system/promise';
import { sortCompare } from '../../system/string';
import { pluralize, sortCompare } from '../../system/string';
import { ViewsWithCommits } from '../viewBase'; import { ViewsWithCommits } from '../viewBase';
import { FileNode, FolderNode } from './folderNode'; import { FileNode, FolderNode } from './folderNode';
import { ResultsFileNode } from './resultsFileNode'; import { ResultsFileNode } from './resultsFileNode';
@ -22,6 +22,7 @@ export enum FilesQueryFilter {
export interface FilesQueryResults { export interface FilesQueryResults {
label: string; label: string;
files: GitFile[] | undefined; files: GitFile[] | undefined;
stats?: (GitDiffShortStat & { approximated?: boolean }) | undefined;
filtered?: Map<FilesQueryFilter, GitFile[]>; filtered?: Map<FilesQueryFilter, GitFile[]>;
} }
@ -106,15 +107,27 @@ export class ResultsFilesNode extends ViewNode {
async getTreeItem(): Promise<TreeItem> { async getTreeItem(): Promise<TreeItem> {
let label; let label;
let description;
let icon; let icon;
let files: GitFile[] | undefined; let files: GitFile[] | undefined;
let state; let state;
let tooltip;
const filter = this.filter; const filter = this.filter;
try { try {
const results = await cancellable(this.getFilesQueryResults(), 100); const results = await cancellable(this.getFilesQueryResults(), 100);
label = results.label; label = results.label;
if (filter == null && results.stats != null) {
description = `${pluralize('addition', results.stats.additions)} (+), ${pluralize(
'deletion',
results.stats.deletions,
)} (-)${results.stats.approximated ? ' *approximated' : ''}`;
tooltip = `${label}, ${description}`;
}
if (filter != null) { if (filter != null) {
description = 'Filtered';
tooltip = `${label} &mdash; ${description}`;
files = results.filtered?.get(filter); files = results.filtered?.get(filter);
if (files == null) { if (files == null) {
label = 'files changed'; label = 'files changed';
@ -153,12 +166,13 @@ export class ResultsFilesNode extends ViewNode {
`${filter != null && files != null ? `Showing ${files.length} of ` : ''}${label}`, `${filter != null && files != null ? `Showing ${files.length} of ` : ''}${label}`,
state, state,
); );
item.description = filter != null ? 'Filtered' : undefined;
item.description = description;
item.id = this.id; item.id = this.id;
item.iconPath = icon; item.iconPath = icon;
item.contextValue = `${ContextValues.ResultsFiles}${ item.contextValue = `${ContextValues.ResultsFiles}${
this.filterable ? '+filterable' : '' this.filterable ? '+filterable' : ''
}${this.getFilterContextValue()}`; }${this.getFilterContextValue()}`;
item.tooltip = tooltip;
return item; return item;
} }

Loading…
Cancel
Save