mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 21:11:38 +01:00
Git - incoming/outgoing polish (#197877)
* Git - refactor diffBetweenShortStat to return an object with files, insertions, and deletions * Add statistics label tooltip
This commit is contained in:
@@ -1316,15 +1316,23 @@ export class Repository {
|
||||
return result.stdout.trim();
|
||||
}
|
||||
|
||||
async diffBetweenShortStat(ref1: string, ref2: string): Promise<string> {
|
||||
async diffBetweenShortStat(ref1: string, ref2: string): Promise<{ files: number; insertions: number; deletions: number }> {
|
||||
const args = ['diff', '--shortstat', `${ref1}...${ref2}`];
|
||||
|
||||
const result = await this.exec(args);
|
||||
if (result.exitCode) {
|
||||
return '';
|
||||
return { files: 0, insertions: 0, deletions: 0 };
|
||||
}
|
||||
|
||||
return result.stdout.trim();
|
||||
const regex = /(\d+) files? changed(?:, (\d+) insertions\(\+\))?(?:, (\d+) deletions\(-\))?/;
|
||||
const matches = result.stdout.trim().match(regex);
|
||||
|
||||
if (!matches) {
|
||||
return { files: 0, insertions: 0, deletions: 0 };
|
||||
}
|
||||
|
||||
const [, files, insertions = undefined, deletions = undefined] = matches;
|
||||
return { files: parseInt(files), insertions: parseInt(insertions ?? '0'), deletions: parseInt(deletions ?? '0') };
|
||||
}
|
||||
|
||||
private async diffFiles(cached: boolean, ref?: string): Promise<Change[]> {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlActionButton, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryItemGroup, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, l10n, SourceControlHistoryItemStatistics } from 'vscode';
|
||||
import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlActionButton, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryItemGroup, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, l10n } from 'vscode';
|
||||
import { Repository, Resource } from './repository';
|
||||
import { IDisposable } from './util';
|
||||
import { toGitUri } from './uri';
|
||||
@@ -195,21 +195,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
|
||||
}
|
||||
|
||||
private async getSummaryHistoryItem(ref1: string, ref2: string): Promise<SourceControlHistoryItem> {
|
||||
let statistics: SourceControlHistoryItemStatistics | undefined;
|
||||
|
||||
const diffShortStat = await this.repository.diffBetweenShortStat(ref1, ref2);
|
||||
const regex = /(\d+) files? changed(?:, (\d+) insertions\(\+\))?(?:, (\d+) deletions\(-\))?/;
|
||||
const matches = diffShortStat.match(regex);
|
||||
|
||||
if (matches) {
|
||||
const [, files, insertions = undefined, deletions = undefined] = matches;
|
||||
statistics = {
|
||||
files: parseInt(files),
|
||||
insertions: parseInt(insertions ?? '0'),
|
||||
deletions: parseInt(deletions ?? '0')
|
||||
};
|
||||
}
|
||||
|
||||
const statistics = await this.repository.diffBetweenShortStat(ref1, ref2);
|
||||
return { id: `${ref1}..${ref2}`, parentIds: [], icon: new ThemeIcon('files'), label: l10n.t('All Changes'), statistics };
|
||||
}
|
||||
|
||||
|
||||
@@ -1185,7 +1185,7 @@ export class Repository implements Disposable {
|
||||
return this.run(Operation.Diff, () => this.repository.diffBetween(ref1, ref2, path));
|
||||
}
|
||||
|
||||
diffBetweenShortStat(ref1: string, ref2: string): Promise<string> {
|
||||
diffBetweenShortStat(ref1: string, ref2: string): Promise<{ files: number; insertions: number; deletions: number }> {
|
||||
return this.run(Operation.Diff, () => this.repository.diffBetweenShortStat(ref1, ref2));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user