Ver a proveniência

Consolidates certain getLogForFile usage patterns into getLogCommit

main
Eric Amodio há 7 anos
ascendente
cometimento
c10a79a7ee
8 ficheiros alterados com 40 adições e 35 eliminações
  1. +1
    -2
      src/blameActiveLineController.ts
  2. +1
    -4
      src/commands/copyMessageToClipboard.ts
  3. +4
    -6
      src/commands/diffWithWorking.ts
  4. +2
    -4
      src/commands/showQuickCommitFileDetails.ts
  5. +1
    -3
      src/git/gitUri.ts
  6. +2
    -5
      src/gitRevisionCodeLensProvider.ts
  7. +26
    -6
      src/gitService.ts
  8. +3
    -5
      src/quickPicks/commitFileDetails.ts

+ 1
- 2
src/blameActiveLineController.ts Ver ficheiro

@ -298,8 +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.repoPath, this._uri.fsPath, commit.sha, undefined, 1);
logCommit = log && log.commits.get(commit.sha);
logCommit = await this.git.getLogCommit(this._uri.repoPath, this._uri.fsPath, commit.sha);
}
// I have no idea why I need this protection -- but it happens

+ 1
- 4
src/commands/copyMessageToClipboard.ts Ver ficheiro

@ -56,10 +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.repoPath, gitUri.fsPath, sha, undefined, 1);
if (!log) return undefined;
const commit = log.commits.get(sha);
const commit = await this.git.getLogCommit(gitUri.repoPath, gitUri.fsPath, sha);
if (!commit) return undefined;
message = commit.message;

+ 4
- 6
src/commands/diffWithWorking.ts Ver ficheiro

@ -1,5 +1,5 @@
'use strict';
import { Iterables } from '../system';
// import { Iterables } from '../system';
import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands } from './commands';
import { BuiltInCommands } from '../constants';
@ -27,13 +27,11 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri, this.git);
try {
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());
commit = await this.git.getLogCommit(gitUri.repoPath, gitUri.fsPath, gitUri.sha, { firstIfMissing: true });
if (!commit) return window.showWarningMessage(`Unable to open diff. File is probably not under source control`);
}
catch (ex) {
Logger.error('[GitLens.DiffWithWorkingCommand]', `getLogForFile(${gitUri.repoPath}, ${gitUri.fsPath})`, ex);
Logger.error('[GitLens.DiffWithWorkingCommand]', `getLogCommit(${gitUri.repoPath}, ${gitUri.fsPath}, ${gitUri.sha})`, ex);
return window.showErrorMessage(`Unable to open diff. See output channel for more details`);
}
}

+ 2
- 4
src/commands/showQuickCommitFileDetails.ts Ver ficheiro

@ -54,10 +54,8 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
}
if (!fileLog) {
const log = await this.git.getLogForFile(commit ? commit.repoPath : gitUri.repoPath, commit ? commit.uri.fsPath : gitUri.fsPath, sha, undefined, 2);
if (!log) return window.showWarningMessage(`Unable to show commit file details`);
commit = log.commits.get(sha);
commit = await this.git.getLogCommit(commit ? commit.repoPath : gitUri.repoPath, commit ? commit.uri.fsPath : gitUri.fsPath, sha, { previous: true });
if (!commit) return window.showWarningMessage(`Unable to show commit file details`);
}
}

+ 1
- 3
src/git/gitUri.ts Ver ficheiro

@ -1,5 +1,4 @@
'use strict';
import { Iterables } from '../system';
import { Uri } from 'vscode';
import { DocumentSchemes } from '../constants';
import { Git, GitService } from '../gitService';
@ -83,8 +82,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(undefined, uri.fsPath, undefined, undefined, 1);
const commit = log && Iterables.first(log.commits.values());
const commit = await git.getLogCommit(undefined, uri.fsPath);
if (commit) return new GitUri(uri, commit);
}

+ 2
- 5
src/gitRevisionCodeLensProvider.ts Ver ficheiro

@ -1,5 +1,5 @@
'use strict';
import { Iterables } from './system';
// import { Iterables } from './system';
import { CancellationToken, CodeLens, CodeLensProvider, DocumentSelector, ExtensionContext, Range, TextDocument, Uri } from 'vscode';
import { Commands } from './commands';
import { DocumentSchemes } from './constants';
@ -31,10 +31,7 @@ export class GitRevisionCodeLensProvider implements CodeLensProvider {
const lenses: CodeLens[] = [];
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());
const commit = await this.git.getLogCommit(gitUri.repoPath, gitUri.fsPath, gitUri.sha, { firstIfMissing: true, previous: true });
if (!commit) return lenses;
lenses.push(new GitDiffWithWorkingCodeLens(this.git, commit.uri.fsPath, commit, new Range(0, 0, 0, 1)));

+ 26
- 6
src/gitService.ts Ver ficheiro

@ -4,7 +4,7 @@ import { Disposable, Event, EventEmitter, ExtensionContext, FileSystemWatcher, l
import { CommandContext, setCommandContext } from './commands';
import { CodeLensVisibility, IConfig } from './configuration';
import { DocumentSchemes, WorkspaceState } from './constants';
import { Git, GitBlameParser, GitBranch, GitCommit, GitLogParser, GitRemote, GitStatusFile, GitStatusParser, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog, IGitStatus } from './git/git';
import { Git, GitBlameParser, GitBranch, GitCommit, GitLogCommit, GitLogParser, GitRemote, GitStatusFile, GitStatusParser, IGitAuthor, IGitBlame, IGitBlameLine, IGitBlameLines, IGitLog, IGitStatus } from './git/git';
import { IGitUriData, GitUri } from './git/gitUri';
import { GitCodeLensProvider } from './gitCodeLensProvider';
import { Logger } from './logger';
@ -243,13 +243,11 @@ export class GitService extends Disposable {
if (await this._fileExists(repoPath, fileName)) return fileName;
// Get the most recent commit for this file name
let log = await this.getLogForFile(repoPath, fileName, undefined, undefined, 1);
if (!log) return undefined;
let c = Iterables.first(log.commits.values());
let c = await this.getLogCommit(repoPath, fileName);
if (!c) return undefined;
// Get the full commit (so we can see if there are any matching renames in the file statuses)
log = await this.getLogForRepo(repoPath, c.sha, 1);
let log = await this.getLogForRepo(repoPath, c.sha, 1);
if (!log) return undefined;
c = Iterables.first(log.commits.values());
@ -500,6 +498,28 @@ export class GitService extends Disposable {
}
}
async getLogCommit(repoPath: string, fileName: string, options?: { firstIfMissing?: boolean, previous?: boolean }): Promise<GitLogCommit | undefined>;
async getLogCommit(repoPath: string, fileName: string, sha: string, options?: { firstIfMissing?: boolean, previous?: boolean }): Promise<GitLogCommit | undefined>;
async getLogCommit(repoPath: string, fileName: string, shaOrOptions?: string | { firstIfMissing?: boolean, previous?: boolean }, options?: { firstIfMissing?: boolean, previous?: boolean }): Promise<GitLogCommit | undefined> {
let sha: string;
if (typeof shaOrOptions === 'string') {
sha = shaOrOptions;
}
else if (!options) {
options = shaOrOptions;
}
options = options || {};
const log = await this.getLogForFile(repoPath, fileName, sha, undefined, options.previous ? 2 : 1);
if (!log) return undefined;
const commit = sha && log.commits.get(sha);
if (!commit && !options.firstIfMissing) return undefined;
return commit || Iterables.first(log.commits.values());
}
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})`);

+ 3
- 5
src/quickPicks/commitFileDetails.ts Ver ficheiro

@ -39,10 +39,8 @@ 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(undefined, commit.uri.fsPath, undefined, undefined, 2);
if (!log) return undefined;
commit = Iterables.first(log.commits.values());
commit = await git.getLogCommit(undefined, commit.uri.fsPath, { previous: true });
if (!commit) return undefined;
}
items.push(new CommandQuickPickItem({
@ -141,7 +139,7 @@ export class CommitFileDetailsQuickPick {
c = undefined;
// Try to find the next commit
const nextLog = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, undefined, 1, true);
const nextLog = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, undefined, 1, true, true);
const next = nextLog && Iterables.first(nextLog.commits.values());
if (next && next.sha !== commit.sha) {
c = commit;

Carregando…
Cancelar
Guardar