mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-17 17:25:51 -05:00
Reduces git calls on known untrackables
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user