Browse Source

Fixes issue with repo event while suspended 🤞

main
Eric Amodio 4 years ago
parent
commit
a54a179f9a
3 changed files with 41 additions and 20 deletions
  1. +3
    -6
      src/git/gitService.ts
  2. +36
    -13
      src/git/models/repository.ts
  3. +2
    -1
      src/vsls/guest.ts

+ 3
- 6
src/git/gitService.ts View File

@ -126,7 +126,6 @@ export class GitService implements Disposable {
private readonly _disposable: Disposable;
private readonly _repositoryTree: TernarySearchTree<Repository>;
private _repositoriesLoadingPromise: Promise<void> | undefined;
private _suspended: boolean = false;
private readonly _branchesCache = new Map<string, GitBranch[]>();
private readonly _remotesWithApiProviderCache = new Map<string, GitRemote<RemoteProviderWithApi> | null>();
@ -222,8 +221,6 @@ export class GitService implements Disposable {
@debug()
private onWindowStateChanged(e: WindowState) {
this._suspended = !e.focused;
if (e.focused) {
this._repositoryTree.forEach(r => r.resume());
} else {
@ -333,7 +330,7 @@ export class GitService implements Disposable {
const rootPath = await this.getRepoPathCore(uri.fsPath, true);
if (rootPath != null) {
Logger.log(cc, `found root repository in '${rootPath}'`);
repositories.push(new Repository(folder, rootPath, true, anyRepoChangedFn, this._suspended));
repositories.push(new Repository(folder, rootPath, true, anyRepoChangedFn, !window.state.focused));
}
if (depth <= 0) return repositories;
@ -382,7 +379,7 @@ export class GitService implements Disposable {
if (rp == null) continue;
Logger.log(cc, `found repository in '${rp}'`);
repositories.push(new Repository(folder, rp, false, anyRepoChangedFn, this._suspended));
repositories.push(new Repository(folder, rp, false, anyRepoChangedFn, !window.state.focused));
}
return repositories;
@ -2966,7 +2963,7 @@ export class GitService implements Disposable {
}
Logger.log(cc, `Repository found in '${rp}'`);
repo = new Repository(folder, rp, false, this.onAnyRepositoryChanged.bind(this), this._suspended);
repo = new Repository(folder, rp, false, this.onAnyRepositoryChanged.bind(this), !window.state.focused);
this._repositoryTree.set(rp, repo);
// Send a notification that the repositories changed

+ 36
- 13
src/git/models/repository.ts View File

@ -23,7 +23,7 @@ import { Logger } from '../../logger';
import { Messages } from '../../messages';
import { GitBranchReference, GitReference, GitTagReference } from './models';
import { RemoteProviderFactory, RemoteProviders, RemoteProviderWithApi } from '../remotes/factory';
import { Arrays, Functions, gate, Iterables, log, logName } from '../../system';
import { Arrays, debug, Functions, gate, Iterables, log, logName } from '../../system';
import { runGitCommandInTerminal } from '../../terminal';
const ignoreGitRegex = /\.git(?:\/|\\|$)/;
@ -91,8 +91,8 @@ export class Repository implements Disposable {
private _branch: Promise<GitBranch | undefined> | undefined;
private readonly _disposable: Disposable;
private _fireChangeDebounced: ((e: RepositoryChangeEvent) => void) | undefined = undefined;
private _fireFileSystemChangeDebounced: ((e: RepositoryFileSystemChangeEvent) => void) | undefined = undefined;
private _fireChangeDebounced: (() => void) | undefined = undefined;
private _fireFileSystemChangeDebounced: (() => void) | undefined = undefined;
private _fsWatchCounter = 0;
private _fsWatcherDisposable: Disposable | undefined;
private _pendingFileSystemChange?: RepositoryFileSystemChangeEvent;
@ -192,6 +192,7 @@ export class Repository implements Disposable {
this.fireFileSystemChange(uri);
}
@debug()
private onRepositoryChanged(uri: Uri | undefined) {
if (uri == null) {
this.fireChange(RepositoryChange.Unknown);
@ -619,11 +620,11 @@ export class Repository implements Disposable {
// If we've come back into focus and we are dirty, fire the change events
if (this._pendingRepoChange != null) {
this._fireChangeDebounced!(this._pendingRepoChange);
this._fireChangeDebounced!();
}
if (this._pendingFileSystemChange != null) {
this._fireFileSystemChangeDebounced!(this._pendingFileSystemChange);
this._fireFileSystemChangeDebounced!();
}
}
@ -764,9 +765,8 @@ export class Repository implements Disposable {
this.runTerminalCommand('tag', ...args, ...tags.map(t => t.ref));
}
@debug()
private fireChange(...changes: RepositoryChange[]) {
this.onAnyRepositoryChanged(this, new RepositoryChangeEvent(this, changes));
if (this._fireChangeDebounced == null) {
this._fireChangeDebounced = Functions.debounce(this.fireChangeCore.bind(this), 250);
}
@ -783,17 +783,28 @@ export class Repository implements Disposable {
}
}
if (this._suspended) return;
this.onAnyRepositoryChanged(this, new RepositoryChangeEvent(this, changes));
if (this._suspended) {
Logger.debug(`Repository[${this.name}(${this.id})] queueing suspended changes=${e.changes.join(', ')}`);
return;
}
this._fireChangeDebounced(e);
this._fireChangeDebounced();
}
private fireChangeCore(e: RepositoryChangeEvent) {
private fireChangeCore() {
const e = this._pendingRepoChange;
if (e == null) return;
this._pendingRepoChange = undefined;
Logger.debug(`Repository[${this.name}(${this.id})] firing changes=${e.changes.join(', ')}`);
this._onDidChange.fire(e);
}
@debug()
private fireFileSystemChange(uri: Uri) {
if (this._fireFileSystemChangeDebounced == null) {
this._fireFileSystemChangeDebounced = Functions.debounce(this.fireFileSystemChangeCore.bind(this), 2500);
@ -806,12 +817,22 @@ export class Repository implements Disposable {
const e = this._pendingFileSystemChange;
e.uris.push(uri);
if (this._suspended) return;
if (this._suspended) {
Logger.debug(
`Repository[${this.name}(${this.id})] queueing suspended fs changes=${e.uris
.map(u => u.fsPath)
.join(', ')}`,
);
return;
}
this._fireFileSystemChangeDebounced(e);
this._fireFileSystemChangeDebounced();
}
private async fireFileSystemChangeCore(e: RepositoryFileSystemChangeEvent) {
private async fireFileSystemChangeCore() {
let e = this._pendingFileSystemChange;
if (e == null) return;
this._pendingFileSystemChange = undefined;
const uris = await Container.git.excludeIgnoredUris(this.path, e.uris);
@ -821,6 +842,8 @@ export class Repository implements Disposable {
e = { ...e, uris: uris };
}
Logger.debug(`Repository[${this.name}(${this.id})] firing fs changes=${e.uris.map(u => u.fsPath).join(', ')}`);
this._onDidChangeFileSystem.fire(e);
}

+ 2
- 1
src/vsls/guest.ts View File

@ -68,7 +68,8 @@ export class VslsGuestService implements Disposable {
});
return response.repositories.map(
(r: RepositoryProxy) => new Repository(folder, r.path, r.root, onAnyRepositoryChanged, false, r.closed),
(r: RepositoryProxy) =>
new Repository(folder, r.path, r.root, onAnyRepositoryChanged, !window.state.focused, r.closed),
);
}

Loading…
Cancel
Save