Ver código fonte

Adds onDid[Open|Close]Repository provider events

Ensures known SCM repos are known to GitLens
main
Eric Amodio 2 anos atrás
pai
commit
18ff67751f
3 arquivos alterados com 62 adições e 30 exclusões
  1. +36
    -29
      src/env/node/git/localGitProvider.ts
  2. +11
    -1
      src/git/gitProvider.ts
  3. +15
    -0
      src/git/gitProviderService.ts

+ 36
- 29
src/env/node/git/localGitProvider.ts Ver arquivo

@ -32,7 +32,9 @@ import {
GitProviderDescriptor,
GitProviderId,
PagedResult,
RepositoryCloseEvent,
RepositoryInitWatcher,
RepositoryOpenEvent,
ScmRepository,
} from '../../../git/gitProvider';
import { GitProviderService } from '../../../git/gitProviderService';
@ -136,6 +138,16 @@ export class LocalGitProvider implements GitProvider, Disposable {
return this._onDidChangeRepository.event;
}
private _onDidCloseRepository = new EventEmitter<RepositoryCloseEvent>();
get onDidCloseRepository(): Event<RepositoryCloseEvent> {
return this._onDidCloseRepository.event;
}
private _onDidOpenRepository = new EventEmitter<RepositoryOpenEvent>();
get onDidOpenRepository(): Event<RepositoryOpenEvent> {
return this._onDidOpenRepository.event;
}
private readonly _branchesCache = new Map<string, Promise<PagedResult<GitBranch>>>();
private readonly _contributorsCache = new Map<string, Promise<GitContributor[]>>();
private readonly _mergeStatusCache = new Map<string, GitMergeStatus | null>();
@ -146,11 +158,15 @@ export class LocalGitProvider implements GitProvider, Disposable {
private readonly _trackedPaths = new PathTrie<PromiseOrValue<[string, string] | undefined>>();
private readonly _userMapCache = new Map<string, GitUser | null>();
private _disposables: Disposable[] = [];
constructor(private readonly container: Container) {
Git.setLocator(this.ensureGit.bind(this));
}
dispose() {}
dispose() {
Disposable.from(...this._disposables).dispose();
}
private get useCaching() {
return this.container.config.advanced.caching.enabled;
@ -214,31 +230,22 @@ export class LocalGitProvider implements GitProvider, Disposable {
throw new UnableToFindGitError();
}
const scmPromise = this.getScmGitApi();
const scmGitPromise = this.getScmGitApi();
async function subscribeToScmOpenCloseRepository(
container: Container,
apiPromise: Promise<BuiltInGitApi | undefined>,
) {
const gitApi = await apiPromise;
if (gitApi == null) return;
async function subscribeToScmOpenCloseRepository(this: LocalGitProvider) {
const scmGit = await scmGitPromise;
if (scmGit == null) return;
container.context.subscriptions.push(
gitApi.onDidCloseRepository(e => {
const repository = container.git.getCachedRepository(normalizePath(e.rootUri.fsPath));
if (repository != null) {
repository.closed = true;
}
}),
gitApi.onDidOpenRepository(e => {
const repository = container.git.getCachedRepository(normalizePath(e.rootUri.fsPath));
if (repository != null) {
repository.closed = false;
}
}),
this._disposables.push(
scmGit.onDidCloseRepository(e => this._onDidCloseRepository.fire({ uri: e.rootUri })),
scmGit.onDidOpenRepository(e => this._onDidOpenRepository.fire({ uri: e.rootUri })),
);
for (const scmRepository of scmGit.repositories) {
this._onDidOpenRepository.fire({ uri: scmRepository.rootUri });
}
}
void subscribeToScmOpenCloseRepository(this.container, scmPromise);
void subscribeToScmOpenCloseRepository.call(this);
const potentialGitPaths =
configuration.getAny<string | string[]>('git.path') ??
@ -248,7 +255,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const findGitPromise = findGitPath(potentialGitPaths);
// Try to use the same git as the built-in vscode git extension, but don't wait for it if we find something faster
const findGitFromSCMPromise = scmPromise.then(gitApi => {
const findGitFromSCMPromise = scmGitPromise.then(gitApi => {
const path = gitApi?.git.path;
if (!path) return findGitPromise;
@ -294,15 +301,15 @@ export class LocalGitProvider implements GitProvider, Disposable {
async discoverRepositories(uri: Uri): Promise<Repository[]> {
if (uri.scheme !== DocumentSchemes.File) return [];
const autoRepositoryDetection =
configuration.getAny<boolean | 'subFolders' | 'openEditors'>(
BuiltInGitConfiguration.AutoRepositoryDetection,
) ?? true;
if (autoRepositoryDetection === false || autoRepositoryDetection === 'openEditors') return [];
try {
void (await this.ensureGit());
const autoRepositoryDetection =
configuration.getAny<boolean | 'subFolders' | 'openEditors'>(
BuiltInGitConfiguration.AutoRepositoryDetection,
) ?? true;
if (autoRepositoryDetection === false || autoRepositoryDetection === 'openEditors') return [];
const repositories = await this.repositorySearch(workspace.getWorkspaceFolder(uri)!);
if (autoRepositoryDetection === true || autoRepositoryDetection === 'subFolders') {
for (const repository of repositories) {

+ 11
- 1
src/git/gitProvider.ts Ver arquivo

@ -64,8 +64,18 @@ export interface PagedResult {
readonly values: NonNullable<T>[];
}
export interface GitProvider {
export interface RepositoryCloseEvent {
readonly uri: Uri;
}
export interface RepositoryOpenEvent {
readonly uri: Uri;
}
export interface GitProvider extends Disposable {
get onDidChangeRepository(): Event<RepositoryChangeEvent>;
get onDidCloseRepository(): Event<RepositoryCloseEvent>;
get onDidOpenRepository(): Event<RepositoryOpenEvent>;
readonly descriptor: GitProviderDescriptor;
readonly supportedSchemes: string[];

+ 15
- 0
src/git/gitProviderService.ts Ver arquivo

@ -308,6 +308,7 @@ export class GitProviderService implements Disposable {
}
const disposable = Disposable.from(
provider,
...disposables,
provider.onDidChangeRepository(e => {
if (e.changed(RepositoryChange.Closed, RepositoryChangeComparisonMode.Any)) {
@ -319,6 +320,20 @@ export class GitProviderService implements Disposable {
this._onDidChangeRepository.fire(e);
}),
provider.onDidCloseRepository(e => {
const repository = this._repositories.get(e.uri);
if (repository != null) {
repository.closed = true;
}
}),
provider.onDidOpenRepository(e => {
const repository = this._repositories.get(e.uri);
if (repository != null) {
repository.closed = false;
} else {
void this.getOrCreateRepository(e.uri);
}
}),
);
this.fireProvidersChanged([provider]);

Carregando…
Cancelar
Salvar