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:
Ladislau Szomoru
2023-11-10 02:40:58 +01:00
committed by GitHub
parent 8de9ba22b2
commit 64783a4eb9
4 changed files with 29 additions and 23 deletions

View File

@@ -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[]> {