Skip to content

Fix #57910 - Add setting for auto fetch timeout #59988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,12 @@
"usesOnlineServices"
]
},
"git.autofetchPeriod": {
"type": "number",
"scope":"resource",
"description": "%config.autofetchPeriod%",
"default": 3
},
"git.branchValidationRegex": {
"type": "string",
"description": "%config.branchValidationRegex%",
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"config.autoRepositoryDetection.openEditors": "Scan for parent folders of open files.",
"config.autorefresh": "Whether auto refreshing is enabled.",
"config.autofetch": "Whether auto fetching is enabled.",
"config.autofetchPeriod": "Time period, in minutes, between each auto fetch run",
"config.confirmSync": "Confirm before synchronizing git repositories.",
"config.countBadge": "Controls the git badge counter.",
"config.countBadge.all": "Count all changes.",
Expand Down
29 changes: 16 additions & 13 deletions extensions/git/src/autofetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ function isRemoteOperation(operation: Operation): boolean {

export class AutoFetcher {

private static readonly Period = 3 * 60 * 1000 /* three minutes */;
private static DidInformUser = 'autofetch.didInformUser';

private _onDidChange = new EventEmitter<boolean>();
private _onDidChange = new EventEmitter<boolean | number>();
private onDidChange = this._onDidChange.event;

private _enabled: boolean = false;
get enabled(): boolean { return this._enabled; }
set enabled(enabled: boolean) { this._enabled = enabled; this._onDidChange.fire(enabled); }

private _timeout: number = workspace.getConfiguration('git').get<number>('autofetchPeriod', 3) * 60 * 1000;
private get timeout(): number { return this._timeout; }
private set timeout(minutes: number) { this._timeout = minutes * 60 * 1000; this._onDidChange.fire(minutes); }

private disposables: Disposable[] = [];

constructor(private repository: Repository, private globalState: Memento) {
Expand Down Expand Up @@ -72,19 +75,19 @@ export class AutoFetcher {

private onConfiguration(): void {
const gitConfig = workspace.getConfiguration('git');
const minutes = gitConfig.get<number>('autofetchPeriod', 3);
const autofetch = gitConfig.get<boolean>('autofetch');

if (gitConfig.get<boolean>('autofetch') === false) {
this.disable();
} else {
this.enable();
if (this.timeout !== minutes) {
this.timeout = minutes;
}
}

enable(): void {
if (this.enabled) {
return;
if (this.enabled !== autofetch) {
autofetch ? this.enable() : this.disable();
}
}

enable(): void {
this.enabled = true;
this.run();
}
Expand Down Expand Up @@ -113,9 +116,9 @@ export class AutoFetcher {
return;
}

const timeout = new Promise(c => setTimeout(c, AutoFetcher.Period));
const whenDisabled = eventToPromise(filterEvent(this.onDidChange, enabled => !enabled));
await Promise.race([timeout, whenDisabled]);
const timeout = new Promise(c => setTimeout(c, this.timeout));
const onChanged = eventToPromise(filterEvent(this.onDidChange, () => true));
await Promise.race([timeout, onChanged]);
}
}

Expand Down