From 3cf118fe9565fb7925c95099a74f1d7d0ba8b78d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 19 Jul 2022 19:26:16 -0400 Subject: [PATCH] Polishes stats in comparisons --- src/views/nodes/compareBranchNode.ts | 44 +++++++++++++++++++++++++++-------- src/views/nodes/compareResultsNode.ts | 35 +++++++++++++++++++++------- src/views/nodes/resultsFilesNode.ts | 20 +++++++++++++--- 3 files changed, 77 insertions(+), 22 deletions(-) diff --git a/src/views/nodes/compareBranchNode.ts b/src/views/nodes/compareBranchNode.ts index 3718e6b..396bc03 100644 --- a/src/views/nodes/compareBranchNode.ts +++ b/src/views/nodes/compareBranchNode.ts @@ -252,12 +252,17 @@ export class CompareBranchNode extends ViewNode { 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.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 stats: FilesQueryResults['stats'] = getSettledValue(statsResult); if (this.compareWithWorkingTree) { const workingFiles = getSettledValue(workingFilesResult); @@ -275,22 +280,42 @@ export class CompareBranchNode extends ViewNode { 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 { label: `${pluralize('file', files.length, { zero: 'No' })} changed`, files: files, + stats: getSettledValue(statsResult), }; } @@ -327,17 +352,16 @@ export class CompareBranchNode extends ViewNode { comparison: string, compareWithWorkingTree: boolean, ): Promise { - const [filesResult, workingFilesResult] = await Promise.allSettled([ + const [filesResult, workingFilesResult, statsResult, workingStatsResult] = await Promise.allSettled([ this.view.container.git.getDiffStatus(this.repoPath, comparison), 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 stats: FilesQueryResults['stats'] = getSettledValue(statsResult); if (compareWithWorkingTree) { 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 { label: `${pluralize('file', files.length, { zero: 'No' })} changed`, files: files, + stats: stats, }; } @@ -317,17 +335,16 @@ export class CompareResultsNode extends ViewNode { 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 { - 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, + stats: getSettledValue(statsResult), }; } diff --git a/src/views/nodes/resultsFilesNode.ts b/src/views/nodes/resultsFilesNode.ts index b8fb174..711bf1e 100644 --- a/src/views/nodes/resultsFilesNode.ts +++ b/src/views/nodes/resultsFilesNode.ts @@ -1,14 +1,14 @@ import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { ViewFilesLayout } from '../../configuration'; import { GitUri } from '../../git/gitUri'; -import { GitFile } from '../../git/models'; +import { GitDiffShortStat, GitFile } from '../../git/models'; import { makeHierarchical } from '../../system/array'; import { gate } from '../../system/decorators/gate'; import { debug } from '../../system/decorators/log'; import { map } from '../../system/iterable'; import { joinPaths, normalizePath } from '../../system/path'; import { cancellable, PromiseCancelledError } from '../../system/promise'; -import { sortCompare } from '../../system/string'; +import { pluralize, sortCompare } from '../../system/string'; import { ViewsWithCommits } from '../viewBase'; import { FileNode, FolderNode } from './folderNode'; import { ResultsFileNode } from './resultsFileNode'; @@ -22,6 +22,7 @@ export enum FilesQueryFilter { export interface FilesQueryResults { label: string; files: GitFile[] | undefined; + stats?: (GitDiffShortStat & { approximated?: boolean }) | undefined; filtered?: Map; } @@ -106,15 +107,27 @@ export class ResultsFilesNode extends ViewNode { async getTreeItem(): Promise { let label; + let description; let icon; let files: GitFile[] | undefined; let state; + let tooltip; const filter = this.filter; try { const results = await cancellable(this.getFilesQueryResults(), 100); 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) { + description = 'Filtered'; + tooltip = `${label} — ${description}`; files = results.filtered?.get(filter); if (files == null) { label = 'files changed'; @@ -153,12 +166,13 @@ export class ResultsFilesNode extends ViewNode { `${filter != null && files != null ? `Showing ${files.length} of ` : ''}${label}`, state, ); - item.description = filter != null ? 'Filtered' : undefined; + item.description = description; item.id = this.id; item.iconPath = icon; item.contextValue = `${ContextValues.ResultsFiles}${ this.filterable ? '+filterable' : '' }${this.getFilterContextValue()}`; + item.tooltip = tooltip; return item; }