mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
[Git] Migrate to git autostash when pulling for better performance (#187850)
* git: migrate to git autostash when pulling (better performance) * should be implemented correctly! * refactor other op * Pull request feedback --------- Co-authored-by: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com>
This commit is contained in:
@@ -1127,8 +1127,9 @@ function parseGitBlame(data: string): BlameInformation[] {
|
||||
}
|
||||
|
||||
export interface PullOptions {
|
||||
unshallow?: boolean;
|
||||
tags?: boolean;
|
||||
readonly unshallow?: boolean;
|
||||
readonly tags?: boolean;
|
||||
readonly autoStash?: boolean;
|
||||
readonly cancellationToken?: CancellationToken;
|
||||
}
|
||||
|
||||
@@ -2087,6 +2088,11 @@ export class Repository {
|
||||
args.push('--unshallow');
|
||||
}
|
||||
|
||||
// --auto-stash option is only available `git pull --merge` starting with git 2.27.0
|
||||
if (options.autoStash && this._git.compareGitVersionTo('2.27.0') !== -1) {
|
||||
args.push('--autostash');
|
||||
}
|
||||
|
||||
if (rebase) {
|
||||
args.push('-r');
|
||||
}
|
||||
|
||||
@@ -1798,6 +1798,7 @@ export class Repository implements Disposable {
|
||||
await this.run(Operation.Pull, async () => {
|
||||
await this.maybeAutoStash(async () => {
|
||||
const config = workspace.getConfiguration('git', Uri.file(this.root));
|
||||
const autoStash = config.get<boolean>('autoStash');
|
||||
const fetchOnPull = config.get<boolean>('fetchOnPull');
|
||||
const tags = config.get<boolean>('pullTags');
|
||||
|
||||
@@ -1807,7 +1808,7 @@ export class Repository implements Disposable {
|
||||
}
|
||||
|
||||
if (await this.checkIfMaybeRebased(this.HEAD?.name)) {
|
||||
await this._pullAndHandleTagConflict(rebase, remote, branch, { unshallow, tags });
|
||||
await this._pullAndHandleTagConflict(rebase, remote, branch, { unshallow, tags, autoStash });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1881,6 +1882,7 @@ export class Repository implements Disposable {
|
||||
await this.run(Operation.Sync, async () => {
|
||||
await this.maybeAutoStash(async () => {
|
||||
const config = workspace.getConfiguration('git', Uri.file(this.root));
|
||||
const autoStash = config.get<boolean>('autoStash');
|
||||
const fetchOnPull = config.get<boolean>('fetchOnPull');
|
||||
const tags = config.get<boolean>('pullTags');
|
||||
const followTags = config.get<boolean>('followTagsWhenSync');
|
||||
@@ -1893,7 +1895,7 @@ export class Repository implements Disposable {
|
||||
}
|
||||
|
||||
if (await this.checkIfMaybeRebased(this.HEAD?.name)) {
|
||||
await this._pullAndHandleTagConflict(rebase, remoteName, pullBranch, { tags, cancellationToken });
|
||||
await this._pullAndHandleTagConflict(rebase, remoteName, pullBranch, { tags, cancellationToken, autoStash });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2530,6 +2532,7 @@ export class Repository implements Disposable {
|
||||
private async maybeAutoStash<T>(runOperation: () => Promise<T>): Promise<T> {
|
||||
const config = workspace.getConfiguration('git', Uri.file(this.root));
|
||||
const shouldAutoStash = config.get<boolean>('autoStash')
|
||||
&& this.repository.git.compareGitVersionTo('2.27.0') < 0
|
||||
&& (this.indexGroup.resourceStates.length > 0
|
||||
|| this.workingTreeGroup.resourceStates.some(
|
||||
r => r.type !== Status.UNTRACKED && r.type !== Status.IGNORED));
|
||||
|
||||
Reference in New Issue
Block a user