|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { commands, Uri, Command, EventEmitter, Event, scm, SourceControl, SourceControlInputBox, SourceControlResourceGroup, SourceControlResourceState, SourceControlResourceDecorations, SourceControlInputBoxValidation, Disposable, ProgressLocation, window, workspace, WorkspaceEdit, ThemeColor, DecorationData, Memento, SourceControlInputBoxValidationType } from 'vscode'; |
| 6 | +import { commands, Uri, Command, EventEmitter, Event, scm, SourceControl, SourceControlInputBox, SourceControlResourceGroup, SourceControlResourceState, SourceControlResourceDecorations, SourceControlInputBoxValidation, Disposable, ProgressLocation, window, workspace, WorkspaceEdit, ThemeColor, DecorationData, Memento, SourceControlInputBoxValidationType, OutputChannel, LogLevel, env } from 'vscode'; |
7 | 7 | import { Repository as BaseRepository, Commit, Stash, GitError, Submodule, CommitOptions, ForcePushMode } from './git'; |
8 | | -import { anyEvent, filterEvent, eventToPromise, dispose, find, isDescendant, IDisposable, onceEvent, EmptyDisposable, debounceEvent, toDisposable } from './util'; |
| 8 | +import { anyEvent, filterEvent, eventToPromise, dispose, find, isDescendant, IDisposable, onceEvent, EmptyDisposable, debounceEvent, toDisposable, combinedDisposable } from './util'; |
9 | 9 | import { memoize, throttle, debounce } from './decorators'; |
10 | 10 | import { toGitUri } from './uri'; |
11 | 11 | import { AutoFetcher } from './autofetch'; |
@@ -447,6 +447,39 @@ class ProgressManager { |
447 | 447 | } |
448 | 448 | } |
449 | 449 |
|
| 450 | +class FileEventLogger { |
| 451 | + |
| 452 | + private eventDisposable: IDisposable = EmptyDisposable; |
| 453 | + private logLevelDisposable: IDisposable = EmptyDisposable; |
| 454 | + |
| 455 | + constructor( |
| 456 | + private onWorkspaceWorkingTreeFileChange: Event<Uri>, |
| 457 | + private onDotGitFileChange: Event<Uri>, |
| 458 | + private outputChannel: OutputChannel |
| 459 | + ) { |
| 460 | + this.logLevelDisposable = env.onDidChangeLogLevel(this.onDidChangeLogLevel, this); |
| 461 | + this.onDidChangeLogLevel(env.logLevel); |
| 462 | + } |
| 463 | + |
| 464 | + private onDidChangeLogLevel(level: LogLevel): void { |
| 465 | + this.eventDisposable.dispose(); |
| 466 | + |
| 467 | + if (level > LogLevel.Debug) { |
| 468 | + return; |
| 469 | + } |
| 470 | + |
| 471 | + this.eventDisposable = combinedDisposable([ |
| 472 | + this.onWorkspaceWorkingTreeFileChange(uri => this.outputChannel.appendLine(`[debug] [wt] Change: ${uri.fsPath}`)), |
| 473 | + this.onDotGitFileChange(uri => this.outputChannel.appendLine(`[debug] [.git] Change: ${uri.fsPath}`)) |
| 474 | + ]); |
| 475 | + } |
| 476 | + |
| 477 | + dispose(): void { |
| 478 | + this.eventDisposable.dispose(); |
| 479 | + this.logLevelDisposable.dispose(); |
| 480 | + } |
| 481 | +} |
| 482 | + |
450 | 483 | export class Repository implements Disposable { |
451 | 484 |
|
452 | 485 | private _onDidChangeRepository = new EventEmitter<Uri>(); |
@@ -547,34 +580,39 @@ export class Repository implements Disposable { |
547 | 580 | private isRepositoryHuge = false; |
548 | 581 | private didWarnAboutLimit = false; |
549 | 582 | private isFreshRepository: boolean | undefined = undefined; |
| 583 | + |
| 584 | + |
550 | 585 | private disposables: Disposable[] = []; |
551 | 586 |
|
552 | 587 | constructor( |
553 | 588 | private readonly repository: BaseRepository, |
554 | | - globalState: Memento |
| 589 | + globalState: Memento, |
| 590 | + outputChannel: OutputChannel |
555 | 591 | ) { |
556 | 592 | const workspaceWatcher = workspace.createFileSystemWatcher('**'); |
557 | 593 | this.disposables.push(workspaceWatcher); |
558 | 594 |
|
559 | | - const onWorkspaceFileChanges = anyEvent(workspaceWatcher.onDidChange, workspaceWatcher.onDidCreate, workspaceWatcher.onDidDelete); |
560 | | - const onWorkspaceRepositoryFileChanges = filterEvent(onWorkspaceFileChanges, uri => isDescendant(repository.root, uri.fsPath)); |
561 | | - const onWorkspaceWorkingTreeFileChanges = filterEvent(onWorkspaceRepositoryFileChanges, uri => !/\/\.git($|\/)/.test(uri.path)); |
| 595 | + const onWorkspaceFileChange = anyEvent(workspaceWatcher.onDidChange, workspaceWatcher.onDidCreate, workspaceWatcher.onDidDelete); |
| 596 | + const onWorkspaceRepositoryFileChange = filterEvent(onWorkspaceFileChange, uri => isDescendant(repository.root, uri.fsPath)); |
| 597 | + const onWorkspaceWorkingTreeFileChange = filterEvent(onWorkspaceRepositoryFileChange, uri => !/\/\.git($|\/)/.test(uri.path)); |
562 | 598 |
|
563 | 599 | const dotGitWatcher = fs.watch(repository.dotGit); |
564 | | - const onRepositoryFileEmitter = new EventEmitter<Uri>(); |
565 | | - dotGitWatcher.on('change', (_, e) => onRepositoryFileEmitter.fire(Uri.file(path.join(repository.dotGit, e as string)))); |
| 600 | + const onDotGitFileChangeEmitter = new EventEmitter<Uri>(); |
| 601 | + dotGitWatcher.on('change', (_, e) => onDotGitFileChangeEmitter.fire(Uri.file(path.join(repository.dotGit, e as string)))); |
566 | 602 | dotGitWatcher.on('error', err => console.error(err)); |
567 | 603 | this.disposables.push(toDisposable(() => dotGitWatcher.close())); |
568 | | - const onRelevantRepositoryChanges = filterEvent(onRepositoryFileEmitter.event, uri => !/\/\.git(\/index\.lock)?$/.test(uri.path)); |
| 604 | + const onDotGitFileChange = filterEvent(onDotGitFileChangeEmitter.event, uri => !/\/\.git(\/index\.lock)?$/.test(uri.path)); |
569 | 605 |
|
570 | 606 | // FS changes should trigger `git status`: |
571 | 607 | // - any change inside the repository working tree |
572 | 608 | // - any change whithin the first level of the `.git` folder, except the folder itself and `index.lock` |
573 | | - const onFSChange = anyEvent(onWorkspaceWorkingTreeFileChanges, onRelevantRepositoryChanges); |
574 | | - onFSChange(this.onFSChange, this, this.disposables); |
| 609 | + const onFileChange = anyEvent(onWorkspaceWorkingTreeFileChange, onDotGitFileChange); |
| 610 | + onFileChange(this.onFileChange, this, this.disposables); |
575 | 611 |
|
576 | 612 | // Relevate repository changes should trigger virtual document change events |
577 | | - onRelevantRepositoryChanges(this._onDidChangeRepository.fire, this._onDidChangeRepository, this.disposables); |
| 613 | + onDotGitFileChange(this._onDidChangeRepository.fire, this._onDidChangeRepository, this.disposables); |
| 614 | + |
| 615 | + this.disposables.push(new FileEventLogger(onWorkspaceWorkingTreeFileChange, onDotGitFileChange, outputChannel)); |
578 | 616 |
|
579 | 617 | const root = Uri.file(repository.root); |
580 | 618 | this._sourceControl = scm.createSourceControl('git', 'Git', root); |
@@ -1454,7 +1492,7 @@ export class Repository implements Disposable { |
1454 | 1492 | return result; |
1455 | 1493 | } |
1456 | 1494 |
|
1457 | | - private onFSChange(_uri: Uri): void { |
| 1495 | + private onFileChange(_uri: Uri): void { |
1458 | 1496 | const config = workspace.getConfiguration('git'); |
1459 | 1497 | const autorefresh = config.get<boolean>('autorefresh'); |
1460 | 1498 |
|
|
0 commit comments