Adds git diff --shortstat support

This commit is contained in:
Eric Amodio
2017-09-20 01:10:47 -04:00
parent a114e2de87
commit 712544fab8
4 changed files with 37 additions and 2 deletions

View File

@@ -259,6 +259,14 @@ export class Git {
return gitCommand({ cwd: repoPath }, ...params);
}
static diff_shortstat(repoPath: string, sha?: string) {
const params = [`diff`, `--shortstat`, `--no-ext-diff`];
if (sha) {
params.push(sha);
}
return gitCommand({ cwd: repoPath }, ...params);
}
static difftool_dirDiff(repoPath: string, sha1: string, sha2?: string) {
const params = [`difftool`, `--dir-diff`, sha1];
if (sha2) {

View File

@@ -33,4 +33,10 @@ export interface GitDiff {
chunks: GitDiffChunk[];
diff?: string;
}
export interface GitDiffShortStat {
files: number;
insertions: number;
deletions: number;
}

View File

@@ -1,8 +1,9 @@
'use strict';
import { Iterables, Strings } from '../../system';
import { GitDiff, GitDiffChunk, GitDiffChunkLine, GitDiffLine } from './../git';
import { GitDiff, GitDiffChunk, GitDiffChunkLine, GitDiffLine, GitDiffShortStat } from './../git';
const unifiedDiffRegex = /^@@ -([\d]+),([\d]+) [+]([\d]+),([\d]+) @@([\s\S]*?)(?=^@@)/gm;
const shortStatDiffRegex = /^\s*(\d+)\sfiles? changed(?:,\s+(\d+)\s+insertions?\(\+\))?(?:,\s+(\d+)\s+deletions?\(-\))?/;
export class GitDiffParser {
@@ -116,4 +117,20 @@ export class GitDiffParser {
return chunkLines;
}
static parseShortStat(data: string): GitDiffShortStat | undefined {
if (!data) return undefined;
const match = shortStatDiffRegex.exec(data);
if (match == null) return undefined;
const files = match[1];
const insertions = match[2];
const deletions = match[3];
return {
files: files == null ? 0 : parseInt(files, 10),
insertions: insertions == null ? 0 : parseInt(insertions, 10),
deletions: deletions == null ? 0 : parseInt(deletions, 10)
} as GitDiffShortStat;
}
}