mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-27 17:25:09 -05:00
Adds git diff --shortstat support
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -33,4 +33,10 @@ export interface GitDiff {
|
||||
chunks: GitDiffChunk[];
|
||||
|
||||
diff?: string;
|
||||
}
|
||||
|
||||
export interface GitDiffShortStat {
|
||||
files: number;
|
||||
insertions: number;
|
||||
deletions: number;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user