Adds support for git commands on scheme=git

Rewrites blame annotation controller and provider - fixes whitespace issues, reduces overhead, and provides better performance
Rewrites status bar blame support - reduces overhead and provides better performance
Adds showFileHistory command to status bar
Renames showHistory to showFileHistory
Fixes log to use iso 8601 for dates
This commit is contained in:
Eric Amodio
2016-11-12 01:25:42 -05:00
parent 7ace9cb152
commit 638a6dc838
28 changed files with 592 additions and 259 deletions

View File

@@ -2,7 +2,7 @@
import { commands, TextEditor, TextEditorEdit, Uri, window } from 'vscode';
import { EditorCommand } from './commands';
import { Commands } from '../constants';
import GitProvider, { GitCommit } from '../gitProvider';
import GitProvider, { GitCommit, GitUri } from '../gitProvider';
import { Logger } from '../logger';
export default class DiffLineWithWorkingCommand extends EditorCommand {
@@ -10,33 +10,38 @@ export default class DiffLineWithWorkingCommand extends EditorCommand {
super(Commands.DiffLineWithWorking);
}
async execute(editor: TextEditor, edit: TextEditorEdit): Promise<any>;
async execute(editor: TextEditor, edit: TextEditorEdit, uri?: Uri, commit?: GitCommit, line?: number): Promise<any> {
async execute(editor: TextEditor): Promise<any>;
async execute(editor: TextEditor, edit: TextEditorEdit, uri: Uri): Promise<any>;
async execute(editor: TextEditor, edit?: TextEditorEdit, uri?: Uri, commit?: GitCommit, line?: number): Promise<any> {
if (!(uri instanceof Uri)) {
if (!editor.document) return undefined;
uri = editor.document.uri;
}
line = line || editor.selection.active.line;
if (!commit || GitProvider.isUncommitted(commit.sha)) {
if (!(uri instanceof Uri)) {
if (!editor.document) return undefined;
uri = editor.document.uri;
}
const gitUri = GitUri.fromUri(uri);
const blameline = line - gitUri.offset;
if (blameline < 0) return undefined;
try {
const blame = await this.git.getBlameForLine(uri.fsPath, line);
const blame = await this.git.getBlameForLine(gitUri.fsPath, blameline, gitUri.sha, gitUri.repoPath);
if (!blame) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`);
commit = blame.commit;
// If the line is uncommitted, find the previous commit
if (commit.isUncommitted) {
commit = new GitCommit(commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message);
line = blame.line.line + 1;
line = blame.line.line + 1 + gitUri.offset;
}
}
catch (ex) {
Logger.error('[GitLens.DiffLineWithWorkingCommand]', `getBlameForLine(${line})`, ex);
Logger.error('[GitLens.DiffLineWithWorkingCommand]', `getBlameForLine(${blameline})`, ex);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
}
}
return commands.executeCommand(Commands.DiffWithWorking, commit.uri, commit, line);
return commands.executeCommand(Commands.DiffWithWorking, uri, commit, line);
}
}