Fixes #1 Support blame on files outside repo

Replaces blame regex parsing with more robust parser (also use s--incremental instead of --porcelain)
Stops throwing on git blame errors (too many are common)
Fixes issues with Diff with Previous command
Fixes issues with blame explorer code lens -- with previous commits
Fixes issues with compact blame annotations -- skips blank lines
This commit is contained in:
Eric Amodio
2016-09-19 04:11:46 -04:00
parent c69a160ea5
commit ff01054f90
8 changed files with 368 additions and 234 deletions

View File

@@ -6,13 +6,13 @@ import * as moment from 'moment';
import * as path from 'path';
export class GitDiffWithWorkingTreeCodeLens extends CodeLens {
constructor(private git: GitProvider, public fileName: string, public sha: string, range: Range) {
constructor(private git: GitProvider, public fileName: string, public commit: IGitCommit, range: Range) {
super(range);
}
}
export class GitDiffWithPreviousCodeLens extends CodeLens {
constructor(private git: GitProvider, public fileName: string, public sha: string, public compareWithSha: string, range: Range) {
constructor(private git: GitProvider, public fileName: string, public commit: IGitCommit, range: Range) {
super(range);
}
}
@@ -31,22 +31,17 @@ export default class GitBlameCodeLensProvider implements CodeLensProvider {
const lenses: CodeLens[] = [];
if (!blame) return lenses;
const commits = Array.from(blame.commits.values());
let index = commits.findIndex(c => c.sha === sha) + 1;
let previousCommit: IGitCommit;
if (index < commits.length) {
previousCommit = commits[index];
}
const commit = blame.commits.get(sha);
const absoluteFileName = path.join(commit.repoPath, fileName);
// Add codelens to each "group" of blame lines
const lines = blame.lines.filter(l => l.sha === sha && l.originalLine >= data.range.start.line && l.originalLine <= data.range.end.line);
let lastLine = lines[0].originalLine;
lines.forEach(l => {
if (l.originalLine !== lastLine + 1) {
lenses.push(new GitDiffWithWorkingTreeCodeLens(this.git, fileName, sha, new Range(l.originalLine, 0, l.originalLine, 1)));
if (previousCommit) {
lenses.push(new GitDiffWithPreviousCodeLens(this.git, fileName, sha, previousCommit.sha, new Range(l.originalLine, 1, l.originalLine, 2)));
lenses.push(new GitDiffWithWorkingTreeCodeLens(this.git, absoluteFileName, commit, new Range(l.originalLine, 0, l.originalLine, 1)));
if (commit.previousSha) {
lenses.push(new GitDiffWithPreviousCodeLens(this.git, absoluteFileName, commit, new Range(l.originalLine, 1, l.originalLine, 2)));
}
}
lastLine = l.originalLine;
@@ -54,9 +49,9 @@ export default class GitBlameCodeLensProvider implements CodeLensProvider {
// Check if we have a lens for the whole document -- if not add one
if (!lenses.find(l => l.range.start.line === 0 && l.range.end.line === 0)) {
lenses.push(new GitDiffWithWorkingTreeCodeLens(this.git, fileName, sha, new Range(0, 0, 0, 1)));
if (previousCommit) {
lenses.push(new GitDiffWithPreviousCodeLens(this.git, fileName, sha, previousCommit.sha, new Range(0, 1, 0, 2)));
lenses.push(new GitDiffWithWorkingTreeCodeLens(this.git, absoluteFileName, commit, new Range(0, 0, 0, 1)));
if (commit.previousSha) {
lenses.push(new GitDiffWithPreviousCodeLens(this.git, absoluteFileName, commit, new Range(0, 1, 0, 2)));
}
}
@@ -73,16 +68,16 @@ export default class GitBlameCodeLensProvider implements CodeLensProvider {
lens.command = {
title: `Compare with Working Tree`,
command: Commands.DiffWithWorking,
arguments: [Uri.file(path.join(this.git.repoPath, lens.fileName)), lens.sha]
arguments: [Uri.file(lens.fileName), lens.commit.sha, lens.commit.uri, lens.range.start.line]
};
return Promise.resolve(lens);
}
_resolveGitDiffWithPreviousCodeLens(lens: GitDiffWithPreviousCodeLens, token: CancellationToken): Thenable<CodeLens> {
lens.command = {
title: `Compare with Previous (${lens.compareWithSha})`,
title: `Compare with Previous (${lens.commit.previousSha})`,
command: Commands.DiffWithPrevious,
arguments: [Uri.file(path.join(this.git.repoPath, lens.fileName)), lens.sha, lens.compareWithSha]
arguments: [Uri.file(lens.fileName), lens.commit.sha, lens.commit.uri, lens.commit.previousSha, lens.commit.previousUri, lens.range.start.line]
};
return Promise.resolve(lens);
}