From 4a88edd5ca579a80a51a6f143a6f2184014d6f79 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 18 Feb 2017 17:17:08 -0500 Subject: [PATCH] Optimizes performance of git-log --- src/commands/diffWithPrevious.ts | 5 +++-- src/commands/diffWithWorking.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index 8eba912..bbaed1b 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -41,10 +41,11 @@ export default class DiffWithPreviousCommand extends EditorCommand { } } - const log = await this.git.getLogForFile(gitUri.fsPath, undefined, gitUri.repoPath, rangeOrLine as Range); + const sha = (commit && commit.sha) || gitUri.sha; + + const log = await this.git.getLogForFile(gitUri.fsPath, undefined, gitUri.repoPath, rangeOrLine as Range, sha ? undefined : 2); if (!log) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`); - const sha = (commit && commit.sha) || gitUri.sha; commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); } catch (ex) { diff --git a/src/commands/diffWithWorking.ts b/src/commands/diffWithWorking.ts index ddfc25f..e593a24 100644 --- a/src/commands/diffWithWorking.ts +++ b/src/commands/diffWithWorking.ts @@ -27,7 +27,7 @@ export default class DiffWithWorkingCommand extends EditorCommand { const gitUri = GitUri.fromUri(uri, this.git); try { - const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath); + const log = await this.git.getLogForFile(gitUri.fsPath, gitUri.sha, gitUri.repoPath, 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());