Skip to content

Commit

Permalink
Renames getLogCommit* methods
Browse files Browse the repository at this point in the history
Removes getRecentLogCommitForFile
  • Loading branch information
eamodio committed May 3, 2019
1 parent 9c75a74 commit 818242c
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/annotations/blameAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/recentChangesAnnotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/copyMessageToClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/copyRemoteFileUrlToClipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down
4 changes: 2 additions & 2 deletions src/commands/diffWithWorking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
});
Expand Down
7 changes: 6 additions & 1 deletion src/commands/openInRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
Expand Down
2 changes: 1 addition & 1 deletion src/commands/showQuickCommitFileDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
4 changes: 2 additions & 2 deletions src/git/formatters/commitFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
}

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

return this._padOrTruncate(this._item.getFormattedDiffStatus(), this._options.tokenOptions.changes);
}

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

Expand Down
71 changes: 33 additions & 38 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,36 @@ export class GitService implements Disposable {
return GitDiffParser.parseShortStat(data);
}

@log()
async getCommit(repoPath: string, ref: string): Promise<GitLogCommit | undefined> {
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<GitLogCommit | undefined> {
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<string | undefined> {
return Git.config_get(key, repoPath);
Expand Down Expand Up @@ -1235,41 +1265,6 @@ export class GitService implements Disposable {
return files[0];
}

@log()
getRecentLogCommitForFile(repoPath: string | undefined, fileName: string): Promise<GitLogCommit | undefined> {
return this.getLogCommitForFile(repoPath, fileName, undefined);
}

@log()
async getLogCommit(repoPath: string, ref: string): Promise<GitLogCommit | undefined> {
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<GitLogCommit | undefined> {
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,
Expand All @@ -1286,7 +1281,7 @@ export class GitService implements Disposable {
});
const log = GitLogParser.parse(
data,
GitCommitType.Branch,
GitCommitType.Log,
repoPath,
undefined,
ref,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1562,7 +1557,7 @@ export class GitService implements Disposable {
});
const log = GitLogParser.parse(
data,
GitCommitType.File,
GitCommitType.LogFile,
root,
file,
ref,
Expand Down
8 changes: 4 additions & 4 deletions src/git/models/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/git/models/logCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/git/parsers/logParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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!,
Expand All @@ -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
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hovers/lineHoverController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/quickpicks/commitFileQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/quickpicks/repoStatusQuickPick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -70,7 +70,7 @@ export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPick
}
else {
this.commit = new GitLogCommit(
GitCommitType.File,
GitCommitType.LogFile,
status.repoPath,
GitService.uncommittedSha,
'You',
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/fileHistoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/lineHistoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/views/nodes/statusFilesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class StatusFilesNode extends ViewNode<RepositoriesView> {
fileName: file.fileName,
originalFileName: file.originalFileName,
commit: new GitLogCommit(
GitCommitType.File,
GitCommitType.LogFile,
file.repoPath,
ref,
'You',
Expand Down
2 changes: 1 addition & 1 deletion src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 818242c

Please sign in to comment.