diff --git a/src/blameActiveLineController.ts b/src/blameActiveLineController.ts index 18297c4..04a5e57 100644 --- a/src/blameActiveLineController.ts +++ b/src/blameActiveLineController.ts @@ -138,7 +138,7 @@ export class BlameActiveLineController extends Disposable { const maxLines = this._config.advanced.caching.statusBar.maxLines; this._useCaching = this._config.advanced.caching.enabled && (maxLines <= 0 || editor.document.lineCount <= maxLines); if (this._useCaching) { - this._blame = this.git.getBlameForFile(this._uri.fsPath, this._uri.sha, this._uri.repoPath); + this._blame = this.git.getBlameForFile(this._uri); } else { this._blame = undefined; @@ -199,7 +199,7 @@ export class BlameActiveLineController extends Disposable { commit = sha && blame.commits.get(sha); } else { - const blameLine = await this.git.getBlameForLine(this._uri.fsPath, line, this._uri.sha, this._uri.repoPath); + const blameLine = await this.git.getBlameForLine(this._uri, line); commitLine = blameLine && blameLine.line; commit = blameLine && blameLine.commit; } @@ -298,7 +298,7 @@ export class BlameActiveLineController extends Disposable { // Get the full commit message -- since blame only returns the summary let logCommit: GitCommit; if (!commit.isUncommitted) { - const log = await this.git.getLogForFile(this._uri.fsPath, commit.sha, this._uri.repoPath, undefined, 1); + const log = await this.git.getLogForFile(this._uri.repoPath, this._uri.fsPath, commit.sha, undefined, 1); logCommit = log && log.commits.get(commit.sha); } diff --git a/src/blameAnnotationProvider.ts b/src/blameAnnotationProvider.ts index 85cdbea..f06e5d2 100644 --- a/src/blameAnnotationProvider.ts +++ b/src/blameAnnotationProvider.ts @@ -21,7 +21,7 @@ export class BlameAnnotationProvider extends Disposable { this.document = this.editor.document; - this._blame = this.git.getBlameForFile(this.uri.fsPath, this.uri.sha, this.uri.repoPath); + this._blame = this.git.getBlameForFile(this.uri); this._config = workspace.getConfiguration('gitlens').get('blame'); diff --git a/src/commands/copyMessageToClipboard.ts b/src/commands/copyMessageToClipboard.ts index d412302..52c5c58 100644 --- a/src/commands/copyMessageToClipboard.ts +++ b/src/commands/copyMessageToClipboard.ts @@ -39,7 +39,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { if (blameline < 0) return undefined; try { - const blame = await this.git.getBlameForLine(gitUri.fsPath, blameline, gitUri.sha, gitUri.repoPath); + const blame = await this.git.getBlameForLine(gitUri, blameline); if (!blame) return undefined; if (blame.commit.isUncommitted) return undefined; @@ -56,7 +56,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { } // Get the full commit message -- since blame only returns the summary - const log = await this.git.getLogForFile(gitUri.fsPath, sha, gitUri.repoPath, undefined, 1); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, sha, undefined, 1); if (!log) return undefined; const commit = log.commits.get(sha); diff --git a/src/commands/copyShaToClipboard.ts b/src/commands/copyShaToClipboard.ts index 417cce1..57eb6aa 100644 --- a/src/commands/copyShaToClipboard.ts +++ b/src/commands/copyShaToClipboard.ts @@ -38,7 +38,7 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand { if (blameline < 0) return undefined; try { - const blame = await this.git.getBlameForLine(gitUri.fsPath, blameline, gitUri.sha, gitUri.repoPath); + const blame = await this.git.getBlameForLine(gitUri, blameline); if (!blame) return undefined; sha = blame.commit.sha; diff --git a/src/commands/diffLineWithPrevious.ts b/src/commands/diffLineWithPrevious.ts index 8415e67..54e2236 100644 --- a/src/commands/diffLineWithPrevious.ts +++ b/src/commands/diffLineWithPrevious.ts @@ -30,7 +30,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand { if (blameline < 0) return undefined; try { - const blame = await this.git.getBlameForLine(gitUri.fsPath, blameline, gitUri.sha, gitUri.repoPath); + const blame = await this.git.getBlameForLine(gitUri, blameline); if (!blame) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`); commit = blame.commit; @@ -56,8 +56,8 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand { try { const [rhs, lhs] = await Promise.all([ - this.git.getVersionedFile(gitUri.fsPath, gitUri.repoPath, gitUri.sha), - this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.sha) + this.git.getVersionedFile(gitUri.repoPath, gitUri.fsPath, gitUri.sha), + this.git.getVersionedFile(commit.repoPath, commit.uri.fsPath, commit.sha) ]); await commands.executeCommand(BuiltInCommands.Diff, Uri.file(lhs), Uri.file(rhs), `${path.basename(commit.uri.fsPath)} (${commit.shortSha}) ↔ ${path.basename(gitUri.fsPath)} (${gitUri.shortSha})`); // TODO: Figure out how to focus the left pane diff --git a/src/commands/diffLineWithWorking.ts b/src/commands/diffLineWithWorking.ts index d7387e1..dda4b52 100644 --- a/src/commands/diffLineWithWorking.ts +++ b/src/commands/diffLineWithWorking.ts @@ -28,7 +28,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand { if (blameline < 0) return undefined; try { - const blame = await this.git.getBlameForLine(gitUri.fsPath, blameline, gitUri.sha, gitUri.repoPath); + const blame = await this.git.getBlameForLine(gitUri, blameline); if (!blame) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`); commit = blame.commit; diff --git a/src/commands/diffWithNext.ts b/src/commands/diffWithNext.ts index 54f50ef..3f84af5 100644 --- a/src/commands/diffWithNext.ts +++ b/src/commands/diffWithNext.ts @@ -35,20 +35,20 @@ export class DiffWithNextCommand extends ActiveEditorCommand { try { if (!gitUri.sha) { // If the file is uncommitted, treat it as a DiffWithWorking - if (await this.git.isFileUncommitted(gitUri.fsPath, gitUri.repoPath)) { + if (await this.git.isFileUncommitted(gitUri)) { return commands.executeCommand(Commands.DiffWithWorking, uri); } } const sha = (commit && commit.sha) || gitUri.sha; - const log = await this.git.getLogForFile(gitUri.fsPath, undefined, gitUri.repoPath, rangeOrLine as Range, sha ? undefined : 2); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, rangeOrLine as Range, sha ? undefined : 2); if (!log) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`); commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); } catch (ex) { - Logger.error('[GitLens.DiffWithNextCommand]', `getLogForFile(${gitUri.fsPath})`, ex); + Logger.error('[GitLens.DiffWithNextCommand]', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`, ex); return window.showErrorMessage(`Unable to open diff. See output channel for more details`); } } @@ -59,8 +59,8 @@ export class DiffWithNextCommand extends ActiveEditorCommand { try { const [rhs, lhs] = await Promise.all([ - this.git.getVersionedFile(commit.nextUri.fsPath, commit.repoPath, commit.nextSha), - this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.sha) + this.git.getVersionedFile(commit.repoPath, commit.nextUri.fsPath, commit.nextSha), + this.git.getVersionedFile(commit.repoPath, commit.uri.fsPath, commit.sha) ]); await commands.executeCommand(BuiltInCommands.Diff, Uri.file(lhs), Uri.file(rhs), `${path.basename(commit.uri.fsPath)} (${commit.shortSha}) ↔ ${path.basename(commit.nextUri.fsPath)} (${commit.nextShortSha})`); return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' }); diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index 4ca6bbe..ab3525f 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -36,20 +36,20 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { try { if (!gitUri.sha) { // If the file is uncommitted, treat it as a DiffWithWorking - if (await this.git.isFileUncommitted(gitUri.fsPath, gitUri.repoPath)) { + if (await this.git.isFileUncommitted(gitUri)) { return commands.executeCommand(Commands.DiffWithWorking, uri); } } const sha = (commit && commit.sha) || gitUri.sha; - const log = await this.git.getLogForFile(gitUri.fsPath, undefined, gitUri.repoPath, rangeOrLine as Range, sha ? undefined : 2); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, rangeOrLine as Range, sha ? undefined : 2); if (!log) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`); commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); } catch (ex) { - Logger.error('[GitLens.DiffWithPreviousCommand]', `getLogForFile(${gitUri.fsPath})`, ex); + Logger.error('[GitLens.DiffWithPreviousCommand]', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`, ex); return window.showErrorMessage(`Unable to open diff. See output channel for more details`); } } @@ -60,8 +60,8 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { try { const [rhs, lhs] = await Promise.all([ - this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.sha), - this.git.getVersionedFile(commit.previousUri.fsPath, commit.repoPath, commit.previousSha) + this.git.getVersionedFile(commit.repoPath, commit.uri.fsPath, commit.sha), + this.git.getVersionedFile(commit.repoPath, commit.previousUri.fsPath, commit.previousSha) ]); await commands.executeCommand(BuiltInCommands.Diff, Uri.file(lhs), Uri.file(rhs), `${path.basename(commit.previousUri.fsPath)} (${commit.previousShortSha}) ↔ ${path.basename(commit.uri.fsPath)} (${commit.shortSha})`); // TODO: Figure out how to focus the left pane diff --git a/src/commands/diffWithWorking.ts b/src/commands/diffWithWorking.ts index 7b6c6c5..66e5579 100644 --- a/src/commands/diffWithWorking.ts +++ b/src/commands/diffWithWorking.ts @@ -27,13 +27,13 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand { const gitUri = await GitUri.fromUri(uri, this.git); try { - const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, gitUri.sha ? undefined : 1); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, gitUri.sha, undefined, gitUri.sha ? undefined : 1); if (!log) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`); commit = (gitUri.sha && log.commits.get(gitUri.sha)) || Iterables.first(log.commits.values()); } catch (ex) { - Logger.error('[GitLens.DiffWithWorkingCommand]', `getLogForFile(${gitUri.fsPath})`, ex); + Logger.error('[GitLens.DiffWithWorkingCommand]', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`, ex); return window.showErrorMessage(`Unable to open diff. See output channel for more details`); } } @@ -41,7 +41,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand { const gitUri = await GitUri.fromUri(uri, this.git); try { - const compare = await this.git.getVersionedFile(commit.uri.fsPath, commit.repoPath, commit.sha); + const compare = await this.git.getVersionedFile(commit.repoPath, commit.uri.fsPath, commit.sha); await commands.executeCommand(BuiltInCommands.Diff, Uri.file(compare), gitUri.fileUri(), `${path.basename(commit.uri.fsPath)} (${commit.shortSha}) ↔ ${path.basename(gitUri.fsPath)}`); return await commands.executeCommand(BuiltInCommands.RevealLine, { lineNumber: line, at: 'center' }); } diff --git a/src/commands/showBlameHistory.ts b/src/commands/showBlameHistory.ts index 93a9ba3..536e72c 100644 --- a/src/commands/showBlameHistory.ts +++ b/src/commands/showBlameHistory.ts @@ -26,7 +26,7 @@ export class ShowBlameHistoryCommand extends EditorCommand { const gitUri = await GitUri.fromUri(uri, this.git); try { - const locations = await this.git.getBlameLocations(gitUri.fsPath, range, gitUri.sha, gitUri.repoPath, sha, line); + const locations = await this.git.getBlameLocations(gitUri, range, sha, line); if (!locations) return window.showWarningMessage(`Unable to show blame history. File is probably not under source control`); return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations); diff --git a/src/commands/showFileHistory.ts b/src/commands/showFileHistory.ts index 38fb35a..ae1c650 100644 --- a/src/commands/showFileHistory.ts +++ b/src/commands/showFileHistory.ts @@ -25,7 +25,7 @@ export class ShowFileHistoryCommand extends EditorCommand { const gitUri = await GitUri.fromUri(uri, this.git); try { - const locations = await this.git.getLogLocations(gitUri.fsPath, gitUri.sha, gitUri.repoPath, sha, line); + const locations = await this.git.getLogLocations(gitUri, sha, line); if (!locations) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`); return commands.executeCommand(BuiltInCommands.ShowReferences, uri, position, locations); diff --git a/src/commands/showQuickCommitDetails.ts b/src/commands/showQuickCommitDetails.ts index 47e0407..19560e3 100644 --- a/src/commands/showQuickCommitDetails.ts +++ b/src/commands/showQuickCommitDetails.ts @@ -28,7 +28,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCommand { if (blameline < 0) return undefined; try { - const blame = await this.git.getBlameForLine(gitUri.fsPath, blameline, gitUri.sha, gitUri.repoPath); + const blame = await this.git.getBlameForLine(gitUri, blameline); if (!blame) return window.showWarningMessage(`Unable to show commit details. File is probably not under source control`); sha = blame.commit.isUncommitted ? blame.commit.previousSha : blame.commit.sha; diff --git a/src/commands/showQuickCommitFileDetails.ts b/src/commands/showQuickCommitFileDetails.ts index 0678857..427b64c 100644 --- a/src/commands/showQuickCommitFileDetails.ts +++ b/src/commands/showQuickCommitFileDetails.ts @@ -27,7 +27,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand { if (blameline < 0) return undefined; try { - const blame = await this.git.getBlameForLine(gitUri.fsPath, blameline, gitUri.sha, gitUri.repoPath); + const blame = await this.git.getBlameForLine(gitUri, blameline); if (!blame) return window.showWarningMessage(`Unable to show commit file details. File is probably not under source control`); sha = blame.commit.isUncommitted ? blame.commit.previousSha : blame.commit.sha; @@ -51,7 +51,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCommand { } if (!fileLog) { - const log = await this.git.getLogForFile(uri.fsPath, sha, undefined, undefined, 2); + const log = await this.git.getLogForFile(undefined, uri.fsPath, sha, undefined, 2); if (!log) return window.showWarningMessage(`Unable to show commit file details`); commit = log.commits.get(sha); diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index d5db218..f62ad85 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -28,7 +28,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand { const progressCancellation = FileHistoryQuickPick.showProgress(gitUri); try { if (!log) { - log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, range, maxCount); + log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, gitUri.sha, range, maxCount); if (!log) return window.showWarningMessage(`Unable to show file history. File is probably not under source control`); } @@ -50,7 +50,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCommand { log); } catch (ex) { - Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'getLogLocations', ex); + Logger.error('[GitLens.ShowQuickFileHistoryCommand]', 'data.repoPath, ', ex); return window.showErrorMessage(`Unable to show file history. See output channel for more details`); } finally { diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index 6e5d000..2cf2276 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -77,7 +77,7 @@ export class GitUri extends Uri { // If this is a git uri, assume it is showing the most recent commit if (uri.scheme === 'git' && uri.query === '~') { - const log = await git.getLogForFile(uri.fsPath, undefined, undefined, undefined, 1); + const log = await git.getLogForFile(undefined, uri.fsPath, undefined, undefined, 1); const commit = log && Iterables.first(log.commits.values()); if (commit) return new GitUri(uri, commit); } diff --git a/src/gitCodeLensProvider.ts b/src/gitCodeLensProvider.ts index 03502f6..8d53d46 100644 --- a/src/gitCodeLensProvider.ts +++ b/src/gitCodeLensProvider.ts @@ -71,7 +71,7 @@ export default class GitCodeLensProvider implements CodeLensProvider { const gitUri = await GitUri.fromUri(document.uri, this.git); - const blamePromise = this.git.getBlameForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath); + const blamePromise = this.git.getBlameForFile(gitUri); let blame: IGitBlame; if (languageLocations.location === CodeLensLocation.Document) { blame = await blamePromise; @@ -97,12 +97,12 @@ export default class GitCodeLensProvider implements CodeLensProvider { const blameRange = document.validateRange(new Range(0, 1000000, 1000000, 1000000)); let blameForRangeFn: () => IGitBlameLines; if (this._documentIsDirty || this._config.codeLens.recentChange.enabled) { - blameForRangeFn = Functions.once(() => this.git.getBlameForRangeSync(blame, gitUri.fsPath, blameRange, gitUri.sha, gitUri.repoPath)); + blameForRangeFn = Functions.once(() => this.git.getBlameForRangeSync(blame, gitUri, blameRange)); lenses.push(new GitRecentChangeCodeLens(blameForRangeFn, gitUri, SymbolKind.File, blameRange, true, new Range(0, 0, 0, blameRange.start.character))); } if (this._config.codeLens.authors.enabled) { if (!blameForRangeFn) { - blameForRangeFn = Functions.once(() => this.git.getBlameForRangeSync(blame, gitUri.fsPath, blameRange, gitUri.sha, gitUri.repoPath)); + blameForRangeFn = Functions.once(() => this.git.getBlameForRangeSync(blame, gitUri, blameRange)); } if (!this._documentIsDirty) { lenses.push(new GitAuthorsCodeLens(blameForRangeFn, gitUri, SymbolKind.File, blameRange, true, new Range(0, 1, 0, blameRange.start.character))); @@ -193,7 +193,7 @@ export default class GitCodeLensProvider implements CodeLensProvider { let blameForRangeFn: () => IGitBlameLines; if (this._documentIsDirty || this._config.codeLens.recentChange.enabled) { - blameForRangeFn = Functions.once(() => this.git.getBlameForRangeSync(blame, gitUri.fsPath, blameRange, gitUri.sha, gitUri.repoPath)); + blameForRangeFn = Functions.once(() => this.git.getBlameForRangeSync(blame, gitUri, blameRange)); lenses.push(new GitRecentChangeCodeLens(blameForRangeFn, gitUri, symbol.kind, blameRange, false, line.range.with(new Position(line.range.start.line, startChar)))); startChar++; } @@ -221,7 +221,7 @@ export default class GitCodeLensProvider implements CodeLensProvider { if (multiline) { if (!blameForRangeFn) { - blameForRangeFn = Functions.once(() => this.git.getBlameForRangeSync(blame, gitUri.fsPath, blameRange, gitUri.sha, gitUri.repoPath)); + blameForRangeFn = Functions.once(() => this.git.getBlameForRangeSync(blame, gitUri, blameRange)); } if (!this._documentIsDirty) { lenses.push(new GitAuthorsCodeLens(blameForRangeFn, gitUri, symbol.kind, blameRange, false, line.range.with(new Position(line.range.start.line, startChar)))); diff --git a/src/gitContentProvider.ts b/src/gitContentProvider.ts index 8a7eb24..27e59b1 100644 --- a/src/gitContentProvider.ts +++ b/src/gitContentProvider.ts @@ -15,7 +15,7 @@ export class GitContentProvider implements TextDocumentContentProvider { const data = GitService.fromGitContentUri(uri); const fileName = data.originalFileName || data.fileName; try { - let text = await this.git.getVersionedFileText(fileName, data.repoPath, data.sha) as string; + let text = await this.git.getVersionedFileText(data.repoPath, fileName, data.sha) as string; if (data.decoration) { text = `${data.decoration}\n${text}`; } diff --git a/src/gitRevisionCodeLensProvider.ts b/src/gitRevisionCodeLensProvider.ts index b92cdc8..7decb99 100644 --- a/src/gitRevisionCodeLensProvider.ts +++ b/src/gitRevisionCodeLensProvider.ts @@ -31,7 +31,7 @@ export class GitRevisionCodeLensProvider implements CodeLensProvider { const lenses: CodeLens[] = []; - const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, undefined, 2); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, gitUri.sha, undefined, 2); if (!log) return lenses; const commit = (gitUri.sha && log.commits.get(gitUri.sha)) || Iterables.first(log.commits.values()); diff --git a/src/gitService.ts b/src/gitService.ts index 9a78198..453c7e8 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -274,7 +274,7 @@ export class GitService extends Disposable { // let commit: GitCommit; // while (true) { // // Go backward from the current commit to head to find the latest filename - // log = await this.getLogForFile(fileName, sha, undefined, undefined, undefined, true); + // log = await this.getLogForFile(undefined, fileName, sha, undefined, undefined, true); // if (!log) break; // commit = Iterables.first(log.commits.values()); @@ -307,15 +307,15 @@ export class GitService extends Disposable { } async getRepoPathFromFile(fileName: string): Promise { - const log = await this.getLogForFile(fileName, undefined, undefined, undefined, 1); + const log = await this.getLogForFile(undefined, fileName, undefined, undefined, 1); return log && log.repoPath; } - getBlameForFile(fileName: string, sha?: string, repoPath?: string): Promise { - Logger.log(`getBlameForFile('${fileName}', ${sha}, '${repoPath}')`); - fileName = Git.normalizePath(fileName); + getBlameForFile(uri: GitUri): Promise { + Logger.log(`getBlameForFile('${uri.repoPath}', '${uri.fsPath}', ${uri.sha})`); - const useCaching = this.UseGitCaching && !sha; + const fileName = Git.normalizePath(uri.fsPath, uri.repoPath); + const useCaching = this.UseGitCaching && !uri.sha; let cacheKey: string | undefined; let entry: GitCacheEntry | undefined; @@ -338,7 +338,7 @@ export class GitService extends Disposable { return GitService.EmptyPromise as Promise; } - return Git.blame(repoPath, fileName, GitService.BlameFormat, sha) + return Git.blame(uri.repoPath, fileName, GitService.BlameFormat, uri.sha) .then(data => new GitBlameParserEnricher(GitService.BlameFormat).enrich(data, fileName)) .catch(ex => { // Trap and cache expected blame errors @@ -374,11 +374,11 @@ export class GitService extends Disposable { return promise; } - async getBlameForLine(fileName: string, line: number, sha?: string, repoPath?: string): Promise { - Logger.log(`getBlameForLine('${fileName}', ${line}, ${sha}, '${repoPath}')`); + async getBlameForLine(uri: GitUri, line: number): Promise { + Logger.log(`getBlameForLine('${uri.repoPath}', '${uri.fsPath}', ${line}, ${uri.sha})`); - if (this.UseGitCaching && !sha) { - const blame = await this.getBlameForFile(fileName); + if (this.UseGitCaching && !uri.sha) { + const blame = await this.getBlameForFile(uri); const blameLine = blame && blame.lines[line]; if (!blameLine) return undefined; @@ -390,16 +390,16 @@ export class GitService extends Disposable { } as IGitBlameLine; } - fileName = Git.normalizePath(fileName); + const fileName = Git.normalizePath(uri.fsPath, uri.repoPath); try { - const data = await Git.blame(repoPath, fileName, GitService.BlameFormat, sha, line + 1, line + 1); + const data = await Git.blame(uri.repoPath, fileName, GitService.BlameFormat, uri.sha, line + 1, line + 1); const blame = new GitBlameParserEnricher(GitService.BlameFormat).enrich(data, fileName); if (!blame) return undefined; const commit = Iterables.first(blame.commits.values()); - if (repoPath) { - commit.repoPath = repoPath; + if (uri.repoPath) { + commit.repoPath = uri.repoPath; } return { author: Iterables.first(blame.authors.values()), @@ -412,16 +412,17 @@ export class GitService extends Disposable { } } - async getBlameForRange(fileName: string, range: Range, sha?: string, repoPath?: string): Promise { - Logger.log(`getBlameForRange('${fileName}', [${range.start.line}, ${range.end.line}], ${sha}, '${repoPath}')`); - const blame = await this.getBlameForFile(fileName, sha, repoPath); + async getBlameForRange(uri: GitUri, range: Range): Promise { + Logger.log(`getBlameForRange('${uri.repoPath}', '${uri.fsPath}', [${range.start.line}, ${range.end.line}], ${uri.sha})`); + + const blame = await this.getBlameForFile(uri); if (!blame) return undefined; - return this.getBlameForRangeSync(blame, fileName, range, sha, repoPath); + return this.getBlameForRangeSync(blame, uri, range); } - getBlameForRangeSync(blame: IGitBlame, fileName: string, range: Range, sha?: string, repoPath?: string): IGitBlameLines | undefined { - Logger.log(`getBlameForRangeSync('${fileName}', [${range.start.line}, ${range.end.line}], ${sha}, '${repoPath}')`); + getBlameForRangeSync(blame: IGitBlame, uri: GitUri, range: Range): IGitBlameLines | undefined { + Logger.log(`getBlameForRangeSync('${uri.repoPath}', '${uri.fsPath}', [${range.start.line}, ${range.end.line}], ${uri.sha})`); if (!blame.lines.length) return Object.assign({ allLines: blame.lines }, blame); @@ -467,10 +468,10 @@ export class GitService extends Disposable { } as IGitBlameLines; } - async getBlameLocations(fileName: string, range: Range, sha?: string, repoPath?: string, selectedSha?: string, line?: number): Promise { - Logger.log(`getBlameLocations('${fileName}', [${range.start.line}, ${range.end.line}], ${sha}, '${repoPath}')`); + async getBlameLocations(uri: GitUri, range: Range, selectedSha?: string, line?: number): Promise { + Logger.log(`getBlameLocations('${uri.repoPath}', '${uri.fsPath}', [${range.start.line}, ${range.end.line}], ${uri.sha})`); - const blame = await this.getBlameForRange(fileName, range, sha, repoPath); + const blame = await this.getBlameForRange(uri, range); if (!blame) return undefined; const commitCount = blame.commits.size; @@ -506,10 +507,10 @@ export class GitService extends Disposable { } } - getLogForFile(fileName: string, sha?: string, repoPath?: string, range?: Range, maxCount?: number, reverse: boolean = false): Promise { - Logger.log(`getLogForFile('${fileName}', ${sha}, '${repoPath}', ${range && `[${range.start.line}, ${range.end.line}]`}, ${maxCount}, ${reverse})`); - fileName = Git.normalizePath(fileName); + getLogForFile(repoPath: string, fileName: string, sha?: string, range?: Range, maxCount?: number, reverse: boolean = false): Promise { + Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${sha}, ${range && `[${range.start.line}, ${range.end.line}]`}, ${maxCount}, ${reverse})`); + fileName = Git.normalizePath(fileName); const useCaching = this.UseGitCaching && !sha && !range && !maxCount; let cacheKey: string; @@ -565,10 +566,10 @@ export class GitService extends Disposable { return promise; } - async getLogLocations(fileName: string, sha?: string, repoPath?: string, selectedSha?: string, line?: number): Promise { - Logger.log(`getLogLocations('${fileName}', ${sha}, '${repoPath}', ${selectedSha}, ${line})`); + async getLogLocations(uri: GitUri, selectedSha?: string, line?: number): Promise { + Logger.log(`getLogLocations('${uri.repoPath}', '${uri.fsPath}', ${uri.sha}, ${selectedSha}, ${line})`); - const log = await this.getLogForFile(fileName, sha, repoPath); + const log = await this.getLogForFile(uri.repoPath, uri.fsPath, uri.sha); if (!log) return undefined; const commitCount = log.commits.size; @@ -588,28 +589,31 @@ export class GitService extends Disposable { return locations; } - async getStatusForFile(fileName: string, repoPath: string): Promise { - Logger.log(`getStatusForFile('${fileName}', '${repoPath}')`); + async getStatusForFile(repoPath: string, fileName: string): Promise { + Logger.log(`getStatusForFile('${repoPath}', '${fileName}')`); + const status = await Git.status_file(repoPath, fileName); return status && status.trim().length && new GitFileStatusItem(repoPath, status); } async getStatusesForRepo(repoPath: string): Promise { Logger.log(`getStatusForRepo('${repoPath}')`); + const statuses = (await Git.status(repoPath)).split('\n').filter(_ => !!_); return statuses.map(_ => new GitFileStatusItem(repoPath, _)); } - async isFileUncommitted(fileName: string, repoPath: string): Promise { - Logger.log(`isFileUncommitted('${fileName}', '${repoPath}')`); - const status = await this.getStatusForFile(fileName, repoPath); + async isFileUncommitted(uri: GitUri): Promise { + Logger.log(`isFileUncommitted('${uri.repoPath}', '${uri.fsPath}')`); + + const status = await this.getStatusForFile(uri.repoPath, uri.fsPath); return !!status; } - async getVersionedFile(fileName: string, repoPath: string, sha: string) { - Logger.log(`getVersionedFile('${fileName}', '${repoPath}', ${sha})`); + async getVersionedFile(repoPath: string, fileName: string, sha: string) { + Logger.log(`getVersionedFile('${repoPath}', '${fileName}', ${sha})`); - const file = await Git.getVersionedFile(fileName, repoPath, sha); + const file = await Git.getVersionedFile(repoPath, fileName, sha); if (this.UseUriCaching) { const cacheKey = this.getCacheEntryKey(file); const entry = new UriCacheEntry(new GitUri(Uri.file(fileName), { sha, repoPath, fileName })); @@ -618,8 +622,9 @@ export class GitService extends Disposable { return file; } - getVersionedFileText(fileName: string, repoPath: string, sha: string) { - Logger.log(`getVersionedFileText('${fileName}', '${repoPath}', ${sha})`); + getVersionedFileText(repoPath: string, fileName: string, sha: string) { + Logger.log(`getVersionedFileText('${repoPath}', '${fileName}', ${sha})`); + return Git.show(repoPath, fileName, sha); } @@ -632,6 +637,7 @@ export class GitService extends Disposable { openDirectoryDiff(repoPath: string, sha1: string, sha2?: string) { Logger.log(`openDirectoryDiff('${repoPath}', ${sha1}, ${sha2})`); + return Git.difftool_dirDiff(repoPath, sha1, sha2); } diff --git a/src/quickPicks/commitFileDetails.ts b/src/quickPicks/commitFileDetails.ts index 0904776..76a0789 100644 --- a/src/quickPicks/commitFileDetails.ts +++ b/src/quickPicks/commitFileDetails.ts @@ -39,7 +39,7 @@ export class CommitFileDetailsQuickPick { const isUncommitted = commit.isUncommitted; if (isUncommitted) { // Since we can't trust the previous sha on an uncommitted commit, find the last commit for this file - const log = await git.getLogForFile(commit.uri.fsPath, undefined, undefined, undefined, 2); + const log = await git.getLogForFile(undefined, commit.uri.fsPath, undefined, undefined, 2); if (!log) return undefined; commit = Iterables.first(log.commits.values()); @@ -107,7 +107,7 @@ export class CommitFileDetailsQuickPick { // If we can't find the commit or the previous commit isn't available (since it isn't trustworthy) if (!c || !c.previousSha) { - log = await git.getLogForFile(uri.fsPath, commit.sha, commit.repoPath, undefined, git.config.advanced.maxQuickHistory); + log = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, undefined, git.config.advanced.maxQuickHistory); c = log && log.commits.get(commit.sha); if (c) { @@ -130,7 +130,7 @@ export class CommitFileDetailsQuickPick { c = undefined; // Try to find the next commit - const nextLog = await git.getLogForFile(uri.fsPath, commit.sha, commit.repoPath, undefined, 1, true); + const nextLog = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, undefined, 1, true); const next = nextLog && Iterables.first(nextLog.commits.values()); if (next && next.sha !== commit.sha) { c = commit;