mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-02 17:25:41 -05:00
Refactors GitService to mostly use GitUris
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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' });
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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' });
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user