diff --git a/src/commands/diffWithNext.ts b/src/commands/diffWithNext.ts index f85afc1..f54d7fd 100644 --- a/src/commands/diffWithNext.ts +++ b/src/commands/diffWithNext.ts @@ -38,7 +38,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand { const sha = args.commit === undefined ? gitUri.sha : args.commit.sha; - const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, sha !== undefined ? undefined : 2, args.range!); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, { maxCount: sha !== undefined ? undefined : 2, range: args.range! }); if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare'); args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index 642c1b6..6b1b210 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -39,7 +39,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { try { const sha = args.commit === undefined ? gitUri.sha : args.commit.sha; - const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, sha !== undefined ? undefined : 2, args.range!); + const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, sha, { maxCount: 2, range: args.range!, skipMerges: true }); if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare'); args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values()); diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index c84ebda..9158795 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -38,7 +38,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { const progressCancellation = FileHistoryQuickPick.showProgress(gitUri); try { if (args.log === undefined) { - args.log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, gitUri.sha, args.maxCount, args.range); + args.log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, gitUri.sha, { maxCount: args.maxCount, range: args.range }); if (args.log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to show file history'); } diff --git a/src/git/git.ts b/src/git/git.ts index 562731e..e22d7d9 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -235,16 +235,16 @@ export class Git { return gitCommand({ cwd: repoPath }, ...params); } - static log_file(repoPath: string, fileName: string, sha?: string, maxCount?: number, reverse: boolean = false, startLine?: number, endLine?: number) { + static log_file(repoPath: string, fileName: string, sha?: string, options: { maxCount?: number, reverse?: boolean, startLine?: number, endLine?: number, skipMerges?: boolean } = { reverse: false, skipMerges: false }) { const [file, root] = Git.splitPath(fileName, repoPath); const params = [...defaultLogParams, `--follow`]; - if (maxCount && !reverse) { - params.push(`-n${maxCount}`); + if (options.maxCount && !options.reverse) { + params.push(`-n${options.maxCount}`); } // If we are looking for a specific sha don't exclude merge commits - if (!sha || maxCount! > 2) { + if (options.skipMerges || !sha || options.maxCount! > 2) { params.push(`--no-merges`); } else { @@ -252,7 +252,7 @@ export class Git { } if (sha) { - if (reverse) { + if (options.reverse) { params.push(`--reverse`); params.push(`--ancestry-path`); params.push(`${sha}..HEAD`); @@ -262,8 +262,8 @@ export class Git { } } - if (startLine != null && endLine != null) { - params.push(`-L ${startLine},${endLine}:${file}`); + if (options.startLine != null && options.endLine != null) { + params.push(`-L ${options.startLine},${options.endLine}:${file}`); } params.push(`--`); diff --git a/src/gitService.ts b/src/gitService.ts index f4dce4d..bc50570 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -269,13 +269,13 @@ export class GitService extends Disposable { } async findNextCommit(repoPath: string, fileName: string, sha?: string): Promise { - let log = await this.getLogForFile(repoPath, fileName, sha, 1, undefined, true); + let log = await this.getLogForFile(repoPath, fileName, sha, { maxCount: 1, reverse: true }); let commit = log && Iterables.first(log.commits.values()); if (commit) return commit; const nextFileName = await this.findNextFileName(repoPath, fileName, sha); if (nextFileName) { - log = await this.getLogForFile(repoPath, nextFileName, sha, 1, undefined, true); + log = await this.getLogForFile(repoPath, nextFileName, sha, { maxCount: 1, reverse: true }); commit = log && Iterables.first(log.commits.values()); } @@ -683,7 +683,7 @@ export class GitService extends Disposable { options = options || {}; - const log = await this.getLogForFile(repoPath, fileName, sha, options.previous ? 2 : 1); + const log = await this.getLogForFile(repoPath, fileName, sha, { maxCount: options.previous ? 2 : 1 }); if (log === undefined) return undefined; const commit = sha && log.commits.get(sha); @@ -743,24 +743,26 @@ export class GitService extends Disposable { } } - async getLogForFile(repoPath: string | undefined, fileName: string, sha?: string, maxCount?: number, range?: Range, reverse: boolean = false): Promise { + async getLogForFile(repoPath: string | undefined, fileName: string, sha?: string, options: { maxCount?: number, range?: Range, reverse?: boolean, skipMerges?: boolean } = {}): Promise { + options = { ...{ reverse: false, skipMerges: false }, ...options }; + let key = 'log'; if (sha !== undefined) { key += `:${sha}`; } - if (maxCount !== undefined) { - key += `:n${maxCount}`; + if (options.maxCount !== undefined) { + key += `:n${options.maxCount}`; } let entry: GitCacheEntry | undefined; - if (this.UseCaching && range === undefined && !reverse) { + if (this.UseCaching && options.range === undefined && !options.reverse) { const cacheKey = this.getCacheEntryKey(fileName); entry = this._gitCache.get(cacheKey); if (entry !== undefined) { const cachedLog = entry.get(key); if (cachedLog !== undefined) { - Logger.log(`Cached(${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${maxCount}, undefined, false)`); + Logger.log(`Cached(${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${options.maxCount}, undefined, false)`); return cachedLog.item; } @@ -769,21 +771,21 @@ export class GitService extends Disposable { const cachedLog = entry.get('log'); if (cachedLog !== undefined) { if (sha === undefined) { - Logger.log(`Cached(~${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${maxCount}, undefined, false)`); + Logger.log(`Cached(~${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${options.maxCount}, undefined, false)`); return cachedLog.item; } - Logger.log(`? Cache(${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${maxCount}, undefined, false)`); + Logger.log(`? Cache(${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${options.maxCount}, undefined, false)`); const log = await cachedLog.item; if (log !== undefined && log.commits.has(sha)) { - Logger.log(`Cached(${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${maxCount}, undefined, false)`); + Logger.log(`Cached(${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${options.maxCount}, undefined, false)`); return cachedLog.item; } } } } - Logger.log(`Not Cached(${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${maxCount}, undefined, false)`); + Logger.log(`Not Cached(${key}): getLogForFile('${repoPath}', '${fileName}', ${sha}, ${options.maxCount}, undefined, false)`); if (entry === undefined) { entry = new GitCacheEntry(cacheKey); @@ -791,10 +793,10 @@ export class GitService extends Disposable { } } else { - Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${sha}, ${maxCount}, ${range && `[${range.start.line}, ${range.end.line}]`}, ${reverse})`); + Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${sha}, ${options.maxCount}, ${options.range && `[${options.range.start.line}, ${options.range.end.line}]`}, ${options.reverse})`); } - const promise = this._getLogForFile(repoPath, fileName, sha, range, maxCount, reverse, entry, key); + const promise = this._getLogForFile(repoPath, fileName, sha, options, entry, key); if (entry) { Logger.log(`Add log cache for '${entry.key}:${key}'`); @@ -807,7 +809,7 @@ export class GitService extends Disposable { return promise; } - private async _getLogForFile(repoPath: string | undefined, fileName: string, sha: string | undefined, range: Range | undefined, maxCount: number | undefined, reverse: boolean, entry: GitCacheEntry | undefined, key: string): Promise { + private async _getLogForFile(repoPath: string | undefined, fileName: string, sha: string | undefined, options: { maxCount?: number, range?: Range, reverse?: boolean, skipMerges?: boolean }, entry: GitCacheEntry | undefined, key: string): Promise { const [file, root] = Git.splitPath(fileName, repoPath, false); const ignore = await this._gitignore; @@ -817,8 +819,9 @@ export class GitService extends Disposable { } try { - const data = await Git.log_file(root, file, sha, maxCount, reverse, range && range.start.line + 1, range && range.end.line + 1); - const log = GitLogParser.parse(data, 'file', root, file, sha, maxCount, reverse, range); + const { range, ...opts } = options; + const data = await Git.log_file(root, file, sha, { ...opts, ...{ startLine: range && range.start.line + 1, endLine: range && range.end.line + 1 } }); + const log = GitLogParser.parse(data, 'file', root, file, sha, options.maxCount, options.reverse!, range); return log; } catch (ex) { @@ -886,7 +889,7 @@ export class GitService extends Disposable { } async getRepoPathFromFile(fileName: string): Promise { - const log = await this.getLogForFile(undefined, fileName, undefined, 1); + const log = await this.getLogForFile(undefined, fileName, undefined, { maxCount: 1 }); if (log === undefined) return undefined; return log.repoPath; diff --git a/src/quickPicks/commitFileDetails.ts b/src/quickPicks/commitFileDetails.ts index d7a5747..484d897 100644 --- a/src/quickPicks/commitFileDetails.ts +++ b/src/quickPicks/commitFileDetails.ts @@ -207,7 +207,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 === undefined || c.previousSha === undefined) { - log = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, git.config.advanced.maxQuickHistory); + log = await git.getLogForFile(commit.repoPath, uri.fsPath, commit.sha, { maxCount: git.config.advanced.maxQuickHistory }); if (log === undefined) return KeyNoopCommand; c = log && log.commits.get(commit.sha);