Browse Source

Reduces git calls on known untrackables

main
Eric Amodio 7 years ago
parent
commit
ce5ff1eb47
3 changed files with 18 additions and 11 deletions
  1. +1
    -1
      src/git/gitContextTracker.ts
  2. +4
    -2
      src/git/gitUri.ts
  3. +13
    -8
      src/gitService.ts

+ 1
- 1
src/git/gitContextTracker.ts View File

@ -114,7 +114,7 @@ export class GitContextTracker extends Disposable {
private async _updateContextHasRemotes(uri: GitUri | undefined) {
try {
let hasRemotes = false;
if (uri) {
if (uri && this.git.isTrackable(uri)) {
const repoPath = uri.repoPath || this.git.repoPath;
if (repoPath) {
const remotes = await this.git.getRemotes(repoPath);

+ 4
- 2
src/git/gitUri.ts View File

@ -72,17 +72,19 @@ export class GitUri extends Uri {
}
getRelativePath(): string {
return GitService.normalizePath(path.relative(this.repoPath || '', this.fsPath));
return GitService.normalizePath(path.relative(this.repoPath || '', this.fsPath));
}
static async fromUri(uri: Uri, git: GitService) {
if (uri instanceof GitUri) return uri;
if (!git.isTrackable(uri)) return new GitUri(uri, git.repoPath);
const gitUri = git.getGitUriForFile(uri.fsPath);
if (gitUri) return gitUri;
// If this is a git uri, assume it is showing the most recent commit
if (uri.scheme === 'git' && uri.query === '~') {
if (uri.scheme === DocumentSchemes.Git && uri.query === '~') {
const commit = await git.getLogCommit(undefined, uri.fsPath);
if (commit) return new GitUri(uri, commit);
}

+ 13
- 8
src/gitService.ts View File

@ -306,7 +306,7 @@ export class GitService extends Disposable {
const cacheKey = this.getCacheEntryKey(uri.fsPath);
const entry = this._gitCache.get(cacheKey);
if (!entry) return await this.isTracked(uri);
if (entry === undefined) return await this.isTracked(uri);
return !entry.hasErrors;
}
@ -691,8 +691,8 @@ export class GitService extends Disposable {
}
async getRemotes(repoPath: string): Promise<GitRemote[]> {
if (!this.config.insiders) return Promise.resolve([]);
if (!repoPath) return Promise.resolve([]);
if (!this.config.insiders) return [];
if (!repoPath) return [];
Logger.log(`getRemotes('${repoPath}')`);
@ -790,10 +790,7 @@ export class GitService extends Disposable {
}
isEditorBlameable(editor: TextEditor): boolean {
return (editor.viewColumn !== undefined ||
editor.document.uri.scheme === DocumentSchemes.File ||
editor.document.uri.scheme === DocumentSchemes.Git ||
this.hasGitUriForFile(editor));
return (editor.viewColumn !== undefined || this.isTrackable(editor.document.uri) || this.hasGitUriForFile(editor));
}
async isFileUncommitted(uri: GitUri): Promise<boolean> {
@ -803,8 +800,16 @@ export class GitService extends Disposable {
return !!status;
}
isTrackable(uri: Uri): boolean {
// Logger.log(`isTrackable('${uri.scheme}', '${uri.fsPath}')`);
return uri.scheme === DocumentSchemes.File || uri.scheme === DocumentSchemes.Git || uri.scheme === DocumentSchemes.GitLensGit;
}
async isTracked(uri: GitUri): Promise<boolean> {
Logger.log(`isFileUncommitted('${uri.repoPath}', '${uri.fsPath}')`);
if (!this.isTrackable(uri)) return false;
Logger.log(`isTracked('${uri.fsPath}', '${uri.repoPath}')`);
const result = await Git.ls_files(uri.repoPath === undefined ? '' : uri.repoPath, uri.fsPath);
return !!result;

Loading…
Cancel
Save