mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 18:48:45 -05:00
Optimized parsers for speed & memory usage
Switches to lazy parsing of diff chunks
This commit is contained in:
@@ -41,7 +41,7 @@ export class DiffAnnotationProvider extends AnnotationProviderBase {
|
|||||||
const decorators: DecorationOptions[] = [];
|
const decorators: DecorationOptions[] = [];
|
||||||
|
|
||||||
for (const chunk of diff.chunks) {
|
for (const chunk of diff.chunks) {
|
||||||
let count = chunk.currentStart - 2;
|
let count = chunk.currentPosition.start - 2;
|
||||||
for (const change of chunk.current) {
|
for (const change of chunk.current) {
|
||||||
if (change === undefined) continue;
|
if (change === undefined) continue;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { Arrays } from '../system';
|
import { Arrays } from '../system';
|
||||||
import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
|
||||||
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
import { ActiveEditorCommand, Commands, getCommandUri } from './common';
|
||||||
import { GitCommit, GitService, GitUri } from '../gitService';
|
import { GitBlameCommit, GitService, GitUri } from '../gitService';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import { Messages } from '../messages';
|
import { Messages } from '../messages';
|
||||||
import { OpenInRemoteCommandArgs } from './openInRemote';
|
import { OpenInRemoteCommandArgs } from './openInRemote';
|
||||||
@@ -33,7 +33,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand {
|
|||||||
let commit = blame.commit;
|
let commit = blame.commit;
|
||||||
// If the line is uncommitted, find the previous commit
|
// If the line is uncommitted, find the previous commit
|
||||||
if (commit.isUncommitted) {
|
if (commit.isUncommitted) {
|
||||||
commit = new GitCommit(commit.type, commit.repoPath, commit.previousSha!, commit.previousFileName!, commit.author, commit.date, commit.message);
|
commit = new GitBlameCommit(commit.repoPath, commit.previousSha!, commit.previousFileName!, commit.author, commit.date, commit.message, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
const remotes = Arrays.uniqueBy(await this.git.getRemotes(gitUri.repoPath), _ => _.url, _ => !!_.provider);
|
const remotes = Arrays.uniqueBy(await this.git.getRemotes(gitUri.repoPath), _ => _.url, _ => !!_.provider);
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { GitAuthor, GitCommit, GitCommitLine } from './commit';
|
import { GitAuthor, GitCommitLine } from './commit';
|
||||||
|
import { GitBlameCommit } from './blameCommit';
|
||||||
|
|
||||||
export interface GitBlame {
|
export interface GitBlame {
|
||||||
repoPath: string;
|
repoPath: string;
|
||||||
authors: Map<string, GitAuthor>;
|
authors: Map<string, GitAuthor>;
|
||||||
commits: Map<string, GitCommit>;
|
commits: Map<string, GitBlameCommit>;
|
||||||
lines: GitCommitLine[];
|
lines: GitCommitLine[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GitBlameLine {
|
export interface GitBlameLine {
|
||||||
author: GitAuthor;
|
author: GitAuthor;
|
||||||
commit: GitCommit;
|
commit: GitBlameCommit;
|
||||||
line: GitCommitLine;
|
line: GitCommitLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,6 +21,6 @@ export interface GitBlameLines extends GitBlame {
|
|||||||
|
|
||||||
export interface GitBlameCommitLines {
|
export interface GitBlameCommitLines {
|
||||||
author: GitAuthor;
|
author: GitAuthor;
|
||||||
commit: GitCommit;
|
commit: GitBlameCommit;
|
||||||
lines: GitCommitLine[];
|
lines: GitCommitLine[];
|
||||||
}
|
}
|
||||||
20
src/git/models/blameCommit.ts
Normal file
20
src/git/models/blameCommit.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
'use strict';
|
||||||
|
import { GitCommit, GitCommitLine } from './commit';
|
||||||
|
|
||||||
|
export class GitBlameCommit extends GitCommit {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
repoPath: string,
|
||||||
|
sha: string,
|
||||||
|
fileName: string,
|
||||||
|
author: string,
|
||||||
|
date: Date,
|
||||||
|
message: string,
|
||||||
|
public lines: GitCommitLine[],
|
||||||
|
originalFileName?: string,
|
||||||
|
previousSha?: string,
|
||||||
|
previousFileName?: string
|
||||||
|
) {
|
||||||
|
super('blame', repoPath, sha, fileName, author, date, message, originalFileName, previousSha, previousFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ export type GitCommitType = 'blame' | 'branch' | 'file' | 'stash';
|
|||||||
export class GitCommit {
|
export class GitCommit {
|
||||||
|
|
||||||
type: GitCommitType;
|
type: GitCommitType;
|
||||||
lines: GitCommitLine[];
|
// lines: GitCommitLine[];
|
||||||
originalFileName?: string;
|
originalFileName?: string;
|
||||||
previousSha?: string;
|
previousSha?: string;
|
||||||
previousFileName?: string;
|
previousFileName?: string;
|
||||||
@@ -36,7 +36,7 @@ export class GitCommit {
|
|||||||
public author: string,
|
public author: string,
|
||||||
public date: Date,
|
public date: Date,
|
||||||
public message: string,
|
public message: string,
|
||||||
lines?: GitCommitLine[],
|
// lines?: GitCommitLine[],
|
||||||
originalFileName?: string,
|
originalFileName?: string,
|
||||||
previousSha?: string,
|
previousSha?: string,
|
||||||
previousFileName?: string
|
previousFileName?: string
|
||||||
@@ -44,7 +44,7 @@ export class GitCommit {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
this.fileName = this.fileName && this.fileName.replace(/, ?$/, '');
|
this.fileName = this.fileName && this.fileName.replace(/, ?$/, '');
|
||||||
|
|
||||||
this.lines = lines || [];
|
// this.lines = lines || [];
|
||||||
this.originalFileName = originalFileName;
|
this.originalFileName = originalFileName;
|
||||||
this.previousSha = previousSha;
|
this.previousSha = previousSha;
|
||||||
this.previousFileName = previousFileName;
|
this.previousFileName = previousFileName;
|
||||||
|
|||||||
@@ -1,20 +1,41 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
import { GitDiffParser } from '../parsers/diffParser';
|
||||||
|
|
||||||
export interface GitDiffLine {
|
export interface GitDiffLine {
|
||||||
line: string;
|
line: string;
|
||||||
state: 'added' | 'removed' | 'unchanged';
|
state: 'added' | 'removed' | 'unchanged';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GitDiffChunk {
|
export class GitDiffChunk {
|
||||||
current: (GitDiffLine | undefined)[];
|
|
||||||
currentStart: number;
|
|
||||||
currentEnd: number;
|
|
||||||
|
|
||||||
previous: (GitDiffLine | undefined)[];
|
private _chunk: string | undefined;
|
||||||
previousStart: number;
|
private _current: (GitDiffLine | undefined)[] | undefined;
|
||||||
previousEnd: number;
|
private _previous: (GitDiffLine | undefined)[] | undefined;
|
||||||
|
|
||||||
chunk?: string;
|
constructor(chunk: string, public currentPosition: { start: number, end: number }, public previousPosition: { start: number, end: number }) {
|
||||||
|
this._chunk = chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
get current(): (GitDiffLine | undefined)[] {
|
||||||
|
if (this._chunk !== undefined) {
|
||||||
|
this.parseChunk();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._current!;
|
||||||
|
}
|
||||||
|
|
||||||
|
get previous(): (GitDiffLine | undefined)[] {
|
||||||
|
if (this._chunk !== undefined) {
|
||||||
|
this.parseChunk();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._previous!;
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseChunk() {
|
||||||
|
[this._current, this._previous] = GitDiffParser.parseChunk(this._chunk!);
|
||||||
|
this._chunk = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GitDiff {
|
export interface GitDiff {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Uri } from 'vscode';
|
import { Uri } from 'vscode';
|
||||||
import { GitCommit, GitCommitLine, GitCommitType } from './commit';
|
import { GitCommit, GitCommitType } from './commit';
|
||||||
import { GitStatusFileStatus, IGitStatusFile } from './status';
|
import { GitStatusFileStatus, IGitStatusFile } from './status';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
@@ -23,12 +23,11 @@ export class GitLogCommit extends GitCommit {
|
|||||||
message: string,
|
message: string,
|
||||||
status?: GitStatusFileStatus,
|
status?: GitStatusFileStatus,
|
||||||
fileStatuses?: IGitStatusFile[],
|
fileStatuses?: IGitStatusFile[],
|
||||||
lines?: GitCommitLine[],
|
|
||||||
originalFileName?: string,
|
originalFileName?: string,
|
||||||
previousSha?: string,
|
previousSha?: string,
|
||||||
previousFileName?: string
|
previousFileName?: string
|
||||||
) {
|
) {
|
||||||
super(type, repoPath, sha, fileName, author, date, message, lines, originalFileName, previousSha, previousFileName);
|
super(type, repoPath, sha, fileName, author, date, message, originalFileName, previousSha, previousFileName);
|
||||||
|
|
||||||
this.fileNames = this.fileName;
|
this.fileNames = this.fileName;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
export * from './blame';
|
export * from './blame';
|
||||||
|
export * from './blameCommit';
|
||||||
export * from './branch';
|
export * from './branch';
|
||||||
export * from './commit';
|
export * from './commit';
|
||||||
export * from './diff';
|
export * from './diff';
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { GitCommitLine } from './commit';
|
|
||||||
import { GitLogCommit } from './logCommit';
|
import { GitLogCommit } from './logCommit';
|
||||||
import { GitStatusFileStatus, IGitStatusFile } from './status';
|
import { GitStatusFileStatus, IGitStatusFile } from './status';
|
||||||
|
|
||||||
@@ -14,12 +13,11 @@ export class GitStashCommit extends GitLogCommit {
|
|||||||
message: string,
|
message: string,
|
||||||
status?: GitStatusFileStatus,
|
status?: GitStatusFileStatus,
|
||||||
fileStatuses?: IGitStatusFile[],
|
fileStatuses?: IGitStatusFile[],
|
||||||
lines?: GitCommitLine[],
|
|
||||||
originalFileName?: string,
|
originalFileName?: string,
|
||||||
previousSha?: string,
|
previousSha?: string,
|
||||||
previousFileName?: string
|
previousFileName?: string
|
||||||
) {
|
) {
|
||||||
super('stash', repoPath, sha, fileName, 'You', date, message, status, fileStatuses, lines, originalFileName, previousSha, previousFileName);
|
super('stash', repoPath, sha, fileName, 'You', date, message, status, fileStatuses, originalFileName, previousSha, previousFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
get shortSha() {
|
get shortSha() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import { Git, GitAuthor, GitBlame, GitCommit, GitCommitLine } from './../git';
|
import { Strings } from '../../system';
|
||||||
|
import { Git, GitAuthor, GitBlame, GitBlameCommit, GitCommitLine } from './../git';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
@@ -11,15 +12,9 @@ interface BlameEntry {
|
|||||||
lineCount: number;
|
lineCount: number;
|
||||||
|
|
||||||
author: string;
|
author: string;
|
||||||
// authorEmail?: string;
|
|
||||||
authorDate?: string;
|
authorDate?: string;
|
||||||
authorTimeZone?: string;
|
authorTimeZone?: string;
|
||||||
|
|
||||||
// committer?: string;
|
|
||||||
// committerEmail?: string;
|
|
||||||
// committerDate?: string;
|
|
||||||
// committerTimeZone?: string;
|
|
||||||
|
|
||||||
previousSha?: string;
|
previousSha?: string;
|
||||||
previousFileName?: string;
|
previousFileName?: string;
|
||||||
|
|
||||||
@@ -30,18 +25,25 @@ interface BlameEntry {
|
|||||||
|
|
||||||
export class GitBlameParser {
|
export class GitBlameParser {
|
||||||
|
|
||||||
private static _parseEntries(data: string): BlameEntry[] | undefined {
|
static parse(data: string, repoPath: string | undefined, fileName: string): GitBlame | undefined {
|
||||||
if (!data) return undefined;
|
if (!data) return undefined;
|
||||||
|
|
||||||
const lines = data.split('\n');
|
const authors: Map<string, GitAuthor> = new Map();
|
||||||
if (!lines.length) return undefined;
|
const commits: Map<string, GitBlameCommit> = new Map();
|
||||||
|
const lines: GitCommitLine[] = [];
|
||||||
|
|
||||||
const entries: BlameEntry[] = [];
|
let relativeFileName = repoPath && fileName;
|
||||||
|
|
||||||
let entry: BlameEntry | undefined = undefined;
|
let entry: BlameEntry | undefined = undefined;
|
||||||
let position = -1;
|
let line: string;
|
||||||
while (++position < lines.length) {
|
let lineParts: string[];
|
||||||
const lineParts = lines[position].split(' ');
|
|
||||||
|
let i = -1;
|
||||||
|
let first = true;
|
||||||
|
|
||||||
|
for (line of Strings.lines(data)) {
|
||||||
|
i++;
|
||||||
|
lineParts = line.split(' ');
|
||||||
if (lineParts.length < 2) continue;
|
if (lineParts.length < 2) continue;
|
||||||
|
|
||||||
if (entry === undefined) {
|
if (entry === undefined) {
|
||||||
@@ -62,10 +64,6 @@ export class GitBlameParser {
|
|||||||
: lineParts.slice(1).join(' ').trim();
|
: lineParts.slice(1).join(' ').trim();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case 'author-mail':
|
|
||||||
// entry.authorEmail = lineParts[1].trim();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
case 'author-time':
|
case 'author-time':
|
||||||
entry.authorDate = lineParts[1];
|
entry.authorDate = lineParts[1];
|
||||||
break;
|
break;
|
||||||
@@ -74,22 +72,6 @@ export class GitBlameParser {
|
|||||||
entry.authorTimeZone = lineParts[1];
|
entry.authorTimeZone = lineParts[1];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case 'committer':
|
|
||||||
// entry.committer = lineParts.slice(1).join(' ').trim();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case 'committer-mail':
|
|
||||||
// entry.committerEmail = lineParts[1].trim();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case 'committer-time':
|
|
||||||
// entry.committerDate = lineParts[1];
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case 'committer-tz':
|
|
||||||
// entry.committerTimeZone = lineParts[1];
|
|
||||||
// break;
|
|
||||||
|
|
||||||
case 'summary':
|
case 'summary':
|
||||||
entry.summary = lineParts.slice(1).join(' ').trim();
|
entry.summary = lineParts.slice(1).join(' ').trim();
|
||||||
break;
|
break;
|
||||||
@@ -102,7 +84,15 @@ export class GitBlameParser {
|
|||||||
case 'filename':
|
case 'filename':
|
||||||
entry.fileName = lineParts.slice(1).join(' ');
|
entry.fileName = lineParts.slice(1).join(' ');
|
||||||
|
|
||||||
entries.push(entry);
|
if (first && repoPath === undefined) {
|
||||||
|
// Try to get the repoPath from the most recent commit
|
||||||
|
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName!, ''));
|
||||||
|
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
GitBlameParser._parseEntry(entry, repoPath, relativeFileName, commits, authors, lines);
|
||||||
|
|
||||||
entry = undefined;
|
entry = undefined;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -111,28 +101,26 @@ export class GitBlameParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
commits.forEach(c => {
|
||||||
}
|
if (c.author === undefined) return;
|
||||||
|
|
||||||
static parse(data: string, repoPath: string | undefined, fileName: string): GitBlame | undefined {
|
const author = authors.get(c.author);
|
||||||
const entries = this._parseEntries(data);
|
if (author === undefined) return;
|
||||||
if (!entries) return undefined;
|
|
||||||
|
author.lineCount += c.lines.length;
|
||||||
const authors: Map<string, GitAuthor> = new Map();
|
});
|
||||||
const commits: Map<string, GitCommit> = new Map();
|
|
||||||
const lines: GitCommitLine[] = [];
|
const sortedAuthors = new Map([...authors.entries()].sort((a, b) => b[1].lineCount - a[1].lineCount));
|
||||||
|
|
||||||
let relativeFileName = repoPath && fileName;
|
return {
|
||||||
|
repoPath: repoPath,
|
||||||
for (let i = 0, len = entries.length; i < len; i++) {
|
authors: sortedAuthors,
|
||||||
const entry = entries[i];
|
commits: commits,
|
||||||
|
lines: lines
|
||||||
if (i === 0 && repoPath === undefined) {
|
} as GitBlame;
|
||||||
// Try to get the repoPath from the most recent commit
|
|
||||||
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName!, ''));
|
|
||||||
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static _parseEntry(entry: BlameEntry, repoPath: string | undefined, fileName: string | undefined, commits: Map<string, GitBlameCommit>, authors: Map<string, GitAuthor>, lines: GitCommitLine[]) {
|
||||||
let commit = commits.get(entry.sha);
|
let commit = commits.get(entry.sha);
|
||||||
if (commit === undefined) {
|
if (commit === undefined) {
|
||||||
if (entry.author !== undefined) {
|
if (entry.author !== undefined) {
|
||||||
@@ -146,9 +134,9 @@ export class GitBlameParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commit = new GitCommit('blame', repoPath!, entry.sha, relativeFileName!, entry.author, moment(`${entry.authorDate} ${entry.authorTimeZone}`, 'X +-HHmm').toDate(), entry.summary!);
|
commit = new GitBlameCommit(repoPath!, entry.sha, fileName!, entry.author, moment(`${entry.authorDate} ${entry.authorTimeZone}`, 'X +-HHmm').toDate(), entry.summary!, []);
|
||||||
|
|
||||||
if (relativeFileName !== entry.fileName) {
|
if (fileName !== entry.fileName) {
|
||||||
commit.originalFileName = entry.fileName;
|
commit.originalFileName = entry.fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,11 +148,11 @@ export class GitBlameParser {
|
|||||||
commits.set(entry.sha, commit);
|
commits.set(entry.sha, commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let j = 0, len = entry.lineCount; j < len; j++) {
|
for (let i = 0, len = entry.lineCount; i < len; i++) {
|
||||||
const line: GitCommitLine = {
|
const line: GitCommitLine = {
|
||||||
sha: entry.sha,
|
sha: entry.sha,
|
||||||
line: entry.line + j,
|
line: entry.line + i,
|
||||||
originalLine: entry.originalLine + j
|
originalLine: entry.originalLine + i
|
||||||
};
|
};
|
||||||
|
|
||||||
if (commit.previousSha) {
|
if (commit.previousSha) {
|
||||||
@@ -175,33 +163,4 @@ export class GitBlameParser {
|
|||||||
lines[line.line] = line;
|
lines[line.line] = line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commits.forEach(c => {
|
|
||||||
if (c.author === undefined) return;
|
|
||||||
|
|
||||||
const author = authors.get(c.author);
|
|
||||||
if (author === undefined) return;
|
|
||||||
|
|
||||||
author.lineCount += c.lines.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
const sortedAuthors: Map<string, GitAuthor> = new Map();
|
|
||||||
// const values =
|
|
||||||
Array.from(authors.values())
|
|
||||||
.sort((a, b) => b.lineCount - a.lineCount)
|
|
||||||
.forEach(a => sortedAuthors.set(a.name, a));
|
|
||||||
|
|
||||||
// const sortedCommits: Map<string, IGitCommit> = new Map();
|
|
||||||
// Array.from(commits.values())
|
|
||||||
// .sort((a, b) => b.date.getTime() - a.date.getTime())
|
|
||||||
// .forEach(c => sortedCommits.set(c.sha, c));
|
|
||||||
|
|
||||||
return {
|
|
||||||
repoPath: repoPath,
|
|
||||||
authors: sortedAuthors,
|
|
||||||
// commits: sortedCommits,
|
|
||||||
commits: commits,
|
|
||||||
lines: lines
|
|
||||||
} as GitBlame;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
import { Iterables, Strings } from '../../system';
|
||||||
import { GitDiff, GitDiffChunk, GitDiffLine } from './../git';
|
import { GitDiff, GitDiffChunk, GitDiffLine } from './../git';
|
||||||
|
|
||||||
const unifiedDiffRegex = /^@@ -([\d]+),([\d]+) [+]([\d]+),([\d]+) @@([\s\S]*?)(?=^@@)/gm;
|
const unifiedDiffRegex = /^@@ -([\d]+),([\d]+) [+]([\d]+),([\d]+) @@([\s\S]*?)(?=^@@)/gm;
|
||||||
@@ -19,7 +20,20 @@ export class GitDiffParser {
|
|||||||
const currentStart = +match[3];
|
const currentStart = +match[3];
|
||||||
|
|
||||||
const chunk = match[5];
|
const chunk = match[5];
|
||||||
const lines = chunk.split('\n').slice(1);
|
chunks.push(new GitDiffChunk(chunk, { start: currentStart, end: currentStart + +match[4] }, { start: previousStart, end: previousStart + +match[2] }));
|
||||||
|
} while (match != null);
|
||||||
|
|
||||||
|
if (!chunks.length) return undefined;
|
||||||
|
|
||||||
|
const diff = {
|
||||||
|
diff: debug ? data : undefined,
|
||||||
|
chunks: chunks
|
||||||
|
} as GitDiff;
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static parseChunk(chunk: string): [(GitDiffLine | undefined)[], (GitDiffLine | undefined)[]] {
|
||||||
|
const lines = Iterables.skip(Strings.lines(chunk), 1);
|
||||||
|
|
||||||
const current: (GitDiffLine | undefined)[] = [];
|
const current: (GitDiffLine | undefined)[] = [];
|
||||||
const previous: (GitDiffLine | undefined)[] = [];
|
const previous: (GitDiffLine | undefined)[] = [];
|
||||||
@@ -48,23 +62,6 @@ export class GitDiffParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chunks.push({
|
return [current, previous];
|
||||||
chunk: debug ? chunk : undefined,
|
|
||||||
current: current,
|
|
||||||
currentStart: currentStart,
|
|
||||||
currentEnd: currentStart + +match[4],
|
|
||||||
previous: previous,
|
|
||||||
previousStart: previousStart,
|
|
||||||
previousEnd: previousStart + +match[2]
|
|
||||||
});
|
|
||||||
} while (match != null);
|
|
||||||
|
|
||||||
if (!chunks.length) return undefined;
|
|
||||||
|
|
||||||
const diff = {
|
|
||||||
diff: debug ? data : undefined,
|
|
||||||
chunks: chunks
|
|
||||||
} as GitDiff;
|
|
||||||
return diff;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
import { Strings } from '../../system';
|
||||||
import { Range } from 'vscode';
|
import { Range } from 'vscode';
|
||||||
import { Git, GitAuthor, GitCommitType, GitLog, GitLogCommit, GitStatusFileStatus, IGitStatusFile } from './../git';
|
import { Git, GitAuthor, GitCommitType, GitLog, GitLogCommit, GitStatusFileStatus, IGitStatusFile } from './../git';
|
||||||
// import { Logger } from '../../logger';
|
// import { Logger } from '../../logger';
|
||||||
@@ -11,9 +12,6 @@ interface LogEntry {
|
|||||||
author: string;
|
author: string;
|
||||||
authorDate?: string;
|
authorDate?: string;
|
||||||
|
|
||||||
// committer?: string;
|
|
||||||
// committerDate?: string;
|
|
||||||
|
|
||||||
parentShas?: string[];
|
parentShas?: string[];
|
||||||
|
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
@@ -29,24 +27,47 @@ const diffRegex = /diff --git a\/(.*) b\/(.*)/;
|
|||||||
|
|
||||||
export class GitLogParser {
|
export class GitLogParser {
|
||||||
|
|
||||||
private static _parseEntries(data: string, type: GitCommitType, maxCount: number | undefined, reverse: boolean): LogEntry[] | undefined {
|
static parse(data: string, type: GitCommitType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range | undefined): GitLog | undefined {
|
||||||
if (!data) return undefined;
|
if (!data) return undefined;
|
||||||
|
|
||||||
const lines = data.split('\n');
|
const authors: Map<string, GitAuthor> = new Map();
|
||||||
if (!lines.length) return undefined;
|
const commits: Map<string, GitLogCommit> = new Map();
|
||||||
|
|
||||||
const entries: LogEntry[] = [];
|
let relativeFileName: string;
|
||||||
|
let recentCommit: GitLogCommit | undefined = undefined;
|
||||||
|
|
||||||
|
if (repoPath !== undefined) {
|
||||||
|
repoPath = Git.normalizePath(repoPath);
|
||||||
|
}
|
||||||
|
|
||||||
let entry: LogEntry | undefined = undefined;
|
let entry: LogEntry | undefined = undefined;
|
||||||
let position = -1;
|
let line: string | undefined = undefined;
|
||||||
while (++position < lines.length) {
|
let lineParts: string[];
|
||||||
// Since log --reverse doesn't properly honor a max count -- enforce it here
|
let next: IteratorResult<string> | undefined = undefined;
|
||||||
if (reverse && maxCount && (entries.length >= maxCount)) break;
|
|
||||||
|
|
||||||
let lineParts = lines[position].split(' ');
|
let i = -1;
|
||||||
if (lineParts.length < 2) {
|
let first = true;
|
||||||
continue;
|
let skip = false;
|
||||||
|
|
||||||
|
const lines = Strings.lines(data);
|
||||||
|
// for (line of lines) {
|
||||||
|
while (true) {
|
||||||
|
if (!skip) {
|
||||||
|
next = lines.next();
|
||||||
|
if (next.done) break;
|
||||||
|
|
||||||
|
line = next.value;
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
skip = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since log --reverse doesn't properly honor a max count -- enforce it here
|
||||||
|
if (reverse && maxCount && (i >= maxCount)) break;
|
||||||
|
|
||||||
|
lineParts = line!.split(' ');
|
||||||
|
if (lineParts.length < 2) continue;
|
||||||
|
|
||||||
if (entry === undefined) {
|
if (entry === undefined) {
|
||||||
if (!Git.shaRegex.test(lineParts[0])) continue;
|
if (!Git.shaRegex.test(lineParts[0])) continue;
|
||||||
@@ -69,47 +90,54 @@ export class GitLogParser {
|
|||||||
entry.authorDate = `${lineParts[1]}T${lineParts[2]}${lineParts[3]}`;
|
entry.authorDate = `${lineParts[1]}T${lineParts[2]}${lineParts[3]}`;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case 'committer':
|
|
||||||
// entry.committer = lineParts.slice(1).join(' ').trim();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// case 'committer-date':
|
|
||||||
// entry.committerDate = lineParts.slice(1).join(' ').trim();
|
|
||||||
// break;
|
|
||||||
|
|
||||||
case 'parents':
|
case 'parents':
|
||||||
entry.parentShas = lineParts.slice(1);
|
entry.parentShas = lineParts.slice(1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'summary':
|
case 'summary':
|
||||||
entry.summary = lineParts.slice(1).join(' ').trim();
|
entry.summary = lineParts.slice(1).join(' ').trim();
|
||||||
while (++position < lines.length) {
|
while (true) {
|
||||||
const next = lines[position];
|
next = lines.next();
|
||||||
if (!next) break;
|
if (next.done) break;
|
||||||
if (next === 'filename ?') {
|
|
||||||
position--;
|
i++;
|
||||||
|
line = next.value;
|
||||||
|
if (!line) break;
|
||||||
|
|
||||||
|
if (line === 'filename ?') {
|
||||||
|
skip = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.summary += `\n${lines[position]}`;
|
entry.summary += `\n${line}`;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'filename':
|
case 'filename':
|
||||||
if (type === 'branch') {
|
if (type === 'branch') {
|
||||||
const nextLine = lines[position + 1];
|
next = lines.next();
|
||||||
// If the next line isn't blank, make sure it isn't starting a new commit
|
if (next.done) break;
|
||||||
if (nextLine && Git.shaRegex.test(nextLine)) continue;
|
|
||||||
|
|
||||||
position++;
|
i++;
|
||||||
|
line = next.value;
|
||||||
|
|
||||||
|
// If the next line isn't blank, make sure it isn't starting a new commit
|
||||||
|
if (line && Git.shaRegex.test(line)) {
|
||||||
|
skip = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let diff = false;
|
let diff = false;
|
||||||
while (++position < lines.length) {
|
while (true) {
|
||||||
const line = lines[position];
|
next = lines.next();
|
||||||
|
if (next.done) break;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
line = next.value;
|
||||||
lineParts = line.split(' ');
|
lineParts = line.split(' ');
|
||||||
|
|
||||||
if (Git.shaRegex.test(lineParts[0])) {
|
if (Git.shaRegex.test(lineParts[0])) {
|
||||||
position--;
|
skip = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,46 +175,18 @@ export class GitLogParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
position += 2;
|
next = lines.next();
|
||||||
const line = lines[position];
|
next = lines.next();
|
||||||
|
|
||||||
|
i += 2;
|
||||||
|
line = next.value;
|
||||||
|
|
||||||
entry.status = line[0] as GitStatusFileStatus;
|
entry.status = line[0] as GitStatusFileStatus;
|
||||||
entry.fileName = line.substring(1);
|
entry.fileName = line.substring(1);
|
||||||
this._parseFileName(entry);
|
this._parseFileName(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
entries.push(entry);
|
if (first && repoPath === undefined && type === 'file' && fileName !== undefined) {
|
||||||
entry = undefined;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
static parse(data: string, type: GitCommitType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range | undefined): GitLog | undefined {
|
|
||||||
const entries = this._parseEntries(data, type, maxCount, reverse);
|
|
||||||
if (!entries) return undefined;
|
|
||||||
|
|
||||||
const authors: Map<string, GitAuthor> = new Map();
|
|
||||||
const commits: Map<string, GitLogCommit> = new Map();
|
|
||||||
|
|
||||||
let relativeFileName: string;
|
|
||||||
let recentCommit: GitLogCommit | undefined = undefined;
|
|
||||||
|
|
||||||
if (repoPath !== undefined) {
|
|
||||||
repoPath = Git.normalizePath(repoPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0, len = entries.length; i < len; i++) {
|
|
||||||
// Since log --reverse doesn't properly honor a max count -- enforce it here
|
|
||||||
if (reverse && maxCount && (i >= maxCount)) break;
|
|
||||||
|
|
||||||
const entry = entries[i];
|
|
||||||
|
|
||||||
if (i === 0 && repoPath === undefined && type === 'file' && fileName !== undefined) {
|
|
||||||
// Try to get the repoPath from the most recent commit
|
// Try to get the repoPath from the most recent commit
|
||||||
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName!, ''));
|
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName!, ''));
|
||||||
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
|
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
|
||||||
@@ -194,7 +194,30 @@ export class GitLogParser {
|
|||||||
else {
|
else {
|
||||||
relativeFileName = entry.fileName!;
|
relativeFileName = entry.fileName!;
|
||||||
}
|
}
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
recentCommit = GitLogParser._parseEntry(entry, type, repoPath, relativeFileName, commits, authors, recentCommit);
|
||||||
|
|
||||||
|
entry = undefined;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next!.done) break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
repoPath: repoPath,
|
||||||
|
authors: authors,
|
||||||
|
commits: commits,
|
||||||
|
sha: sha,
|
||||||
|
maxCount: maxCount,
|
||||||
|
range: range,
|
||||||
|
truncated: !!(maxCount && i >= maxCount)
|
||||||
|
} as GitLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static _parseEntry(entry: LogEntry, type: GitCommitType, repoPath: string | undefined, relativeFileName: string, commits: Map<string, GitLogCommit>, authors: Map<string, GitAuthor>, recentCommit: GitLogCommit | undefined): GitLogCommit | undefined {
|
||||||
let commit = commits.get(entry.sha);
|
let commit = commits.get(entry.sha);
|
||||||
if (commit === undefined) {
|
if (commit === undefined) {
|
||||||
if (entry.author !== undefined) {
|
if (entry.author !== undefined) {
|
||||||
@@ -233,39 +256,7 @@ export class GitLogParser {
|
|||||||
commit.nextFileName = recentCommit.originalFileName || recentCommit.fileName;
|
commit.nextFileName = recentCommit.originalFileName || recentCommit.fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recentCommit = commit;
|
return commit;
|
||||||
}
|
|
||||||
|
|
||||||
commits.forEach(c => {
|
|
||||||
if (c.author === undefined) return;
|
|
||||||
|
|
||||||
const author = authors.get(c.author);
|
|
||||||
if (author === undefined) return;
|
|
||||||
|
|
||||||
author.lineCount += c.lines.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
const sortedAuthors: Map<string, GitAuthor> = new Map();
|
|
||||||
// const values =
|
|
||||||
Array.from(authors.values())
|
|
||||||
.sort((a, b) => b.lineCount - a.lineCount)
|
|
||||||
.forEach(a => sortedAuthors.set(a.name, a));
|
|
||||||
|
|
||||||
// const sortedCommits: Map<string, IGitCommit> = new Map();
|
|
||||||
// Array.from(commits.values())
|
|
||||||
// .sort((a, b) => b.date.getTime() - a.date.getTime())
|
|
||||||
// .forEach(c => sortedCommits.set(c.sha, c));
|
|
||||||
|
|
||||||
return {
|
|
||||||
repoPath: repoPath,
|
|
||||||
authors: sortedAuthors,
|
|
||||||
// commits: sortedCommits,
|
|
||||||
commits: commits,
|
|
||||||
sha: sha,
|
|
||||||
maxCount: maxCount,
|
|
||||||
range: range,
|
|
||||||
truncated: !!(maxCount && entries.length >= maxCount)
|
|
||||||
} as GitLog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _parseFileName(entry: { fileName?: string, originalFileName?: string }) {
|
private static _parseFileName(entry: { fileName?: string, originalFileName?: string }) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { CancellationToken, CodeLens, CodeLensProvider, Command, commands, Docum
|
|||||||
import { Commands, DiffWithPreviousCommandArgs, ShowBlameHistoryCommandArgs, ShowFileHistoryCommandArgs, ShowQuickCommitDetailsCommandArgs, ShowQuickCommitFileDetailsCommandArgs, ShowQuickFileHistoryCommandArgs } from './commands';
|
import { Commands, DiffWithPreviousCommandArgs, ShowBlameHistoryCommandArgs, ShowFileHistoryCommandArgs, ShowQuickCommitDetailsCommandArgs, ShowQuickCommitFileDetailsCommandArgs, ShowQuickFileHistoryCommandArgs } from './commands';
|
||||||
import { BuiltInCommands, DocumentSchemes, ExtensionKey } from './constants';
|
import { BuiltInCommands, DocumentSchemes, ExtensionKey } from './constants';
|
||||||
import { CodeLensCommand, CodeLensLocations, ICodeLensLanguageLocation, IConfig } from './configuration';
|
import { CodeLensCommand, CodeLensLocations, ICodeLensLanguageLocation, IConfig } from './configuration';
|
||||||
import { GitBlame, GitBlameLines, GitCommit, GitService, GitUri } from './gitService';
|
import { GitBlame, GitBlameCommit, GitBlameLines, GitService, GitUri } from './gitService';
|
||||||
import { Logger } from './logger';
|
import { Logger } from './logger';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyShowBlameHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitCommit): T {
|
_applyShowBlameHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitBlameCommit): T {
|
||||||
let line = lens.range.start.line;
|
let line = lens.range.start.line;
|
||||||
if (commit) {
|
if (commit) {
|
||||||
const blameLine = commit.lines.find(_ => _.line === line);
|
const blameLine = commit.lines.find(_ => _.line === line);
|
||||||
@@ -330,7 +330,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyShowFileHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitCommit): T {
|
_applyShowFileHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitBlameCommit): T {
|
||||||
let line = lens.range.start.line;
|
let line = lens.range.start.line;
|
||||||
if (commit) {
|
if (commit) {
|
||||||
const blameLine = commit.lines.find(_ => _.line === line);
|
const blameLine = commit.lines.find(_ => _.line === line);
|
||||||
@@ -355,7 +355,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyDiffWithPreviousCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitCommit): T {
|
_applyDiffWithPreviousCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitBlameCommit): T {
|
||||||
if (commit === undefined) {
|
if (commit === undefined) {
|
||||||
const blameLine = blame.allLines[lens.range.start.line];
|
const blameLine = blame.allLines[lens.range.start.line];
|
||||||
commit = blame.commits.get(blameLine.sha);
|
commit = blame.commits.get(blameLine.sha);
|
||||||
@@ -375,7 +375,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyShowQuickCommitDetailsCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitCommit): T {
|
_applyShowQuickCommitDetailsCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitBlameCommit): T {
|
||||||
lens.command = {
|
lens.command = {
|
||||||
title: title,
|
title: title,
|
||||||
command: commit !== undefined && commit.isUncommitted ? '' : CodeLensCommand.ShowQuickCommitDetails,
|
command: commit !== undefined && commit.isUncommitted ? '' : CodeLensCommand.ShowQuickCommitDetails,
|
||||||
@@ -389,7 +389,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyShowQuickCommitFileDetailsCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitCommit): T {
|
_applyShowQuickCommitFileDetailsCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitBlameCommit): T {
|
||||||
lens.command = {
|
lens.command = {
|
||||||
title: title,
|
title: title,
|
||||||
command: commit !== undefined && commit.isUncommitted ? '' : CodeLensCommand.ShowQuickCommitFileDetails,
|
command: commit !== undefined && commit.isUncommitted ? '' : CodeLensCommand.ShowQuickCommitFileDetails,
|
||||||
@@ -403,7 +403,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyShowQuickFileHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitCommit): T {
|
_applyShowQuickFileHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitBlameCommit): T {
|
||||||
lens.command = {
|
lens.command = {
|
||||||
title: title,
|
title: title,
|
||||||
command: CodeLensCommand.ShowQuickFileHistory,
|
command: CodeLensCommand.ShowQuickFileHistory,
|
||||||
@@ -417,7 +417,7 @@ export class GitCodeLensProvider implements CodeLensProvider {
|
|||||||
return lens;
|
return lens;
|
||||||
}
|
}
|
||||||
|
|
||||||
_applyShowQuickBranchHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitCommit): T {
|
_applyShowQuickBranchHistoryCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(title: string, lens: T, blame: GitBlameLines, commit?: GitBlameCommit): T {
|
||||||
lens.command = {
|
lens.command = {
|
||||||
title: title,
|
title: title,
|
||||||
command: CodeLensCommand.ShowQuickCurrentBranchHistory,
|
command: CodeLensCommand.ShowQuickCurrentBranchHistory,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Disposable, Event, EventEmitter, ExtensionContext, FileSystemWatcher, l
|
|||||||
import { CommandContext, setCommandContext } from './commands';
|
import { CommandContext, setCommandContext } from './commands';
|
||||||
import { IConfig } from './configuration';
|
import { IConfig } from './configuration';
|
||||||
import { DocumentSchemes, ExtensionKey } from './constants';
|
import { DocumentSchemes, ExtensionKey } from './constants';
|
||||||
import { Git, GitAuthor, GitBlame, GitBlameLine, GitBlameLines, GitBlameParser, GitBranch, GitCommit, GitDiff, GitDiffLine, GitDiffParser, GitLog, GitLogCommit, GitLogParser, GitRemote, GitStash, GitStashParser, GitStatus, GitStatusFile, GitStatusParser, IGit, setDefaultEncoding } from './git/git';
|
import { Git, GitAuthor, GitBlame, GitBlameCommit, GitBlameLine, GitBlameLines, GitBlameParser, GitBranch, GitCommit, GitDiff, GitDiffLine, GitDiffParser, GitLog, GitLogCommit, GitLogParser, GitRemote, GitStash, GitStashParser, GitStatus, GitStatusFile, GitStatusParser, IGit, setDefaultEncoding } from './git/git';
|
||||||
import { GitUri, IGitCommitInfo, IGitUriData } from './git/gitUri';
|
import { GitUri, IGitCommitInfo, IGitUriData } from './git/gitUri';
|
||||||
import { GitCodeLensProvider } from './gitCodeLensProvider';
|
import { GitCodeLensProvider } from './gitCodeLensProvider';
|
||||||
import { Logger } from './logger';
|
import { Logger } from './logger';
|
||||||
@@ -395,7 +395,8 @@ export class GitService extends Disposable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.blame(root, file, uri.sha);
|
const data = await Git.blame(root, file, uri.sha);
|
||||||
return GitBlameParser.parse(data, root, file);
|
const blame = GitBlameParser.parse(data, root, file);
|
||||||
|
return blame;
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
// Trap and cache expected blame errors
|
// Trap and cache expected blame errors
|
||||||
@@ -480,15 +481,14 @@ export class GitService extends Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lines = blame.lines.slice(range.start.line, range.end.line + 1);
|
const lines = blame.lines.slice(range.start.line, range.end.line + 1);
|
||||||
const shas: Set<string> = new Set();
|
const shas = new Set(lines.map(l => l.sha));
|
||||||
lines.forEach(l => shas.add(l.sha));
|
|
||||||
|
|
||||||
const authors: Map<string, GitAuthor> = new Map();
|
const authors: Map<string, GitAuthor> = new Map();
|
||||||
const commits: Map<string, GitCommit> = new Map();
|
const commits: Map<string, GitBlameCommit> = new Map();
|
||||||
blame.commits.forEach(c => {
|
for (const c of blame.commits.values()) {
|
||||||
if (!shas.has(c.sha)) return;
|
if (!shas.has(c.sha)) return;
|
||||||
|
|
||||||
const commit: GitCommit = new GitCommit('blame', c.repoPath, c.sha, c.fileName, c.author, c.date, c.message,
|
const commit = new GitBlameCommit(c.repoPath, c.sha, c.fileName, c.author, c.date, c.message,
|
||||||
c.lines.filter(l => l.line >= range.start.line && l.line <= range.end.line), c.originalFileName, c.previousSha, c.previousFileName);
|
c.lines.filter(l => l.line >= range.start.line && l.line <= range.end.line), c.originalFileName, c.previousSha, c.previousFileName);
|
||||||
commits.set(c.sha, commit);
|
commits.set(c.sha, commit);
|
||||||
|
|
||||||
@@ -502,12 +502,9 @@ export class GitService extends Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
author.lineCount += commit.lines.length;
|
author.lineCount += commit.lines.length;
|
||||||
});
|
}
|
||||||
|
|
||||||
const sortedAuthors: Map<string, GitAuthor> = new Map();
|
const sortedAuthors = new Map([...authors.entries()].sort((a, b) => b[1].lineCount - a[1].lineCount));
|
||||||
Array.from(authors.values())
|
|
||||||
.sort((a, b) => b.lineCount - a.lineCount)
|
|
||||||
.forEach(a => sortedAuthors.set(a.name, a));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
authors: sortedAuthors,
|
authors: sortedAuthors,
|
||||||
@@ -629,7 +626,8 @@ export class GitService extends Disposable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.diff(root, file, sha1, sha2);
|
const data = await Git.diff(root, file, sha1, sha2);
|
||||||
return GitDiffParser.parse(data);
|
const diff = GitDiffParser.parse(data);
|
||||||
|
return diff;
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
// Trap and cache expected diff errors
|
// Trap and cache expected diff errors
|
||||||
@@ -654,12 +652,12 @@ export class GitService extends Disposable {
|
|||||||
const diff = await this.getDiffForFile(uri, sha1, sha2);
|
const diff = await this.getDiffForFile(uri, sha1, sha2);
|
||||||
if (diff === undefined) return [undefined, undefined];
|
if (diff === undefined) return [undefined, undefined];
|
||||||
|
|
||||||
const chunk = diff.chunks.find(_ => _.currentStart <= line && _.currentEnd >= line);
|
const chunk = diff.chunks.find(_ => _.currentPosition.start <= line && _.currentPosition.end >= line);
|
||||||
if (chunk === undefined) return [undefined, undefined];
|
if (chunk === undefined) return [undefined, undefined];
|
||||||
|
|
||||||
// Search for the line (skipping deleted lines -- since they don't currently exist in the editor)
|
// Search for the line (skipping deleted lines -- since they don't currently exist in the editor)
|
||||||
// Keep track of the deleted lines for the original version
|
// Keep track of the deleted lines for the original version
|
||||||
line = line - chunk.currentStart + 1;
|
line = line - chunk.currentPosition.start + 1;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
let deleted = 0;
|
let deleted = 0;
|
||||||
for (const l of chunk.current) {
|
for (const l of chunk.current) {
|
||||||
@@ -676,7 +674,7 @@ export class GitService extends Disposable {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
chunk.previous[line + deleted - 1],
|
chunk.previous[line + deleted - 1],
|
||||||
chunk.current[line + deleted + (chunk.currentStart - chunk.previousStart)]
|
chunk.current[line + deleted + (chunk.currentPosition.start - chunk.previousPosition.start)]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
@@ -715,7 +713,8 @@ export class GitService extends Disposable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.log(repoPath, sha, maxCount, reverse);
|
const data = await Git.log(repoPath, sha, maxCount, reverse);
|
||||||
return GitLogParser.parse(data, 'branch', repoPath, undefined, sha, maxCount, reverse, undefined);
|
const log = GitLogParser.parse(data, 'branch', repoPath, undefined, sha, maxCount, reverse, undefined);
|
||||||
|
return log;
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -748,7 +747,8 @@ export class GitService extends Disposable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.log_search(repoPath, searchArgs, maxCount);
|
const data = await Git.log_search(repoPath, searchArgs, maxCount);
|
||||||
return GitLogParser.parse(data, 'branch', repoPath, undefined, undefined, maxCount, false, undefined);
|
const log = GitLogParser.parse(data, 'branch', repoPath, undefined, undefined, maxCount, false, undefined);
|
||||||
|
return log;
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -830,7 +830,8 @@ export class GitService extends Disposable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.log_file(root, file, sha, maxCount, reverse, range && range.start.line + 1, range && range.end.line + 1);
|
const data = await Git.log_file(root, file, sha, maxCount, reverse, range && range.start.line + 1, range && range.end.line + 1);
|
||||||
return GitLogParser.parse(data, 'file', root, file, sha, maxCount, reverse, range);
|
const log = GitLogParser.parse(data, 'file', root, file, sha, maxCount, reverse, range);
|
||||||
|
return log;
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
// Trap and cache expected log errors
|
// Trap and cache expected log errors
|
||||||
@@ -915,7 +916,8 @@ export class GitService extends Disposable {
|
|||||||
Logger.log(`getStash('${repoPath}')`);
|
Logger.log(`getStash('${repoPath}')`);
|
||||||
|
|
||||||
const data = await Git.stash_list(repoPath);
|
const data = await Git.stash_list(repoPath);
|
||||||
return GitStashParser.parse(data, repoPath);
|
const stash = GitStashParser.parse(data, repoPath);
|
||||||
|
return stash;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getStatusForFile(repoPath: string, fileName: string): Promise<GitStatusFile | undefined> {
|
async getStatusForFile(repoPath: string, fileName: string): Promise<GitStatusFile | undefined> {
|
||||||
@@ -936,7 +938,8 @@ export class GitService extends Disposable {
|
|||||||
const porcelainVersion = Git.validateVersion(2, 11) ? 2 : 1;
|
const porcelainVersion = Git.validateVersion(2, 11) ? 2 : 1;
|
||||||
|
|
||||||
const data = await Git.status(repoPath, porcelainVersion);
|
const data = await Git.status(repoPath, porcelainVersion);
|
||||||
return GitStatusParser.parse(data, repoPath, porcelainVersion);
|
const status = GitStatusParser.parse(data, repoPath, porcelainVersion);
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getVersionedFile(repoPath: string | undefined, fileName: string, sha: string) {
|
async getVersionedFile(repoPath: string | undefined, fileName: string, sha: string) {
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export namespace Iterables {
|
|||||||
return source.next().value;
|
return source.next().value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* skip<T>(source: Iterable<T> | IterableIterator<T>, count: number): Iterable<T> {
|
export function* skip<T>(source: Iterable<T> | IterableIterator<T>, count: number): Iterable<T> | IterableIterator<T> {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const item of source) {
|
for (const item of source) {
|
||||||
if (i >= count) yield item;
|
if (i >= count) yield item;
|
||||||
|
|||||||
@@ -43,6 +43,19 @@ export namespace Strings {
|
|||||||
return new Function(`return \`${template}\`;`).call(context);
|
return new Function(`return \`${template}\`;`).call(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function* lines(s: string): IterableIterator<string> {
|
||||||
|
let i = 0;
|
||||||
|
while (i < s.length) {
|
||||||
|
let j = s.indexOf('\n', i);
|
||||||
|
if (j === -1) {
|
||||||
|
j = s.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield s.substring(i, j);
|
||||||
|
i = j + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function padLeft(s: string, padTo: number, padding: string = '\u00a0') {
|
export function padLeft(s: string, padTo: number, padding: string = '\u00a0') {
|
||||||
const diff = padTo - s.length;
|
const diff = padTo - s.length;
|
||||||
return (diff <= 0) ? s : '\u00a0'.repeat(diff) + s;
|
return (diff <= 0) ? s : '\u00a0'.repeat(diff) + s;
|
||||||
|
|||||||
Reference in New Issue
Block a user