From 53bcea2500b26aef951f2c064440a24ea3057f4e Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 13 Jun 2019 11:55:34 -0400 Subject: [PATCH] Changes fetch/pull/push to be in parallel --- src/git/gitService.ts | 87 ++++++++++++++++++-------------------------- src/git/models/repository.ts | 9 ++--- 2 files changed, 39 insertions(+), 57 deletions(-) diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 7d42832..0e4ca5a 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -510,85 +510,70 @@ export class GitService implements Disposable { @gate() @log() - async fetchAll() { - const repositories = await this.getOrderedRepositories(); + async fetchAll(repositories?: Repository[]) { + if (repositories === undefined) { + repositories = await this.getOrderedRepositories(); + } if (repositories.length === 0) return; + if (repositories.length === 1) { + repositories[0].fetch(); + + return; + } + await window.withProgress( { location: ProgressLocation.Notification, - title: 'Fetching repositories', - cancellable: true + title: `Fetching ${repositories.length} repositories` }, - async (progress, token) => { - const total = repositories.length; - for (const repo of repositories) { - progress.report({ - message: `${repo.formattedName}...`, - increment: 100 / total - }); - - if (token.isCancellationRequested) break; - - await repo.fetch({ progress: false }); - } - } + () => Promise.all(repositories!.map(r => r.fetch({ progress: false }))) ); } @gate() @log() - async pullAll() { - const repositories = await this.getOrderedRepositories(); + async pullAll(repositories?: Repository[]) { + if (repositories === undefined) { + repositories = await this.getOrderedRepositories(); + } if (repositories.length === 0) return; + if (repositories.length === 1) { + repositories[0].pull(); + + return; + } + await window.withProgress( { location: ProgressLocation.Notification, - title: 'Pulling repositories', - cancellable: true + title: `Pulling ${repositories.length} repositories` }, - async (progress, token) => { - const total = repositories.length; - for (const repo of repositories) { - progress.report({ - message: `${repo.formattedName}...`, - increment: 100 / total - }); - - if (token.isCancellationRequested) break; - - await repo.pull({ progress: false }); - } - } + () => Promise.all(repositories!.map(r => r.pull({ progress: false }))) ); } @gate() @log() - async pushAll() { - const repositories = await this.getOrderedRepositories(); + async pushAll(repositories?: Repository[]) { + if (repositories === undefined) { + repositories = await this.getOrderedRepositories(); + } if (repositories.length === 0) return; + if (repositories.length === 1) { + repositories[0].push(); + + return; + } + await window.withProgress( { location: ProgressLocation.Notification, - title: 'Pushing repositories', - cancellable: true + title: `Pushing ${repositories.length} repositories` }, - async (progress, token) => { - const total = repositories.length; - for (const repo of repositories) { - progress.report({ - message: `${repo.formattedName}...`, - increment: 100 / total - }); - - if (token.isCancellationRequested) break; - - await repo.push({ progress: false }); - } - } + () => Promise.all(repositories!.map(r => r.push({ progress: false }))) ); } diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index 679262c..f1d8ef8 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -244,8 +244,7 @@ export class Repository implements Disposable { return void (await window.withProgress( { location: ProgressLocation.Notification, - title: `Fetching ${opts.remote ? `${opts.remote} of ` : ''}${this.formattedName}...`, - cancellable: false + title: `Fetching ${opts.remote ? `${opts.remote} of ` : ''}${this.formattedName}...` }, () => this.fetchCore(opts) )); @@ -332,8 +331,7 @@ export class Repository implements Disposable { return void (await window.withProgress( { location: ProgressLocation.Notification, - title: `Pulling ${this.formattedName}...`, - cancellable: false + title: `Pulling ${this.formattedName}...` }, () => this.pullCore() )); @@ -360,8 +358,7 @@ export class Repository implements Disposable { return void (await window.withProgress( { location: ProgressLocation.Notification, - title: `Pushing ${this.formattedName}...`, - cancellable: false + title: `Pushing ${this.formattedName}...` }, () => this.pushCore(force) ));