Bladeren bron

Polishes stats in comparisons

main
Eric Amodio 2 jaren geleden
bovenliggende
commit
3cf118fe95
3 gewijzigde bestanden met toevoegingen van 77 en 22 verwijderingen
  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 Bestand weergeven

@ -252,12 +252,17 @@ export class CompareBranchNode extends ViewNode
private async getAheadFilesQuery(): Promise<FilesQueryResults> {
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 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,
};
}
private async getBehindFilesQuery(): Promise<FilesQueryResults> {
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 = `${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 {
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),
};
}

+ 26
- 9
src/views/nodes/compareResultsNode.ts Bestand weergeven

@ -252,12 +252,15 @@ export class CompareResultsNode extends ViewNode {
comparison: string,
compareWithWorkingTree: boolean,
): Promise<FilesQueryResults> {
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),
};
}

+ 17
- 3
src/views/nodes/resultsFilesNode.ts Bestand weergeven

@ -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<FilesQueryFilter, GitFile[]>;
}
@ -106,15 +107,27 @@ export class ResultsFilesNode extends ViewNode {
async getTreeItem(): Promise<TreeItem> {
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} &mdash; ${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;
}

Laden…
Annuleren
Opslaan