Parcourir la source

Refactors to use options obj for optional params

main
Eric Amodio il y a 7 ans
Parent
révision
bad7ac447a
22 fichiers modifiés avec 172 ajouts et 165 suppressions
  1. +1
    -1
      src/annotations/annotations.ts
  2. +1
    -1
      src/commands/copyMessageToClipboard.ts
  3. +1
    -1
      src/commands/copyShaToClipboard.ts
  4. +1
    -1
      src/commands/diffWithNext.ts
  5. +1
    -1
      src/commands/diffWithPrevious.ts
  6. +1
    -1
      src/commands/diffWithRevision.ts
  7. +1
    -1
      src/commands/showCommitSearch.ts
  8. +1
    -1
      src/commands/showQuickBranchHistory.ts
  9. +1
    -1
      src/commands/showQuickCommitDetails.ts
  10. +80
    -80
      src/commands/showQuickFileHistory.ts
  11. +23
    -23
      src/git/git.ts
  12. +48
    -41
      src/gitService.ts
  13. +2
    -2
      src/quickPicks/commitDetails.ts
  14. +1
    -1
      src/quickPicks/commitFileDetails.ts
  15. +1
    -1
      src/views/branchNode.ts
  16. +1
    -1
      src/views/commitFileNode.ts
  17. +1
    -1
      src/views/commitNode.ts
  18. +1
    -1
      src/views/comparisionResultsNode.ts
  19. +1
    -1
      src/views/fileHistoryNode.ts
  20. +1
    -1
      src/views/stashNode.ts
  21. +1
    -1
      src/views/statusFilesNode.ts
  22. +2
    -2
      src/views/statusUpstreamNode.ts

+ 1
- 1
src/annotations/annotations.ts Voir le fichier

@ -259,6 +259,6 @@ export class Annotations {
});
}
return { ...decoration, ...{ range: range } };
return { ...decoration, range: range };
}
}

+ 1
- 1
src/commands/copyMessageToClipboard.ts Voir le fichier

@ -40,7 +40,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
const repoPath = await this.git.getActiveRepoPath(editor);
if (!repoPath) return undefined;
const log = await this.git.getLogForRepo(repoPath, undefined, 1);
const log = await this.git.getLogForRepo(repoPath, { maxCount: 1 });
if (!log) return undefined;
args.message = Iterables.first(log.commits.values()).message;

+ 1
- 1
src/commands/copyShaToClipboard.ts Voir le fichier

@ -39,7 +39,7 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
const repoPath = await this.git.getActiveRepoPath(editor);
if (!repoPath) return undefined;
const log = await this.git.getLogForRepo(repoPath, undefined, 1);
const log = await this.git.getLogForRepo(repoPath, { maxCount: 1 });
if (!log) return undefined;
args.sha = Iterables.first(log.commits.values()).sha;

+ 1
- 1
src/commands/diffWithNext.ts Voir le fichier

@ -42,7 +42,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
// If we are a fake "staged" sha, treat it as a DiffWithWorking
if (GitService.isStagedUncommitted(sha!)) return commands.executeCommand(Commands.DiffWithWorking, uri);
const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, undefined, { maxCount: sha !== undefined ? undefined : 2, range: args.range! });
const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { 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());

+ 1
- 1
src/commands/diffWithPrevious.ts Voir le fichier

@ -47,7 +47,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
isStagedUncommitted = true;
}
const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, sha, { maxCount: 2, range: args.range!, skipMerges: true });
const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: 2, range: args.range!, ref: sha, skipMerges: true });
if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare');
args.commit = (sha && log.commits.get(sha)) || Iterables.first(log.commits.values());

+ 1
- 1
src/commands/diffWithRevision.ts Voir le fichier

@ -38,7 +38,7 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
try {
const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, gitUri.sha, { maxCount: args.maxCount });
const log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: args.maxCount, ref: gitUri.sha });
if (log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open history compare');
if (progressCancellation.token.isCancellationRequested) return undefined;

+ 1
- 1
src/commands/showCommitSearch.ts Voir le fichier

@ -117,7 +117,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
const progressCancellation = CommitsQuickPick.showProgress(placeHolder!);
try {
const queryFn = ((search: string, searchBy: GitRepoSearchBy) => (maxCount: number | undefined) => this.git.getLogForRepoSearch(repoPath, search, searchBy, maxCount))(args.search, args.searchBy);
const queryFn = ((search: string, searchBy: GitRepoSearchBy) => (maxCount: number | undefined) => this.git.getLogForRepoSearch(repoPath, search, searchBy, { maxCount: maxCount }))(args.search, args.searchBy);
const log = await queryFn(undefined);
if (progressCancellation.token.isCancellationRequested) return undefined;

+ 1
- 1
src/commands/showQuickBranchHistory.ts Voir le fichier

@ -56,7 +56,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
}
if (args.log === undefined) {
args.log = await this.git.getLogForRepo(repoPath, (gitUri && gitUri.sha) || args.branch, args.maxCount);
args.log = await this.git.getLogForRepo(repoPath, { maxCount: args.maxCount, ref: (gitUri && gitUri.sha) || args.branch });
if (args.log === undefined) return window.showWarningMessage(`Unable to show branch history`);
}

+ 1
- 1
src/commands/showQuickCommitDetails.ts Voir le fichier

@ -93,7 +93,7 @@ export class ShowQuickCommitDetailsCommand extends ActiveEditorCachedCommand {
}
if (args.repoLog === undefined) {
const log = await this.git.getLogForRepo(repoPath!, args.sha, 2);
const log = await this.git.getLogForRepo(repoPath!, { maxCount: 2, ref: args.sha });
if (log === undefined) return Messages.showCommitNotFoundWarningMessage(`Unable to show commit details`);
args.commit = log.commits.get(args.sha!);

+ 80
- 80
src/commands/showQuickFileHistory.ts Voir le fichier

@ -1,81 +1,81 @@
'use strict';
import { Strings } from '../system';
import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { GlyphChars } from '../constants';
import { GitLog, GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
import { CommandQuickPickItem, FileHistoryQuickPick } from '../quickPicks';
import { ShowQuickCommitFileDetailsCommandArgs } from './showQuickCommitFileDetails';
import { Messages } from '../messages';
import * as path from 'path';
export interface ShowQuickFileHistoryCommandArgs {
log?: GitLog;
maxCount?: number;
range?: Range;
goBackCommand?: CommandQuickPickItem;
nextPageCommand?: CommandQuickPickItem;
}
export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
constructor(
private readonly git: GitService
) {
super(Commands.ShowQuickFileHistory);
}
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory);
const gitUri = await GitUri.fromUri(uri, this.git);
args = { ...args };
if (args.maxCount == null) {
args.maxCount = this.git.config.advanced.maxQuickHistory;
}
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
try {
if (args.log === undefined) {
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');
}
if (progressCancellation.token.isCancellationRequested) return undefined;
const pick = await FileHistoryQuickPick.show(this.git, args.log, gitUri, progressCancellation, { goBackCommand: args.goBackCommand, nextPageCommand: args.nextPageCommand });
if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return pick.execute();
// Create a command to get back to where we are right now
const currentCommand = new CommandQuickPickItem({
label: `go back ${GlyphChars.ArrowBack}`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to history of ${GlyphChars.Space}$(file-text) ${path.basename(pick.commit.fileName)}${gitUri.sha ? ` from ${GlyphChars.Space}$(git-commit) ${gitUri.shortSha}` : ''}`
}, Commands.ShowQuickFileHistory, [
uri,
args
]);
return commands.executeCommand(Commands.ShowQuickCommitFileDetails,
pick.commit.toGitUri(),
{
commit: pick.commit,
fileLog: args.log,
sha: pick.commit.sha,
goBackCommand: currentCommand
} as ShowQuickCommitFileDetailsCommandArgs);
}
catch (ex) {
Logger.error(ex, 'ShowQuickFileHistoryCommand');
return window.showErrorMessage(`Unable to show file history. See output channel for more details`);
}
finally {
progressCancellation.dispose();
}
}
'use strict';
import { Strings } from '../system';
import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common';
import { GlyphChars } from '../constants';
import { GitLog, GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
import { CommandQuickPickItem, FileHistoryQuickPick } from '../quickPicks';
import { ShowQuickCommitFileDetailsCommandArgs } from './showQuickCommitFileDetails';
import { Messages } from '../messages';
import * as path from 'path';
export interface ShowQuickFileHistoryCommandArgs {
log?: GitLog;
maxCount?: number;
range?: Range;
goBackCommand?: CommandQuickPickItem;
nextPageCommand?: CommandQuickPickItem;
}
export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
constructor(
private readonly git: GitService
) {
super(Commands.ShowQuickFileHistory);
}
async execute(editor?: TextEditor, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) {
uri = getCommandUri(uri, editor);
if (uri === undefined) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory);
const gitUri = await GitUri.fromUri(uri, this.git);
args = { ...args };
if (args.maxCount == null) {
args.maxCount = this.git.config.advanced.maxQuickHistory;
}
const progressCancellation = FileHistoryQuickPick.showProgress(gitUri);
try {
if (args.log === undefined) {
args.log = await this.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { maxCount: args.maxCount, range: args.range, ref: gitUri.sha });
if (args.log === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to show file history');
}
if (progressCancellation.token.isCancellationRequested) return undefined;
const pick = await FileHistoryQuickPick.show(this.git, args.log, gitUri, progressCancellation, { goBackCommand: args.goBackCommand, nextPageCommand: args.nextPageCommand });
if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return pick.execute();
// Create a command to get back to where we are right now
const currentCommand = new CommandQuickPickItem({
label: `go back ${GlyphChars.ArrowBack}`,
description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to history of ${GlyphChars.Space}$(file-text) ${path.basename(pick.commit.fileName)}${gitUri.sha ? ` from ${GlyphChars.Space}$(git-commit) ${gitUri.shortSha}` : ''}`
}, Commands.ShowQuickFileHistory, [
uri,
args
]);
return commands.executeCommand(Commands.ShowQuickCommitFileDetails,
pick.commit.toGitUri(),
{
commit: pick.commit,
fileLog: args.log,
sha: pick.commit.sha,
goBackCommand: currentCommand
} as ShowQuickCommitFileDetailsCommandArgs);
}
catch (ex) {
Logger.error(ex, 'ShowQuickFileHistoryCommand');
return window.showErrorMessage(`Unable to show file history. See output channel for more details`);
}
finally {
progressCancellation.dispose();
}
}
}

+ 23
- 23
src/git/git.ts Voir le fichier

@ -345,25 +345,25 @@ export class Git {
return gitCommand({ cwd: repoPath }, ...params);
}
static log(repoPath: string, sha?: string, maxCount?: number, reverse: boolean = false) {
static log(repoPath: string, options: { maxCount?: number, ref?: string, reverse?: boolean }) {
const params = [...defaultLogParams, `-m`];
if (maxCount && !reverse) {
params.push(`-n${maxCount}`);
if (options.maxCount && !options.reverse) {
params.push(`-n${options.maxCount}`);
}
if (sha && !Git.isStagedUncommitted(sha)) {
if (reverse) {
if (options.ref && !Git.isStagedUncommitted(options.ref)) {
if (options.reverse) {
params.push(`--reverse`);
params.push(`--ancestry-path`);
params.push(`${sha}..HEAD`);
params.push(`${options.ref}..HEAD`);
}
else {
params.push(sha);
params.push(options.ref);
}
}
return gitCommand({ cwd: repoPath }, ...params);
}
static log_file(repoPath: string, fileName: string, sha?: string, options: { maxCount?: number, reverse?: boolean, startLine?: number, endLine?: number, skipMerges?: boolean } = { reverse: false, skipMerges: false }) {
static log_file(repoPath: string, fileName: string, options: { maxCount?: number, ref?: string, reverse?: boolean, startLine?: number, endLine?: number, skipMerges?: boolean } = { reverse: false, skipMerges: false }) {
const [file, root] = Git.splitPath(fileName, repoPath);
const params = [...defaultLogParams, `--follow`];
@ -372,21 +372,21 @@ export class Git {
}
// If we are looking for a specific sha don't exclude merge commits
if (options.skipMerges || !sha || options.maxCount! > 2) {
if (options.skipMerges || !options.ref || options.maxCount! > 2) {
params.push(`--no-merges`);
}
else {
params.push(`-m`);
}
if (sha && !Git.isStagedUncommitted(sha)) {
if (options.ref && !Git.isStagedUncommitted(options.ref)) {
if (options.reverse) {
params.push(`--reverse`);
params.push(`--ancestry-path`);
params.push(`${sha}..HEAD`);
params.push(`${options.ref}..HEAD`);
}
else {
params.push(sha);
params.push(options.ref);
}
}
@ -400,9 +400,9 @@ export class Git {
return gitCommand({ cwd: root }, ...params);
}
static async log_resolve(repoPath: string, sha: string, fileName: string) {
static async log_resolve(repoPath: string, fileName: string, ref: string) {
try {
const data = await gitCommand({ cwd: repoPath, willHandleErrors: true }, `log`, `--full-history`, `-M`, `-n1`, `--no-merges`, `--format=%H`, sha, `--`, fileName);
const data = await gitCommand({ cwd: repoPath, willHandleErrors: true }, `log`, `--full-history`, `-M`, `-n1`, `--no-merges`, `--format=%H`, ref, `--`, fileName);
return data.trim();
}
catch {
@ -410,27 +410,27 @@ export class Git {
}
}
static log_search(repoPath: string, search: string[] = [], maxCount?: number) {
static log_search(repoPath: string, search: string[] = [], options: { maxCount?: number } = {}) {
const params = [...defaultLogParams, `-m`, `-i`];
if (maxCount) {
params.push(`-n${maxCount}`);
if (options.maxCount) {
params.push(`-n${options.maxCount}`);
}
return gitCommand({ cwd: repoPath }, ...params, ...search);
}
static log_shortstat(repoPath: string, sha?: string) {
static log_shortstat(repoPath: string, options: { ref?: string }) {
const params = [`log`, `--shortstat`, `--oneline`];
if (sha && !Git.isStagedUncommitted(sha)) {
params.push(sha);
if (options.ref && !Git.isStagedUncommitted(options.ref)) {
params.push(options.ref);
}
return gitCommand({ cwd: repoPath }, ...params);
}
static async ls_files(repoPath: string, fileName: string, sha?: string): Promise<string> {
static async ls_files(repoPath: string, fileName: string, options: { ref?: string } = {}): Promise<string> {
const params = [`ls-files`];
if (sha && !Git.isStagedUncommitted(sha)) {
params.push(`--with-tree=${sha}`);
if (options.ref && !Git.isStagedUncommitted(options.ref)) {
params.push(`--with-tree=${options.ref}`);
}
try {

+ 48
- 41
src/gitService.ts Voir le fichier

@ -407,13 +407,13 @@ export class GitService extends Disposable {
}
async findNextCommit(repoPath: string, fileName: string, sha?: string): Promise<GitLogCommit | undefined> {
let log = await this.getLogForFile(repoPath, fileName, sha, { maxCount: 1, reverse: true });
let log = await this.getLogForFile(repoPath, fileName, { maxCount: 1, ref: sha, 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, { maxCount: 1, reverse: true });
log = await this.getLogForFile(repoPath, nextFileName, { maxCount: 1, ref: sha, reverse: true });
commit = log && Iterables.first(log.commits.values());
}
@ -438,7 +438,7 @@ export class GitService extends Disposable {
}
// Get the full commit (so we can see if there are any matching renames in the file statuses)
const log = await this.getLogForRepo(repoPath, sha, 1);
const log = await this.getLogForRepo(repoPath, { maxCount: 1, ref: sha });
if (log === undefined) return undefined;
const c = Iterables.first(log.commits.values());
@ -846,7 +846,7 @@ export class GitService extends Disposable {
Logger.log(`getLogCommit('${repoPath}', '${fileName}', '${sha}', ${options.firstIfMissing}, ${options.previous})`);
const log = await this.getLogForFile(repoPath, fileName, sha, { maxCount: options.previous ? 2 : 1 });
const log = await this.getLogForFile(repoPath, fileName, { maxCount: options.previous ? 2 : 1, ref: sha });
if (log === undefined) return undefined;
const commit = sha && log.commits.get(sha);
@ -858,16 +858,18 @@ export class GitService extends Disposable {
return commit || Iterables.first(log.commits.values());
}
async getLogForRepo(repoPath: string, sha?: string, maxCount?: number, reverse: boolean = false): Promise<GitLog | undefined> {
Logger.log(`getLogForRepo('${repoPath}', '${sha}', ${maxCount}, ${reverse})`);
async getLogForRepo(repoPath: string, options: { maxCount?: number, ref?: string, reverse?: boolean } = {}): Promise<GitLog | undefined> {
options = { reverse: false, ...options };
if (maxCount == null) {
maxCount = this.config.advanced.maxQuickHistory || 0;
}
Logger.log(`getLogForRepo('${repoPath}', '${options.ref}', ${options.maxCount}, ${options.reverse})`);
const maxCount = options.maxCount == null
? this.config.advanced.maxQuickHistory || 0
: options.maxCount;
try {
const data = await Git.log(repoPath, sha, maxCount, reverse);
const log = GitLogParser.parse(data, GitCommitType.Branch, repoPath, undefined, sha, maxCount, reverse, undefined);
const data = await Git.log(repoPath, { maxCount: maxCount, ref: options.ref, reverse: options.reverse });
const log = GitLogParser.parse(data, GitCommitType.Branch, repoPath, undefined, options.ref, maxCount, options.reverse!, undefined);
return log;
}
catch (ex) {
@ -875,12 +877,12 @@ export class GitService extends Disposable {
}
}
async getLogForRepoSearch(repoPath: string, search: string, searchBy: GitRepoSearchBy, maxCount?: number): Promise<GitLog | undefined> {
Logger.log(`getLogForRepoSearch('${repoPath}', '${search}', '${searchBy}', ${maxCount})`);
async getLogForRepoSearch(repoPath: string, search: string, searchBy: GitRepoSearchBy, options: { maxCount?: number } = {}): Promise<GitLog | undefined> {
Logger.log(`getLogForRepoSearch('${repoPath}', '${search}', '${searchBy}', ${options.maxCount})`);
if (maxCount == null) {
maxCount = this.config.advanced.maxQuickHistory || 0;
}
let maxCount = options.maxCount == null
? this.config.advanced.maxQuickHistory || 0
: options.maxCount;
let searchArgs: string[] | undefined = undefined;
switch (searchBy) {
@ -906,7 +908,7 @@ export class GitService extends Disposable {
}
try {
const data = await Git.log_search(repoPath, searchArgs, maxCount);
const data = await Git.log_search(repoPath, searchArgs, { maxCount: maxCount });
const log = GitLogParser.parse(data, GitCommitType.Branch, repoPath, undefined, undefined, maxCount, false, undefined);
return log;
}
@ -915,12 +917,12 @@ export class GitService extends Disposable {
}
}
async getLogForFile(repoPath: string | undefined, fileName: string, sha?: string, options: { maxCount?: number, range?: Range, reverse?: boolean, skipMerges?: boolean } = {}): Promise<GitLog | undefined> {
options = { ...{ reverse: false, skipMerges: false }, ...options };
async getLogForFile(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, reverse?: boolean, skipMerges?: boolean } = {}): Promise<GitLog | undefined> {
options = { reverse: false, skipMerges: false, ...options };
let key = 'log';
if (sha !== undefined) {
key += `:${sha}`;
if (options.ref !== undefined) {
key += `:${options.ref}`;
}
if (options.maxCount !== undefined) {
key += `:n${options.maxCount}`;
@ -934,7 +936,7 @@ export class GitService extends Disposable {
if (entry !== undefined) {
const cachedLog = entry.get<CachedLog>(key);
if (cachedLog !== undefined) {
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${sha}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
return cachedLog.item;
}
@ -942,22 +944,22 @@ export class GitService extends Disposable {
// Since we are looking for partial log, see if we have the log of the whole file
const cachedLog = entry.get<CachedLog>('log');
if (cachedLog !== undefined) {
if (sha === undefined) {
if (options.ref === undefined) {
Logger.log(`getLogForFile[Cached(~${key})]('${repoPath}', '${fileName}', '', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
return cachedLog.item;
}
Logger.log(`getLogForFile[? Cache(${key})]('${repoPath}', '${fileName}', '${sha}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile[? Cache(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
const log = await cachedLog.item;
if (log !== undefined && log.commits.has(sha)) {
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${sha}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
if (log !== undefined && log.commits.has(options.ref)) {
Logger.log(`getLogForFile[Cached(${key})]('${repoPath}', '${fileName}', '${options.ref}', ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
return cachedLog.item;
}
}
}
}
Logger.log(`getLogForFile[Not Cached(${key})]('${repoPath}', '${fileName}', ${sha}, ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile[Not Cached(${key})]('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, undefined, ${options.reverse}, ${options.skipMerges})`);
if (entry === undefined) {
entry = new GitCacheEntry(cacheKey);
@ -965,10 +967,10 @@ export class GitService extends Disposable {
}
}
else {
Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${sha}, ${options.maxCount}, ${options.range && `[${options.range.start.line}, ${options.range.end.line}]`}, ${options.reverse}, ${options.skipMerges})`);
Logger.log(`getLogForFile('${repoPath}', '${fileName}', ${options.ref}, ${options.maxCount}, ${options.range && `[${options.range.start.line}, ${options.range.end.line}]`}, ${options.reverse}, ${options.skipMerges})`);
}
const promise = this.getLogForFileCore(repoPath, fileName, sha, options, entry, key);
const promise = this.getLogForFileCore(repoPath, fileName, options, entry, key);
if (entry) {
Logger.log(`Add log cache for '${entry.key}:${key}'`);
@ -981,8 +983,8 @@ export class GitService extends Disposable {
return promise;
}
private async getLogForFileCore(repoPath: string | undefined, fileName: string, sha: string | undefined, options: { maxCount?: number, range?: Range, reverse?: boolean, skipMerges?: boolean }, entry: GitCacheEntry | undefined, key: string): Promise<GitLog | undefined> {
if (!(await this.isTracked(fileName, repoPath, sha))) {
private async getLogForFileCore(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, reverse?: boolean, skipMerges?: boolean }, entry: GitCacheEntry | undefined, key: string): Promise<GitLog | undefined> {
if (!(await this.isTracked(fileName, repoPath, options.ref))) {
Logger.log(`Skipping log; '${fileName}' is not tracked`);
return await GitService.emptyPromise as GitLog;
}
@ -991,8 +993,13 @@ export class GitService extends Disposable {
try {
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, GitCommitType.File, root, file, sha, options.maxCount, options.reverse!, range);
const maxCount = options.maxCount == null
? this.config.advanced.maxQuickHistory || 0
: options.maxCount;
const data = await Git.log_file(root, file, { ...opts, maxCount: maxCount, startLine: range && range.start.line + 1, endLine: range && range.end.line + 1 });
const log = GitLogParser.parse(data, GitCommitType.File, root, file, opts.ref, maxCount, opts.reverse!, range);
return log;
}
catch (ex) {
@ -1188,7 +1195,7 @@ export class GitService extends Disposable {
return status;
}
async getVersionedFile(repoPath: string | undefined, fileName: string, sha?: string) {
async getVersionedFile(repoPath: string | undefined, fileName: string, sha: string | undefined) {
Logger.log(`getVersionedFile('${repoPath}', '${fileName}', '${sha}')`);
if (!sha || (Git.isUncommitted(sha) && !Git.isStagedUncommitted(sha))) {
@ -1285,10 +1292,10 @@ export class GitService extends Disposable {
// Even if we have a sha, check first to see if the file exists (that way the cache will be better reused)
let tracked = !!await Git.ls_files(repoPath === undefined ? '' : repoPath, fileName);
if (!tracked && sha !== undefined) {
tracked = !!await Git.ls_files(repoPath === undefined ? '' : repoPath, fileName, sha);
tracked = !!await Git.ls_files(repoPath === undefined ? '' : repoPath, fileName, { ref: sha });
// If we still haven't found this file, make sure it wasn't deleted in that sha (i.e. check the previous)
if (!tracked) {
tracked = !!await Git.ls_files(repoPath === undefined ? '' : repoPath, fileName, `${sha}^`);
tracked = !!await Git.ls_files(repoPath === undefined ? '' : repoPath, fileName, { ref: `${sha}^` });
}
}
return tracked;
@ -1325,14 +1332,14 @@ export class GitService extends Disposable {
return Git.difftool_dirDiff(repoPath, tool, sha1, sha2);
}
async resolveReference(repoPath: string, sha: string, uri?: Uri) {
if (!GitService.isResolveRequired(sha)) return sha;
async resolveReference(repoPath: string, ref: string, uri?: Uri) {
if (!GitService.isResolveRequired(ref)) return ref;
Logger.log(`resolveReference('${repoPath}', '${sha}', '${uri && uri.toString()}')`);
Logger.log(`resolveReference('${repoPath}', '${ref}', '${uri && uri.toString()}')`);
if (uri === undefined) return (await Git.revparse(repoPath, sha)) || sha;
if (uri === undefined) return (await Git.revparse(repoPath, ref)) || ref;
return (await Git.log_resolve(repoPath, sha, Git.normalizePath(path.relative(repoPath, uri.fsPath)))) || sha;
return (await Git.log_resolve(repoPath, Git.normalizePath(path.relative(repoPath, uri.fsPath)), ref)) || ref;
}
stopWatchingFileSystem() {

+ 2
- 2
src/quickPicks/commitDetails.ts Voir le fichier

@ -236,7 +236,7 @@ export class CommitDetailsQuickPick {
// 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.getLogForRepo(commit.repoPath, commit.sha, git.config.advanced.maxQuickHistory);
log = await git.getLogForRepo(commit.repoPath, { maxCount: git.config.advanced.maxQuickHistory, ref: commit.sha });
c = log && log.commits.get(commit.sha);
if (c) {
@ -267,7 +267,7 @@ export class CommitDetailsQuickPick {
c = undefined;
// Try to find the next commit
const nextLog = await git.getLogForRepo(commit.repoPath, commit.sha, 1, true);
const nextLog = await git.getLogForRepo(commit.repoPath, { maxCount: 1, reverse: true, ref: commit.sha });
const next = nextLog && Iterables.first(nextLog.commits.values());
if (next !== undefined && next.sha !== commit.sha) {
c = commit;

+ 1
- 1
src/quickPicks/commitFileDetails.ts Voir le fichier

@ -219,7 +219,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, { maxCount: git.config.advanced.maxQuickHistory });
log = await git.getLogForFile(commit.repoPath, uri.fsPath, { maxCount: git.config.advanced.maxQuickHistory, ref: commit.sha });
if (log === undefined) return KeyNoopCommand;
c = log && log.commits.get(commit.sha);

+ 1
- 1
src/views/branchNode.ts Voir le fichier

@ -23,7 +23,7 @@ export class BranchNode extends ExplorerRefNode {
}
async getChildren(): Promise<ExplorerNode[]> {
const log = await this.explorer.git.getLogForRepo(this.uri.repoPath!, this.branch.name, this.maxCount);
const log = await this.explorer.git.getLogForRepo(this.uri.repoPath!, { maxCount: this.maxCount, ref: this.branch.name });
if (log === undefined) return [new MessageNode('No commits yet')];
const children: (CommitNode | ShowAllNode)[] = [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.explorer, this.branch))];

+ 1
- 1
src/views/commitFileNode.ts Voir le fichier

@ -41,7 +41,7 @@ export class CommitFileNode extends ExplorerNode {
// See if we can get the commit directly from the multi-file commit
const commit = this.commit.toFileCommit(this.status);
if (commit === undefined) {
const log = await this.explorer.git.getLogForFile(this.repoPath, this.status.fileName, this.commit.sha, { maxCount: 2 });
const log = await this.explorer.git.getLogForFile(this.repoPath, this.status.fileName, { maxCount: 2, ref: this.commit.sha });
if (log !== undefined) {
this.commit = log.commits.get(this.commit.sha) || this.commit;
}

+ 1
- 1
src/views/commitNode.ts Voir le fichier

@ -26,7 +26,7 @@ export class CommitNode extends ExplorerRefNode {
async getChildren(): Promise<ExplorerNode[]> {
const repoPath = this.repoPath;
const log = await this.explorer.git.getLogForRepo(repoPath, this.commit.sha, 1);
const log = await this.explorer.git.getLogForRepo(repoPath, { maxCount: 1, ref: this.commit.sha });
if (log === undefined) return [];
const commit = Iterables.first(log.commits.values());

+ 1
- 1
src/views/comparisionResultsNode.ts Voir le fichier

@ -21,7 +21,7 @@ export class ComparisionResultsNode extends ExplorerNode {
async getChildren(): Promise<ExplorerNode[]> {
this.resetChildren();
const commitsQueryFn = (maxCount: number | undefined) => this.explorer.git.getLogForRepo(this.uri.repoPath!, `${this.ref1}...${this.ref2}`, maxCount);
const commitsQueryFn = (maxCount: number | undefined) => this.explorer.git.getLogForRepo(this.uri.repoPath!, { maxCount: maxCount, ref: `${this.ref1}...${this.ref2}` });
const commitsLabelFn = (log: GitLog | undefined) => {
const count = log !== undefined ? log.count : 0;
const truncated = log !== undefined ? log.truncated : false;

+ 1
- 1
src/views/fileHistoryNode.ts Voir le fichier

@ -59,7 +59,7 @@ export class FileHistoryNode extends ExplorerNode {
children.push(new CommitFileNode(status, commit, this.explorer, displayAs));
}
const log = await this.explorer.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, this.uri.sha);
const log = await this.explorer.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, { ref: this.uri.sha });
if (log !== undefined) {
children.push(...Iterables.map(log.commits.values(), c => new CommitFileNode(c.fileStatuses[0], c, this.explorer, displayAs)));
}

+ 1
- 1
src/views/stashNode.ts Voir le fichier

@ -22,7 +22,7 @@ export class StashNode extends ExplorerRefNode {
const statuses = (this.commit as GitStashCommit).fileStatuses;
// Check for any untracked files -- since git doesn't return them via `git stash list` :(
const log = await this.explorer.git.getLogForRepo(this.commit.repoPath, `${(this.commit as GitStashCommit).stashName}^3`, 1);
const log = await this.explorer.git.getLogForRepo(this.commit.repoPath, { maxCount: 1, ref: `${(this.commit as GitStashCommit).stashName}^3` });
if (log !== undefined) {
const commit = Iterables.first(log.commits.values());
if (commit !== undefined && commit.fileStatuses.length !== 0) {

+ 1
- 1
src/views/statusFilesNode.ts Voir le fichier

@ -31,7 +31,7 @@ export class StatusFilesNode extends ExplorerNode {
let log: GitLog | undefined;
if (this.range !== undefined) {
log = await this.explorer.git.getLogForRepo(repoPath, this.range, this.maxCount);
log = await this.explorer.git.getLogForRepo(repoPath, { maxCount: this.maxCount, ref: this.range });
if (log !== undefined) {
statuses = Array.from(Iterables.flatMap(log.commits.values(), c => {
return c.fileStatuses.map(s => {

+ 2
- 2
src/views/statusUpstreamNode.ts Voir le fichier

@ -20,7 +20,7 @@ export class StatusUpstreamNode extends ExplorerNode {
? `${this.status.upstream}..${this.status.branch}`
: `${this.status.branch}..${this.status.upstream}`;
let log = await this.explorer.git.getLogForRepo(this.uri.repoPath!, range, 0);
let log = await this.explorer.git.getLogForRepo(this.uri.repoPath!, { maxCount: 0, ref: range });
if (log === undefined) return [];
if (this.direction !== 'ahead') return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.explorer))];
@ -29,7 +29,7 @@ export class StatusUpstreamNode extends ExplorerNode {
const commits = Array.from(log.commits.values());
const commit = commits[commits.length - 1];
if (commit.previousSha === undefined) {
log = await this.explorer.git.getLogForRepo(this.uri.repoPath!, commit.sha, 2);
log = await this.explorer.git.getLogForRepo(this.uri.repoPath!, { maxCount: 2, ref: commit.sha });
if (log !== undefined) {
commits[commits.length - 1] = Iterables.first(log.commits.values());
}

Chargement…
Annuler
Enregistrer