From 818242c6c6d4b08e7c29ba18567d97573ad2b36d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 2 May 2019 23:10:15 -0400 Subject: [PATCH] Renames getLogCommit* methods Removes getRecentLogCommitForFile --- src/annotations/blameAnnotationProvider.ts | 2 +- src/annotations/recentChangesAnnotationProvider.ts | 2 +- src/commands/copyMessageToClipboard.ts | 2 +- src/commands/copyRemoteFileUrlToClipboard.ts | 2 +- src/commands/diffWithWorking.ts | 4 +- src/commands/openInRemote.ts | 7 ++- src/commands/showQuickCommitFileDetails.ts | 2 +- src/git/formatters/commitFormatter.ts | 4 +- src/git/gitService.ts | 71 ++++++++++------------ src/git/models/commit.ts | 8 +-- src/git/models/logCommit.ts | 2 +- src/git/parsers/logParser.ts | 10 +-- src/hovers/lineHoverController.ts | 2 +- src/quickpicks/commitFileQuickPick.ts | 2 +- src/quickpicks/repoStatusQuickPick.ts | 4 +- src/views/nodes/fileHistoryNode.ts | 2 +- src/views/nodes/lineHistoryNode.ts | 2 +- src/views/nodes/statusFilesNode.ts | 2 +- src/views/viewCommands.ts | 2 +- 19 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/annotations/blameAnnotationProvider.ts b/src/annotations/blameAnnotationProvider.ts index ac5e261..a3bc413 100644 --- a/src/annotations/blameAnnotationProvider.ts +++ b/src/annotations/blameAnnotationProvider.ts @@ -219,7 +219,7 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase // Get the full commit message -- since blame only returns the summary let logCommit: GitCommit | undefined = undefined; if (!commit.isUncommitted) { - logCommit = await Container.git.getLogCommitForFile(commit.repoPath, commit.uri.fsPath, { + logCommit = await Container.git.getCommitForFile(commit.repoPath, commit.uri.fsPath, { ref: commit.sha }); if (logCommit !== undefined) { diff --git a/src/annotations/recentChangesAnnotationProvider.ts b/src/annotations/recentChangesAnnotationProvider.ts index c7bd208..1944d62 100644 --- a/src/annotations/recentChangesAnnotationProvider.ts +++ b/src/annotations/recentChangesAnnotationProvider.ts @@ -29,7 +29,7 @@ export class RecentChangesAnnotationProvider extends AnnotationProviderBase { this.annotationType = FileAnnotationType.RecentChanges; - const commit = await Container.git.getRecentLogCommitForFile(this._uri.repoPath, this._uri.fsPath); + const commit = await Container.git.getCommitForFile(this._uri.repoPath, this._uri.fsPath); if (commit === undefined) return false; const diff = await Container.git.getDiffForFile(this._uri, commit.sha); diff --git a/src/commands/copyMessageToClipboard.ts b/src/commands/copyMessageToClipboard.ts index d312d48..b6be01a 100644 --- a/src/commands/copyMessageToClipboard.ts +++ b/src/commands/copyMessageToClipboard.ts @@ -83,7 +83,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { } // Get the full commit message -- since blame only returns the summary - const commit = await Container.git.getLogCommit(gitUri.repoPath!, args.sha); + const commit = await Container.git.getCommit(gitUri.repoPath!, args.sha); if (commit === undefined) return undefined; args.message = commit.message; diff --git a/src/commands/copyRemoteFileUrlToClipboard.ts b/src/commands/copyRemoteFileUrlToClipboard.ts index e35f772..140d967 100644 --- a/src/commands/copyRemoteFileUrlToClipboard.ts +++ b/src/commands/copyRemoteFileUrlToClipboard.ts @@ -54,7 +54,7 @@ export class CopyRemoteFileUrlToClipboardCommand extends ActiveEditorCommand { args = { ...args }; if (gitUri.sha === undefined) { - const commit = await Container.git.getLogCommitForFile(gitUri.repoPath, gitUri.fsPath, { + const commit = await Container.git.getCommitForFile(gitUri.repoPath, gitUri.fsPath, { firstIfNotFound: true }); diff --git a/src/commands/diffWithWorking.ts b/src/commands/diffWithWorking.ts index 7f8c777..7b73ab4 100644 --- a/src/commands/diffWithWorking.ts +++ b/src/commands/diffWithWorking.ts @@ -68,7 +68,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand { if (status !== undefined && status.indexStatus !== undefined) { let sha = GitService.stagedUncommittedSha; if (args.inDiffEditor) { - const commit = await Container.git.getRecentLogCommitForFile(gitUri.repoPath!, gitUri.fsPath); + const commit = await Container.git.getCommitForFile(gitUri.repoPath!, gitUri.fsPath); if (commit === undefined) return Messages.showCommitHasNoPreviousCommitWarningMessage(); sha = commit.sha; @@ -99,7 +99,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand { } try { - args.commit = await Container.git.getLogCommitForFile(gitUri.repoPath, gitUri.fsPath, { + args.commit = await Container.git.getCommitForFile(gitUri.repoPath, gitUri.fsPath, { ref: sha, firstIfNotFound: true }); diff --git a/src/commands/openInRemote.ts b/src/commands/openInRemote.ts index 98a038f..ad63319 100644 --- a/src/commands/openInRemote.ts +++ b/src/commands/openInRemote.ts @@ -110,7 +110,12 @@ export class OpenInRemoteCommand extends ActiveEditorCommand { } private ensureRemoteBranchName(args: OpenInRemoteCommandArgs) { - if (args.remotes === undefined || args.resource === undefined || args.resource.type !== 'branch') return; + if ( + args.remotes === undefined || + args.resource === undefined || + args.resource.type !== RemoteResourceType.Branch + ) + return; // Check to see if the remote is in the branch const [remotePart, branchPart] = Strings.splitSingle(args.resource.branch, '/'); diff --git a/src/commands/showQuickCommitFileDetails.ts b/src/commands/showQuickCommitFileDetails.ts index e3a8e63..aaff265 100644 --- a/src/commands/showQuickCommitFileDetails.ts +++ b/src/commands/showQuickCommitFileDetails.ts @@ -110,7 +110,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand if (args.fileLog === undefined) { const repoPath = args.commit === undefined ? gitUri.repoPath : args.commit.repoPath; - args.commit = await Container.git.getLogCommitForFile(repoPath, gitUri.fsPath, { ref: args.sha }); + args.commit = await Container.git.getCommitForFile(repoPath, gitUri.fsPath, { ref: args.sha }); if (args.commit === undefined) { return Messages.showCommitNotFoundWarningMessage('Unable to show commit file details'); } diff --git a/src/git/formatters/commitFormatter.ts b/src/git/formatters/commitFormatter.ts index b4724c2..0ed5250 100644 --- a/src/git/formatters/commitFormatter.ts +++ b/src/git/formatters/commitFormatter.ts @@ -145,7 +145,7 @@ export class CommitFormatter extends Formatter { } get changes() { - if (!(this._item instanceof GitLogCommit) || this._item.type === GitCommitType.File) { + if (!(this._item instanceof GitLogCommit) || this._item.type === GitCommitType.LogFile) { return this._padOrTruncate(emptyStr, this._options.tokenOptions.changes); } @@ -153,7 +153,7 @@ export class CommitFormatter extends Formatter { } get changesShort() { - if (!(this._item instanceof GitLogCommit) || this._item.type === GitCommitType.File) { + if (!(this._item instanceof GitLogCommit) || this._item.type === GitCommitType.LogFile) { return this._padOrTruncate(emptyStr, this._options.tokenOptions.changesShort); } diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 9320b57..a7262f6 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -1011,6 +1011,36 @@ export class GitService implements Disposable { } @log() + async getCommit(repoPath: string, ref: string): Promise { + const log = await this.getLog(repoPath, { maxCount: 2, ref: ref }); + if (log === undefined) return undefined; + + return log.commits.get(ref); + } + + @log() + async getCommitForFile( + repoPath: string | undefined, + fileName: string, + options: { ref?: string; firstIfNotFound?: boolean; reverse?: boolean } = {} + ): Promise { + const log = await this.getLogForFile(repoPath, fileName, { + maxCount: 2, + ref: options.ref, + reverse: options.reverse + }); + if (log === undefined) return undefined; + + const commit = options.ref && log.commits.get(options.ref); + if (commit === undefined && !options.firstIfNotFound && options.ref) { + // If the ref isn't a valid sha we will never find it, so let it fall through so we return the first + if (!Git.isSha(options.ref) || Git.isUncommitted(options.ref)) return undefined; + } + + return commit || Iterables.first(log.commits.values()); + } + + @log() getConfig(key: string, repoPath?: string): Promise { return Git.config_get(key, repoPath); } @@ -1236,41 +1266,6 @@ export class GitService implements Disposable { } @log() - getRecentLogCommitForFile(repoPath: string | undefined, fileName: string): Promise { - return this.getLogCommitForFile(repoPath, fileName, undefined); - } - - @log() - async getLogCommit(repoPath: string, ref: string): Promise { - const log = await this.getLog(repoPath, { maxCount: 2, ref: ref }); - if (log === undefined) return undefined; - - return log.commits.get(ref); - } - - @log() - async getLogCommitForFile( - repoPath: string | undefined, - fileName: string, - options: { ref?: string; firstIfNotFound?: boolean; reverse?: boolean } = {} - ): Promise { - const log = await this.getLogForFile(repoPath, fileName, { - maxCount: 2, - ref: options.ref, - reverse: options.reverse - }); - if (log === undefined) return undefined; - - const commit = options.ref && log.commits.get(options.ref); - if (commit === undefined && !options.firstIfNotFound && options.ref) { - // If the ref isn't a valid sha we will never find it, so let it fall through so we return the first - if (!Git.isSha(options.ref) || Git.isUncommitted(options.ref)) return undefined; - } - - return commit || Iterables.first(log.commits.values()); - } - - @log() async getLog( repoPath: string, { ref, ...options }: { authors?: string[]; maxCount?: number; ref?: string; reverse?: boolean } = {} @@ -1286,7 +1281,7 @@ export class GitService implements Disposable { }); const log = GitLogParser.parse( data, - GitCommitType.Branch, + GitCommitType.Log, repoPath, undefined, ref, @@ -1386,7 +1381,7 @@ export class GitService implements Disposable { const data = await Git.log_search(repoPath, searchArgs, { maxCount: maxCount }); const log = GitLogParser.parse( data, - GitCommitType.Branch, + GitCommitType.Log, repoPath, undefined, undefined, @@ -1562,7 +1557,7 @@ export class GitService implements Disposable { }); const log = GitLogParser.parse( data, - GitCommitType.File, + GitCommitType.LogFile, root, file, ref, diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index c02adb4..acbf0d5 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -23,10 +23,10 @@ export interface GitCommitLine { export enum GitCommitType { Blame = 'blame', - Branch = 'branch', - File = 'file', + Log = 'log', + LogFile = 'logFile', Stash = 'stash', - StashFile = 'stash-file' + StashFile = 'stashFile' } export const CommitFormatting = { @@ -86,7 +86,7 @@ export abstract class GitCommit { get isFile() { return ( this.type === GitCommitType.Blame || - this.type === GitCommitType.File || + this.type === GitCommitType.LogFile || this.type === GitCommitType.StashFile ); } diff --git a/src/git/models/logCommit.ts b/src/git/models/logCommit.ts index f26eacb..020ce33 100644 --- a/src/git/models/logCommit.ts +++ b/src/git/models/logCommit.ts @@ -162,7 +162,7 @@ export class GitLogCommit extends GitCommit { const previousSha = this.isFile ? this.previousSha : `${this.sha}^`; return this.with({ - type: this.isStash ? GitCommitType.StashFile : GitCommitType.File, + type: this.isStash ? GitCommitType.StashFile : GitCommitType.LogFile, sha: sha, fileName: file.fileName, originalFileName: file.originalFileName, diff --git a/src/git/parsers/logParser.ts b/src/git/parsers/logParser.ts index c4b0c16..e753670 100644 --- a/src/git/parsers/logParser.ts +++ b/src/git/parsers/logParser.ts @@ -180,7 +180,7 @@ export class GitLogParser { if (line.startsWith('warning:')) continue; - if (type === GitCommitType.Branch) { + if (type === GitCommitType.Log) { match = fileStatusRegex.exec(line); if (match != null) { if (entry.files === undefined) { @@ -262,7 +262,7 @@ export class GitLogParser { ); } - if (first && repoPath === undefined && type === GitCommitType.File && fileName !== undefined) { + if (first && repoPath === undefined && type === GitCommitType.LogFile && fileName !== undefined) { // Try to get the repoPath from the most recent commit repoPath = Strings.normalizePath( fileName.replace( @@ -353,7 +353,7 @@ export class GitLogParser { const originalFileName = entry.originalFileName || (relativeFileName !== entry.fileName ? entry.fileName : undefined); - if (type === GitCommitType.File) { + if (type === GitCommitType.LogFile) { entry.files = [ { status: entry.status!, @@ -376,7 +376,7 @@ export class GitLogParser { entry.files || [], entry.status, originalFileName, - type === GitCommitType.Branch ? entry.parentShas![0] : undefined, + type === GitCommitType.Log ? entry.parentShas![0] : undefined, undefined, entry.parentShas!, entry.line @@ -393,7 +393,7 @@ export class GitLogParser { commit.nextSha = commit.sha !== recentCommit.sha ? recentCommit.sha : recentCommit.nextSha; // Only add a filename if this is a file log - if (type === GitCommitType.File) { + if (type === GitCommitType.LogFile) { recentCommit.previousFileName = commit.originalFileName || commit.fileName; commit.nextFileName = recentCommit.originalFileName || recentCommit.fileName; } diff --git a/src/hovers/lineHoverController.ts b/src/hovers/lineHoverController.ts index 40d76a9..b5f59c6 100644 --- a/src/hovers/lineHoverController.ts +++ b/src/hovers/lineHoverController.ts @@ -99,7 +99,7 @@ export class LineHoverController implements Disposable { // Get the full commit message -- since blame only returns the summary let logCommit = lineState !== undefined ? lineState.logCommit : undefined; if (logCommit === undefined && !commit.isUncommitted) { - logCommit = await Container.git.getLogCommitForFile(commit.repoPath, commit.uri.fsPath, { + logCommit = await Container.git.getCommitForFile(commit.repoPath, commit.uri.fsPath, { ref: commit.sha }); if (logCommit !== undefined) { diff --git a/src/quickpicks/commitFileQuickPick.ts b/src/quickpicks/commitFileQuickPick.ts index 6a4e140..701f716 100644 --- a/src/quickpicks/commitFileQuickPick.ts +++ b/src/quickpicks/commitFileQuickPick.ts @@ -103,7 +103,7 @@ export class CommitFileQuickPick { 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 c = await Container.git.getRecentLogCommitForFile(undefined, commit.uri.fsPath); + const c = await Container.git.getCommitForFile(undefined, commit.uri.fsPath); if (c === undefined) return undefined; commit = c; diff --git a/src/quickpicks/repoStatusQuickPick.ts b/src/quickpicks/repoStatusQuickPick.ts index dcefd89..5a34d91 100644 --- a/src/quickpicks/repoStatusQuickPick.ts +++ b/src/quickpicks/repoStatusQuickPick.ts @@ -52,7 +52,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick this.status = status; if (status.indexStatus !== undefined) { this.commit = new GitLogCommit( - GitCommitType.File, + GitCommitType.LogFile, status.repoPath, GitService.stagedUncommittedSha, 'You', @@ -70,7 +70,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick } else { this.commit = new GitLogCommit( - GitCommitType.File, + GitCommitType.LogFile, status.repoPath, GitService.uncommittedSha, 'You', diff --git a/src/views/nodes/fileHistoryNode.ts b/src/views/nodes/fileHistoryNode.ts index ffeaa20..2763c84 100644 --- a/src/views/nodes/fileHistoryNode.ts +++ b/src/views/nodes/fileHistoryNode.ts @@ -54,7 +54,7 @@ export class FileHistoryNode extends SubscribeableViewNode implements PageableVi const user = await Container.git.getCurrentUser(this.uri.repoPath!); const commit = new GitLogCommit( - GitCommitType.File, + GitCommitType.LogFile, this.uri.repoPath!, sha, 'You', diff --git a/src/views/nodes/lineHistoryNode.ts b/src/views/nodes/lineHistoryNode.ts index 21992f4..5ef23f2 100644 --- a/src/views/nodes/lineHistoryNode.ts +++ b/src/views/nodes/lineHistoryNode.ts @@ -59,7 +59,7 @@ export class LineHistoryNode extends SubscribeableViewNode implements PageableVi }; const uncommitted = new GitLogCommit( - GitCommitType.File, + GitCommitType.LogFile, this.uri.repoPath!, commit.sha, 'You', diff --git a/src/views/nodes/statusFilesNode.ts b/src/views/nodes/statusFilesNode.ts index 913100e..84e47a9 100644 --- a/src/views/nodes/statusFilesNode.ts +++ b/src/views/nodes/statusFilesNode.ts @@ -166,7 +166,7 @@ export class StatusFilesNode extends ViewNode { fileName: file.fileName, originalFileName: file.originalFileName, commit: new GitLogCommit( - GitCommitType.File, + GitCommitType.LogFile, file.repoPath, ref, 'You', diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 3a3b56b..e09b737 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -367,7 +367,7 @@ export class ViewCommands implements Disposable { }; if (node instanceof ResultsFileNode) { - args.commit = await Container.git.getLogCommitForFile(node.repoPath, node.uri.fsPath, { + args.commit = await Container.git.getCommitForFile(node.repoPath, node.uri.fsPath, { ref: node.uri.sha, firstIfNotFound: true, reverse: true