Skip to content

Commit

Permalink
Fixes #798 - multiple repo fetch/push/pull fails
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Jul 30, 2019
1 parent aaac484 commit b4c96c5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Fixed

- Fixes [#798](https://github.com/eamodio/vscode-gitlens/issues/798) - git pull/fetch all repositories
- Fixes [#805](https://github.com/eamodio/vscode-gitlens/issues/805) - Version 9.9.1 breaks working tree comparison

## [9.9.1] - 2019-07-23
Expand Down
10 changes: 7 additions & 3 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ export class GitService implements Disposable {
return Git.fetch(repoPath, options);
}

@gate()
@gate<GitService['fetchAll']>(
(repos, opts) => `${repos === undefined ? '' : repos.map(r => r.id).join(',')}|${JSON.stringify(opts)}`
)
@log({
args: {
0: (repos?: Repository[]) => (repos === undefined ? false : repos.map(r => r.name).join(', '))
Expand All @@ -538,7 +540,9 @@ export class GitService implements Disposable {
);
}

@gate()
@gate<GitService['pullAll']>(
(repos, opts) => `${repos === undefined ? '' : repos.map(r => r.id).join(',')}|${JSON.stringify(opts)}`
)
@log({
args: {
0: (repos?: Repository[]) => (repos === undefined ? false : repos.map(r => r.name).join(', '))
Expand All @@ -565,7 +569,7 @@ export class GitService implements Disposable {
);
}

@gate()
@gate<GitService['pushAll']>(repos => `${repos === undefined ? '' : repos.map(r => r.id).join(',')}`)
@log({
args: {
0: (repos?: Repository[]) => (repos === undefined ? false : repos.map(r => r.name).join(', '))
Expand Down
32 changes: 26 additions & 6 deletions src/system/decorators/gate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
'use strict';
import { Promises } from '../promise';

export function gate() {
const emptyStr = '';

function defaultResolver(...args: any[]): string {
if (args.length === 1) {
const arg0 = args[0];
if (arg0 == null) return emptyStr;
if (typeof arg0 === 'string') return arg0;
if (typeof arg0 === 'number' || typeof arg0 === 'boolean') {
return String(arg0);
}

return JSON.stringify(arg0);
}

return JSON.stringify(args);
}

export function gate<T extends (...arg: any) => any>(resolver?: (...args: Parameters<T>) => string) {
return (target: any, key: string, descriptor: PropertyDescriptor) => {
let fn: Function | undefined;
if (typeof descriptor.value === 'function') {
Expand All @@ -15,24 +32,27 @@ export function gate() {
const gateKey = `$gate$${key}`;

descriptor.value = function(this: any, ...args: any[]) {
if (!Object.prototype.hasOwnProperty.call(this, gateKey)) {
Object.defineProperty(this, gateKey, {
const prop =
args.length === 0 ? gateKey : `${gateKey}$${(resolver || defaultResolver)(...(args as Parameters<T>))}`;

if (!Object.prototype.hasOwnProperty.call(this, prop)) {
Object.defineProperty(this, prop, {
configurable: false,
enumerable: false,
writable: true,
value: undefined
});
}

let promise = this[gateKey];
let promise = this[prop];
if (promise === undefined) {
const result = fn!.apply(this, args);
if (result == null || !Promises.isPromise(result)) {
return result;
}

this[gateKey] = promise = result.then((r: any) => {
this[gateKey] = undefined;
this[prop] = promise = result.then((r: any) => {
this[prop] = undefined;
return r;
});
}
Expand Down
1 change: 0 additions & 1 deletion src/views/nodes/fileHistoryTrackerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode<FileHistoryVie
this.canSubscribe = enabled;
}

@gate()
@log()
async showHistoryForUri(uri: GitUri, baseRef?: string) {
this._fileUri = uri;
Expand Down

0 comments on commit b4c96c5

Please sign in to comment.