Browse Source

Renames getLogCommit to getLogCommitForFile

Adds new getLogCommit
Adds getRecentLogCommitForFile
Renames getLogForRepo to getLog
Renames getLogForRepoSearch to getLogForSearch
main
Eric Amodio 7 years ago
parent
commit
ab9d0eb7b4
20 changed files with 50 additions and 47 deletions
  1. +1
    -1
      src/annotations/blameAnnotationProvider.ts
  2. +1
    -1
      src/annotations/recentChangesAnnotationProvider.ts
  3. +2
    -2
      src/commands/copyMessageToClipboard.ts
  4. +1
    -1
      src/commands/copyShaToClipboard.ts
  5. +1
    -1
      src/commands/diffWithWorking.ts
  6. +1
    -1
      src/commands/showCommitSearch.ts
  7. +1
    -1
      src/commands/showQuickBranchHistory.ts
  8. +1
    -1
      src/commands/showQuickCommitDetails.ts
  9. +1
    -1
      src/commands/showQuickCommitFileDetails.ts
  10. +1
    -1
      src/currentLineController.ts
  11. +1
    -1
      src/gitRevisionCodeLensProvider.ts
  12. +28
    -25
      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/comparisionResultsNode.ts
  17. +1
    -1
      src/views/stashNode.ts
  18. +1
    -1
      src/views/statusFilesNode.ts
  19. +2
    -2
      src/views/statusUpstreamNode.ts
  20. +1
    -1
      src/views/tagNode.ts

+ 1
- 1
src/annotations/blameAnnotationProvider.ts View File

@ -114,7 +114,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.getLogCommit(commit.repoPath, commit.uri.fsPath, commit.sha);
logCommit = await Container.git.getLogCommitForFile(commit.repoPath, commit.uri.fsPath, { ref: commit.sha });
if (logCommit !== undefined) {
// Preserve the previous commit from the blame commit
logCommit.previousFileName = commit.previousFileName;

+ 1
- 1
src/annotations/recentChangesAnnotationProvider.ts View File

@ -25,7 +25,7 @@ export class RecentChangesAnnotationProvider extends AnnotationProviderBase {
async onProvideAnnotation(shaOrLine?: string | number): Promise<boolean> {
this.annotationType = FileAnnotationType.RecentChanges;
const commit = await Container.git.getLogCommit(this._uri.repoPath, this._uri.fsPath, { previous: true });
const commit = await Container.git.getRecentLogCommitForFile(this._uri.repoPath, this._uri.fsPath);
if (commit === undefined) return false;
const diff = await Container.git.getDiffForFile(this._uri, commit.previousSha);

+ 2
- 2
src/commands/copyMessageToClipboard.ts View File

@ -39,7 +39,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
const repoPath = await Container.git.getActiveRepoPath(editor);
if (!repoPath) return undefined;
const log = await Container.git.getLogForRepo(repoPath, { maxCount: 1 });
const log = await Container.git.getLog(repoPath, { maxCount: 1 });
if (!log) return undefined;
args.message = Iterables.first(log.commits.values()).message;
@ -74,7 +74,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, gitUri.fsPath, args.sha);
const commit = await Container.git.getLogCommit(gitUri.repoPath!, args.sha);
if (commit === undefined) return undefined;
args.message = commit.message;

+ 1
- 1
src/commands/copyShaToClipboard.ts View File

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

+ 1
- 1
src/commands/diffWithWorking.ts View File

@ -60,7 +60,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
}
try {
args.commit = await Container.git.getLogCommit(gitUri.repoPath, gitUri.fsPath, gitUri.sha, { firstIfMissing: true });
args.commit = await Container.git.getLogCommitForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha, firstIfNotFound: true });
if (args.commit === undefined) return Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare');
}
catch (ex) {

+ 1
- 1
src/commands/showCommitSearch.ts View File

@ -114,7 +114,7 @@ export class ShowCommitSearchCommand extends ActiveEditorCachedCommand {
const progressCancellation = CommitsQuickPick.showProgress(searchLabel!);
try {
const log = await Container.git.getLogForRepoSearch(repoPath, args.search, args.searchBy, { maxCount: args.maxCount });
const log = await Container.git.getLogForSearch(repoPath, args.search, args.searchBy, { maxCount: args.maxCount });
if (progressCancellation.token.isCancellationRequested) return undefined;

+ 1
- 1
src/commands/showQuickBranchHistory.ts View File

@ -52,7 +52,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand {
}
if (args.log === undefined) {
args.log = await Container.git.getLogForRepo(repoPath, { maxCount: args.maxCount, ref: (gitUri && gitUri.sha) || args.branch });
args.log = await Container.git.getLog(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 View File

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

+ 1
- 1
src/commands/showQuickCommitFileDetails.ts View File

@ -94,7 +94,7 @@ export class ShowQuickCommitFileDetailsCommand extends ActiveEditorCachedCommand
}
if (args.fileLog === undefined) {
args.commit = await Container.git.getLogCommit(args.commit === undefined ? gitUri.repoPath : args.commit.repoPath, gitUri.fsPath, args.sha, { previous: true });
args.commit = await Container.git.getLogCommitForFile(args.commit === undefined ? gitUri.repoPath : args.commit.repoPath, gitUri.fsPath, { ref: args.sha });
if (args.commit === undefined) return Messages.showCommitNotFoundWarningMessage(`Unable to show commit file details`);
}
}

+ 1
- 1
src/currentLineController.ts View File

@ -257,7 +257,7 @@ export class CurrentLineController extends Disposable {
// Get the full commit message -- since blame only returns the summary
let logCommit = this._lineTracker.state !== undefined ? this._lineTracker.state.logCommit : undefined;
if (logCommit === undefined && !commit.isUncommitted) {
logCommit = await Container.git.getLogCommit(commit.repoPath, commit.uri.fsPath, commit.sha);
logCommit = await Container.git.getLogCommitForFile(commit.repoPath, commit.uri.fsPath, { ref: commit.sha });
if (logCommit !== undefined) {
// Preserve the previous commit from the blame commit
logCommit.previousSha = commit.previousSha;

+ 1
- 1
src/gitRevisionCodeLensProvider.ts View File

@ -36,7 +36,7 @@ export class GitRevisionCodeLensProvider implements CodeLensProvider {
const lenses: CodeLens[] = [];
const commit = await Container.git.getLogCommit(gitUri.repoPath, gitUri.fsPath, gitUri.sha, { firstIfMissing: true, previous: true });
const commit = await Container.git.getLogCommitForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha, firstIfNotFound: true });
if (commit === undefined) return lenses;
if (commit.previousSha) {

+ 28
- 25
src/gitService.ts View File

@ -337,14 +337,14 @@ export class GitService extends Disposable {
private async findNextFileNameCore(repoPath: string, fileName: string, sha?: string): Promise<string | undefined> {
if (sha === undefined) {
// Get the most recent commit for this file name
const c = await this.getLogCommit(repoPath, fileName);
const c = await this.getRecentLogCommitForFile(repoPath, fileName);
if (c === undefined) return undefined;
sha = c.sha;
}
// Get the full commit (so we can see if there are any matching renames in the file statuses)
const log = await this.getLogForRepo(repoPath, { maxCount: 1, ref: sha });
const log = await this.getLog(repoPath, { maxCount: 1, ref: sha });
if (log === undefined) return undefined;
const c = Iterables.first(log.commits.values());
@ -819,37 +819,38 @@ export class GitService extends Disposable {
}
}
async getLogCommit(repoPath: string | undefined, fileName: string, options?: { firstIfMissing?: boolean, previous?: boolean }): Promise<GitLogCommit | undefined>;
async getLogCommit(repoPath: string | undefined, fileName: string, sha: string | undefined, options?: { firstIfMissing?: boolean, previous?: boolean }): Promise<GitLogCommit | undefined>;
async getLogCommit(repoPath: string | undefined, fileName: string, shaOrOptions?: string | undefined | { firstIfMissing?: boolean, previous?: boolean }, options?: { firstIfMissing?: boolean, previous?: boolean }): Promise<GitLogCommit | undefined> {
let sha: string | undefined = undefined;
if (typeof shaOrOptions === 'string') {
sha = shaOrOptions;
}
else if (options === undefined) {
options = shaOrOptions;
}
async getRecentLogCommitForFile(repoPath: string | undefined, fileName: string): Promise<GitLogCommit | undefined> {
return this.getLogCommitForFile(repoPath, fileName, undefined);
}
async getLogCommit(repoPath: string, ref: string): Promise<GitLogCommit | undefined> {
Logger.log(`getLogCommit('${repoPath}', '${ref}'`);
options = options || {};
const log = await this.getLog(repoPath, { maxCount: 2, ref: ref });
if (log === undefined) return undefined;
return log.commits.get(ref);
}
Logger.log(`getLogCommit('${repoPath}', '${fileName}', '${sha}', ${options.firstIfMissing}, ${options.previous})`);
async getLogCommitForFile(repoPath: string | undefined, fileName: string, options: { ref?: string, firstIfNotFound?: boolean } = {}): Promise<GitLogCommit | undefined> {
Logger.log(`getFileLogCommit('${repoPath}', '${fileName}', '${options.ref}', ${options.firstIfNotFound})`);
const log = await this.getLogForFile(repoPath, fileName, { maxCount: options.previous ? 2 : 1, ref: sha });
const log = await this.getLogForFile(repoPath, fileName, { maxCount: 2, ref: options.ref });
if (log === undefined) return undefined;
const commit = sha && log.commits.get(sha);
if (commit === undefined && sha && !options.firstIfMissing) {
// If the sha isn't resolved we will never find it, so don't kick out
if (!Git.isResolveRequired(sha)) return undefined;
const commit = options.ref && log.commits.get(options.ref);
if (commit === undefined && !options.firstIfNotFound && options.ref) {
// If the sha isn't resolved we will never find it, so let it fall through so we return the first
if (!Git.isResolveRequired(options.ref)) return undefined;
}
return commit || Iterables.first(log.commits.values());
}
async getLogForRepo(repoPath: string, options: { maxCount?: number, ref?: string, reverse?: boolean } = {}): Promise<GitLog | undefined> {
async getLog(repoPath: string, options: { maxCount?: number, ref?: string, reverse?: boolean } = {}): Promise<GitLog | undefined> {
options = { reverse: false, ...options };
Logger.log(`getLogForRepo('${repoPath}', '${options.ref}', ${options.maxCount}, ${options.reverse})`);
Logger.log(`getLog('${repoPath}', '${options.ref}', ${options.maxCount}, ${options.reverse})`);
const maxCount = options.maxCount == null
? Container.config.advanced.maxListItems || 0
@ -861,7 +862,7 @@ export class GitService extends Disposable {
if (log !== undefined) {
const opts = { ...options };
log.query = (maxCount: number | undefined) => this.getLogForRepo(repoPath, { ...opts, maxCount: maxCount });
log.query = (maxCount: number | undefined) => this.getLog(repoPath, { ...opts, maxCount: maxCount });
}
return log;
@ -871,8 +872,8 @@ export class GitService extends Disposable {
}
}
async getLogForRepoSearch(repoPath: string, search: string, searchBy: GitRepoSearchBy, options: { maxCount?: number } = {}): Promise<GitLog | undefined> {
Logger.log(`getLogForRepoSearch('${repoPath}', '${search}', '${searchBy}', ${options.maxCount})`);
async getLogForSearch(repoPath: string, search: string, searchBy: GitRepoSearchBy, options: { maxCount?: number } = {}): Promise<GitLog | undefined> {
Logger.log(`getLogForSearch('${repoPath}', '${search}', '${searchBy}', ${options.maxCount})`);
let maxCount = options.maxCount == null
? Container.config.advanced.maxListItems || 0
@ -907,7 +908,7 @@ export class GitService extends Disposable {
if (log !== undefined) {
const opts = { ...options };
log.query = (maxCount: number | undefined) => this.getLogForRepoSearch(repoPath, search, searchBy, { ...opts, maxCount: maxCount });
log.query = (maxCount: number | undefined) => this.getLogForSearch(repoPath, search, searchBy, { ...opts, maxCount: maxCount });
}
return log;
@ -918,6 +919,8 @@ export class GitService extends Disposable {
}
async getLogForFile(repoPath: string | undefined, fileName: string, options: { maxCount?: number, range?: Range, ref?: string, reverse?: boolean, skipMerges?: boolean } = {}): Promise<GitLog | undefined> {
if (repoPath !== undefined && repoPath === Strings.normalizePath(fileName)) throw new Error(`File name cannot match the repository path; fileName=${fileName}`);
options = { reverse: false, skipMerges: false, ...options };
let key = 'log';

+ 2
- 2
src/quickPicks/commitDetails.ts View File

@ -241,7 +241,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 Container.git.getLogForRepo(commit.repoPath, { maxCount: Container.config.advanced.maxListItems, ref: commit.sha });
log = await Container.git.getLog(commit.repoPath, { maxCount: Container.config.advanced.maxListItems, ref: commit.sha });
c = log && log.commits.get(commit.sha);
if (c) {
@ -272,7 +272,7 @@ export class CommitDetailsQuickPick {
c = undefined;
// Try to find the next commit
const nextLog = await Container.git.getLogForRepo(commit.repoPath, { maxCount: 1, reverse: true, ref: commit.sha });
const nextLog = await Container.git.getLog(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 View File

@ -77,7 +77,7 @@ export class CommitFileDetailsQuickPick {
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.getLogCommit(undefined, commit.uri.fsPath, { previous: true });
const c = await Container.git.getRecentLogCommitForFile(undefined, commit.uri.fsPath);
if (c === undefined) return undefined;
commit = c;

+ 1
- 1
src/views/branchNode.ts View File

@ -24,7 +24,7 @@ export class BranchNode extends ExplorerRefNode {
}
async getChildren(): Promise<ExplorerNode[]> {
const log = await Container.git.getLogForRepo(this.uri.repoPath!, { maxCount: this.maxCount, ref: this.branch.name });
const log = await Container.git.getLog(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/comparisionResultsNode.ts View File

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

+ 1
- 1
src/views/stashNode.ts View File

@ -23,7 +23,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 Container.git.getLogForRepo(this.commit.repoPath, { maxCount: 1, ref: `${(this.commit as GitStashCommit).stashName}^3` });
const log = await Container.git.getLog(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 View File

@ -31,7 +31,7 @@ export class StatusFilesNode extends ExplorerNode {
let log: GitLog | undefined;
if (this.range !== undefined) {
log = await Container.git.getLogForRepo(repoPath, { maxCount: this.maxCount, ref: this.range });
log = await Container.git.getLog(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 View File

@ -21,7 +21,7 @@ export class StatusUpstreamNode extends ExplorerNode {
? `${this.status.upstream}..${this.status.branch}`
: `${this.status.branch}..${this.status.upstream}`;
let log = await Container.git.getLogForRepo(this.uri.repoPath!, { maxCount: 0, ref: range });
let log = await Container.git.getLog(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))];
@ -30,7 +30,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 Container.git.getLogForRepo(this.uri.repoPath!, { maxCount: 2, ref: commit.sha });
log = await Container.git.getLog(this.uri.repoPath!, { maxCount: 2, ref: commit.sha });
if (log !== undefined) {
commits[commits.length - 1] = Iterables.first(log.commits.values());
}

+ 1
- 1
src/views/tagNode.ts View File

@ -23,7 +23,7 @@ export class TagNode extends ExplorerRefNode {
}
async getChildren(): Promise<ExplorerNode[]> {
const log = await Container.git.getLogForRepo(this.uri.repoPath!, { maxCount: this.maxCount, ref: this.tag.name });
const log = await Container.git.getLog(this.uri.repoPath!, { maxCount: this.maxCount, ref: this.tag.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))];

Loading…
Cancel
Save