Parcourir la source

Refactors GitService to mostly use GitUris

main
Eric Amodio il y a 7 ans
Parent
révision
164cb2bfe0
20 fichiers modifiés avec 88 ajouts et 82 suppressions
  1. +3
    -3
      src/blameActiveLineController.ts
  2. +1
    -1
      src/blameAnnotationProvider.ts
  3. +2
    -2
      src/commands/copyMessageToClipboard.ts
  4. +1
    -1
      src/commands/copyShaToClipboard.ts
  5. +3
    -3
      src/commands/diffLineWithPrevious.ts
  6. +1
    -1
      src/commands/diffLineWithWorking.ts
  7. +5
    -5
      src/commands/diffWithNext.ts
  8. +5
    -5
      src/commands/diffWithPrevious.ts
  9. +3
    -3
      src/commands/diffWithWorking.ts
  10. +1
    -1
      src/commands/showBlameHistory.ts
  11. +1
    -1
      src/commands/showFileHistory.ts
  12. +1
    -1
      src/commands/showQuickCommitDetails.ts
  13. +2
    -2
      src/commands/showQuickCommitFileDetails.ts
  14. +2
    -2
      src/commands/showQuickFileHistory.ts
  15. +1
    -1
      src/git/gitUri.ts
  16. +5
    -5
      src/gitCodeLensProvider.ts
  17. +1
    -1
      src/gitContentProvider.ts
  18. +1
    -1
      src/gitRevisionCodeLensProvider.ts
  19. +46
    -40
      src/gitService.ts
  20. +3
    -3
      src/quickPicks/commitFileDetails.ts

+ 3
- 3
src/blameActiveLineController.ts Voir le fichier

@ -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);
}

+ 1
- 1
src/blameAnnotationProvider.ts Voir le fichier

@ -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<IBlameConfig>('blame');

+ 2
- 2
src/commands/copyMessageToClipboard.ts Voir le fichier

@ -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);

+ 1
- 1
src/commands/copyShaToClipboard.ts Voir le fichier

@ -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;

+ 3
- 3
src/commands/diffLineWithPrevious.ts Voir le fichier

@ -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

+ 1
- 1
src/commands/diffLineWithWorking.ts Voir le fichier

@ -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;

+ 5
- 5
src/commands/diffWithNext.ts Voir le fichier

@ -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' });

+ 5
- 5
src/commands/diffWithPrevious.ts Voir le fichier

@ -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

+ 3
- 3
src/commands/diffWithWorking.ts Voir le fichier

@ -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' });
}

+ 1
- 1
src/commands/showBlameHistory.ts Voir le fichier

@ -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);

+ 1
- 1
src/commands/showFileHistory.ts Voir le fichier

@ -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);

+ 1
- 1
src/commands/showQuickCommitDetails.ts Voir le fichier

@ -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;

+ 2
- 2
src/commands/showQuickCommitFileDetails.ts Voir le fichier

@ -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);

+ 2
- 2
src/commands/showQuickFileHistory.ts Voir le fichier

@ -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 {

+ 1
- 1
src/git/gitUri.ts Voir le fichier

@ -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);
}

+ 5
- 5
src/gitCodeLensProvider.ts Voir le fichier

@ -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))));

+ 1
- 1
src/gitContentProvider.ts Voir le fichier

@ -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}`;
}

+ 1
- 1
src/gitRevisionCodeLensProvider.ts Voir le fichier

@ -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());

+ 46
- 40
src/gitService.ts Voir le fichier

@ -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<string | undefined> {
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<IGitBlame | undefined> {
Logger.log(`getBlameForFile('${fileName}', ${sha}, '${repoPath}')`);
fileName = Git.normalizePath(fileName);
getBlameForFile(uri: GitUri): Promise<IGitBlame | undefined> {
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<IGitBlame>;
}
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<IGitBlameLine | undefined> {
Logger.log(`getBlameForLine('${fileName}', ${line}, ${sha}, '${repoPath}')`);
async getBlameForLine(uri: GitUri, line: number): Promise<IGitBlameLine | undefined> {
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<IGitBlameLines | undefined> {
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<IGitBlameLines | undefined> {
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<Location[] | undefined> {
Logger.log(`getBlameLocations('${fileName}', [${range.start.line}, ${range.end.line}], ${sha}, '${repoPath}')`);
async getBlameLocations(uri: GitUri, range: Range, selectedSha?: string, line?: number): Promise<Location[] | undefined> {
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<IGitLog | undefined> {
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<IGitLog | undefined> {
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<Location[] | undefined> {
Logger.log(`getLogLocations('${fileName}', ${sha}, '${repoPath}', ${selectedSha}, ${line})`);
async getLogLocations(uri: GitUri, selectedSha?: string, line?: number): Promise<Location[] | undefined> {
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<GitFileStatusItem> {
Logger.log(`getStatusForFile('${fileName}', '${repoPath}')`);
async getStatusForFile(repoPath: string, fileName: string): Promise<GitFileStatusItem> {
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<GitFileStatusItem[]> {
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<boolean> {
Logger.log(`isFileUncommitted('${fileName}', '${repoPath}')`);
const status = await this.getStatusForFile(fileName, repoPath);
async isFileUncommitted(uri: GitUri): Promise<boolean> {
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);
}

+ 3
- 3
src/quickPicks/commitFileDetails.ts Voir le fichier

@ -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;

Chargement…
Annuler
Enregistrer