Skip to content

Commit 32d22db

Browse files
committed
Merge commit 'refs/pull/59988/head' of github.com:Microsoft/vscode into pr/59988
2 parents a1279d3 + 7761add commit 32d22db

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

extensions/git/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,12 @@
10241024
"usesOnlineServices"
10251025
]
10261026
},
1027+
"git.autofetchPeriod": {
1028+
"type": "number",
1029+
"scope": "resource",
1030+
"description": "%config.autofetchPeriod%",
1031+
"default": 3
1032+
},
10271033
"git.branchValidationRegex": {
10281034
"type": "string",
10291035
"description": "%config.branchValidationRegex%",

extensions/git/package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"config.autoRepositoryDetection.openEditors": "Scan for parent folders of open files.",
6969
"config.autorefresh": "Whether auto refreshing is enabled.",
7070
"config.autofetch": "When enabled, commits will automatically be fetched from the default remote of the current Git repository.",
71+
"config.autofetchPeriod": "Duration in minutes between each automatic git fetch, when `git.autofetch` is enabled.",
7172
"config.confirmSync": "Confirm before synchronizing git repositories.",
7273
"config.countBadge": "Controls the git badge counter.",
7374
"config.countBadge.all": "Count all changes.",
@@ -119,4 +120,4 @@
119120
"colors.ignored": "Color for ignored resources.",
120121
"colors.conflict": "Color for resources with conflicts.",
121122
"colors.submodule": "Color for submodule resources."
122-
}
123+
}

extensions/git/src/autofetch.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ function isRemoteOperation(operation: Operation): boolean {
1717

1818
export class AutoFetcher {
1919

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

23-
private _onDidChange = new EventEmitter<boolean>();
22+
private _onDidChange = new EventEmitter<boolean | number>();
2423
private onDidChange = this._onDidChange.event;
2524

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

29+
private _timeout: number = workspace.getConfiguration('git').get<number>('autofetchPeriod', 3) * 60 * 1000;
30+
private get timeout(): number { return this._timeout; }
31+
private set timeout(minutes: number) { this._timeout = minutes * 60 * 1000; this._onDidChange.fire(minutes); }
32+
3033
private disposables: Disposable[] = [];
3134

3235
constructor(private repository: Repository, private globalState: Memento) {
@@ -70,19 +73,19 @@ export class AutoFetcher {
7073

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

74-
if (gitConfig.get<boolean>('autofetch') === false) {
75-
this.disable();
76-
} else {
77-
this.enable();
79+
if (this.timeout !== minutes) {
80+
this.timeout = minutes;
7881
}
79-
}
8082

81-
enable(): void {
82-
if (this.enabled) {
83-
return;
83+
if (this.enabled !== autofetch) {
84+
autofetch ? this.enable() : this.disable();
8485
}
86+
}
8587

88+
enable(): void {
8689
this.enabled = true;
8790
this.run();
8891
}
@@ -111,9 +114,9 @@ export class AutoFetcher {
111114
return;
112115
}
113116

114-
const timeout = new Promise(c => setTimeout(c, AutoFetcher.Period));
115-
const whenDisabled = eventToPromise(filterEvent(this.onDidChange, enabled => !enabled));
116-
await Promise.race([timeout, whenDisabled]);
117+
const timeout = new Promise(c => setTimeout(c, this.timeout));
118+
const onChanged = eventToPromise(filterEvent(this.onDidChange, () => true));
119+
await Promise.race([timeout, onChanged]);
117120
}
118121
}
119122

0 commit comments

Comments
 (0)