From aa39792843d871ef83528a6d22da78aa5c2dd619 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 28 Mar 2017 15:10:00 -0400 Subject: [PATCH] Moves type to GitCommit for better consistency --- src/commands/diffLineWithPrevious.ts | 2 +- src/commands/diffLineWithWorking.ts | 2 +- src/commands/openCommitInRemote.ts | 2 +- src/git/models/commit.ts | 6 ++++++ src/git/models/logCommit.ts | 8 +++----- src/git/parsers/blameParser.ts | 2 +- src/git/parsers/logParser.ts | 6 +++--- src/gitService.ts | 2 +- src/quickPicks/repoStatus.ts | 2 +- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/commands/diffLineWithPrevious.ts b/src/commands/diffLineWithPrevious.ts index c331d17..dc25e74 100644 --- a/src/commands/diffLineWithPrevious.ts +++ b/src/commands/diffLineWithPrevious.ts @@ -43,7 +43,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand { // If the line is uncommitted, find the previous commit and treat it as a DiffWithWorking if (commit.isUncommitted) { uri = commit.uri; - commit = new GitCommit(commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message); + commit = new GitCommit(commit.type, commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message); line = (blame.line.line + 1) + gitUri.offset; return commands.executeCommand(Commands.DiffWithWorking, uri, commit, line); } diff --git a/src/commands/diffLineWithWorking.ts b/src/commands/diffLineWithWorking.ts index 7a6fa86..d9a970c 100644 --- a/src/commands/diffLineWithWorking.ts +++ b/src/commands/diffLineWithWorking.ts @@ -34,7 +34,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand { commit = blame.commit; // If the line is uncommitted, find the previous commit if (commit.isUncommitted) { - commit = new GitCommit(commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message); + commit = new GitCommit(commit.type, commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message); line = blame.line.line + 1 + gitUri.offset; } } diff --git a/src/commands/openCommitInRemote.ts b/src/commands/openCommitInRemote.ts index 7ee9f22..21fc02a 100644 --- a/src/commands/openCommitInRemote.ts +++ b/src/commands/openCommitInRemote.ts @@ -32,7 +32,7 @@ export class OpenCommitInRemoteCommand extends ActiveEditorCommand { let commit = blame.commit; // If the line is uncommitted, find the previous commit if (commit.isUncommitted) { - commit = new GitCommit(commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message); + commit = new GitCommit(commit.type, commit.repoPath, commit.previousSha, commit.previousFileName, commit.author, commit.date, commit.message); } const remotes = Arrays.uniqueBy(await this.git.getRemotes(this.repoPath), _ => _.url, _ => !!_.provider); diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index 4f01ad1..7067e45 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -9,6 +9,7 @@ export interface IGitAuthor { } export interface IGitCommit { + type: GitCommitType; repoPath: string; sha: string; fileName: string; @@ -33,8 +34,11 @@ export interface IGitCommitLine { code?: string; } +export type GitCommitType = 'blame' | 'file' | 'repo'; + export class GitCommit implements IGitCommit { + type: GitCommitType; lines: IGitCommitLine[]; originalFileName?: string; previousSha?: string; @@ -43,6 +47,7 @@ export class GitCommit implements IGitCommit { private _isUncommitted: boolean | undefined; constructor( + type: GitCommitType, public repoPath: string, public sha: string, public fileName: string, @@ -54,6 +59,7 @@ export class GitCommit implements IGitCommit { previousSha?: string, previousFileName?: string ) { + this.type = type; this.fileName = this.fileName && this.fileName.replace(/, ?$/, ''); this.lines = lines || []; diff --git a/src/git/models/logCommit.ts b/src/git/models/logCommit.ts index 8c71a0c..b79d1bb 100644 --- a/src/git/models/logCommit.ts +++ b/src/git/models/logCommit.ts @@ -1,11 +1,9 @@ 'use strict'; import { Uri } from 'vscode'; -import { GitCommit, IGitCommitLine } from './commit'; +import { GitCommit, GitCommitType, IGitCommitLine } from './commit'; import { IGitStatusFile, GitStatusFileStatus } from './status'; import * as path from 'path'; -export type GitLogType = 'file' | 'repo'; - export class GitLogCommit extends GitCommit { fileNames: string; @@ -15,7 +13,7 @@ export class GitLogCommit extends GitCommit { parentShas: string[]; constructor( - public type: GitLogType, + type: GitCommitType, repoPath: string, sha: string, fileName: string, @@ -29,7 +27,7 @@ export class GitLogCommit extends GitCommit { previousSha?: string, previousFileName?: string ) { - super(repoPath, sha, fileName, author, date, message, lines, originalFileName, previousSha, previousFileName); + super(type, repoPath, sha, fileName, author, date, message, lines, originalFileName, previousSha, previousFileName); this.fileNames = this.fileName; diff --git a/src/git/parsers/blameParser.ts b/src/git/parsers/blameParser.ts index b04172e..250ff59 100644 --- a/src/git/parsers/blameParser.ts +++ b/src/git/parsers/blameParser.ts @@ -146,7 +146,7 @@ export class GitBlameParser { authors.set(entry.author, author); } - commit = new GitCommit(repoPath, entry.sha, relativeFileName, entry.author, moment(`${entry.authorDate} ${entry.authorTimeZone}`, 'X +-HHmm').toDate(), entry.summary); + commit = new GitCommit('blame', repoPath, entry.sha, relativeFileName, entry.author, moment(`${entry.authorDate} ${entry.authorTimeZone}`, 'X +-HHmm').toDate(), entry.summary); if (relativeFileName !== entry.fileName) { commit.originalFileName = entry.fileName; diff --git a/src/git/parsers/logParser.ts b/src/git/parsers/logParser.ts index 82b4cb2..c2bacb9 100644 --- a/src/git/parsers/logParser.ts +++ b/src/git/parsers/logParser.ts @@ -1,6 +1,6 @@ 'use strict'; import { Range } from 'vscode'; -import { Git, GitStatusFileStatus, GitLogCommit, GitLogType, IGitAuthor, IGitLog, IGitStatusFile } from './../git'; +import { Git, GitStatusFileStatus, GitLogCommit, GitCommitType, IGitAuthor, IGitLog, IGitStatusFile } from './../git'; // import { Logger } from '../../logger'; import * as moment from 'moment'; import * as path from 'path'; @@ -29,7 +29,7 @@ const diffRegex = /diff --git a\/(.*) b\/(.*)/; export class GitLogParser { - private static _parseEntries(data: string, type: GitLogType, maxCount: number | undefined, reverse: boolean): ILogEntry[] { + private static _parseEntries(data: string, type: GitCommitType, maxCount: number | undefined, reverse: boolean): ILogEntry[] { if (!data) return undefined; const lines = data.split('\n'); @@ -164,7 +164,7 @@ export class GitLogParser { return entries; } - static parse(data: string, type: GitLogType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range): IGitLog { + static parse(data: string, type: GitCommitType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range): IGitLog { const entries = this._parseEntries(data, type, maxCount, reverse); if (!entries) return undefined; diff --git a/src/gitService.ts b/src/gitService.ts index 55f666d..954c0fa 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -435,7 +435,7 @@ export class GitService extends Disposable { blame.commits.forEach(c => { if (!shas.has(c.sha)) return; - const commit: GitCommit = new GitCommit(c.repoPath, c.sha, c.fileName, c.author, c.date, c.message, + const commit: GitCommit = new GitCommit('blame', c.repoPath, c.sha, c.fileName, c.author, c.date, c.message, c.lines.filter(l => l.line >= range.start.line && l.line <= range.end.line), c.originalFileName, c.previousSha, c.previousFileName); commits.set(c.sha, commit); diff --git a/src/quickPicks/repoStatus.ts b/src/quickPicks/repoStatus.ts index 234ecd9..ba0d3be 100644 --- a/src/quickPicks/repoStatus.ts +++ b/src/quickPicks/repoStatus.ts @@ -3,7 +3,7 @@ import { Iterables } from '../system'; import { QuickPickItem, QuickPickOptions, Uri, window } from 'vscode'; import { Commands, Keyboard } from '../commands'; import { Git, GitStatusFile, GitUri, IGitStatus } from '../gitService'; -import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, OpenFileCommandQuickPickItem } from './quickPicks'; +import { CommandQuickPickItem, getQuickPickIgnoreFocusOut, OpenFileCommandQuickPickItem } from '../quickPicks'; import * as path from 'path'; export class OpenStatusFileCommandQuickPickItem extends OpenFileCommandQuickPickItem {