From 206d342408e9d8efb6dd510e18ceabd28c9a490c Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Mon, 13 Jun 2016 18:06:23 +0200 Subject: [PATCH] use more compact git ipc status messages --- src/vs/workbench/parts/git/common/gitIpc.ts | 147 ++++++++++++++------ 1 file changed, 101 insertions(+), 46 deletions(-) diff --git a/src/vs/workbench/parts/git/common/gitIpc.ts b/src/vs/workbench/parts/git/common/gitIpc.ts index b0db7eb4ccc..e4bf45ad1dd 100644 --- a/src/vs/workbench/parts/git/common/gitIpc.ts +++ b/src/vs/workbench/parts/git/common/gitIpc.ts @@ -8,27 +8,82 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc'; import Event from 'vs/base/common/event'; -import { IRawGitService, RawServiceState, IRawStatus, IPushOptions, IAskpassService, ICredentials } from './git'; +import { IRawGitService, RawServiceState, IRawStatus, IPushOptions, IAskpassService, ICredentials, + ServiceState, IRawFileStatus, IBranch, RefType, IRef, IRemote } from './git'; + +type ISerializer = { to(a: A): B; from(b: B): A; }; + +export type IPCRawFileStatus = [string, string, string, string, string]; +const RawFileStatusSerializer: ISerializer = { + to: a => [a.x, a.y, a.path, a.mimetype, a.rename], + from: b => ({ x: b[0], y: b[1], path: b[2], mimetype: b[3], rename: b[4] }) +}; + +export type IPCBranch = [string, string, RefType, string, string, number, number]; +const BranchSerializer: ISerializer = { + to: a => [a.name, a.commit, a.type, a.remote, a.upstream, a.ahead, a.behind], + from: b => ({ name: b[0], commit: b[1], type: b[2], remote: b[3], upstream: b[4], ahead: b[5], behind: b[6] }) +}; + +export type IPCRef = [string, string, RefType, string]; +const RefSerializer: ISerializer = { + to: a => [a.name, a.commit, a.type, a.remote], + from: b => ({ name: b[0], commit: b[1], type: b[2], remote: b[3] }) +}; + +export type IPCRemote = [string, string]; +const RemoteSerializer: ISerializer = { + to: a => [a.name, a.url], + from: b => ({ name: b[0], url: b[1] }) +}; + +export type IPCRawStatus = [ + string, + ServiceState, + IPCRawFileStatus[], + IPCBranch, + IPCRef[], + IPCRemote[] +]; + +const RawStatusSerializer: ISerializer = { + to: a => !a ? null : [ + a.repositoryRoot, + a.state, + a.status.map(RawFileStatusSerializer.to), + BranchSerializer.to(a.HEAD), + a.refs.map(RefSerializer.to), + a.remotes.map(RemoteSerializer.to) + ], + from: b => !b ? null : { + repositoryRoot: b[0], + state: b[1], + status: b[2].map(RawFileStatusSerializer.from), + HEAD: BranchSerializer.from(b[3]), + refs: b[4].map(RefSerializer.from), + remotes: b[5].map(RemoteSerializer.from) + } +}; export interface IGitChannel extends IChannel { call(command: 'getVersion'): TPromise; call(command: 'serviceState'): TPromise; call(command: 'statusCount'): TPromise; - call(command: 'status'): TPromise; - call(command: 'init'): TPromise; - call(command: 'add', filesPaths?: string[]): TPromise; - call(command: 'stage', args: [string, string]): TPromise; - call(command: 'branch', args: [string, boolean]): TPromise; - call(command: 'checkout', args: [string, string[]]): TPromise; - call(command: 'clean', filePaths: string[]): TPromise; - call(command: 'undo'): TPromise; - call(command: 'reset', args: [string, boolean]): TPromise; - call(command: 'revertFiles', args: [string, string[]]): TPromise; - call(command: 'fetch'): TPromise; - call(command: 'pull', rebase?: boolean): TPromise; - call(command: 'push', args: [string, string, IPushOptions]): TPromise; - call(command: 'sync'): TPromise; - call(command: 'commit', args: [string, boolean, boolean]): TPromise; + call(command: 'status'): TPromise; + call(command: 'init'): TPromise; + call(command: 'add', filesPaths?: string[]): TPromise; + call(command: 'stage', args: [string, string]): TPromise; + call(command: 'branch', args: [string, boolean]): TPromise; + call(command: 'checkout', args: [string, string[]]): TPromise; + call(command: 'clean', filePaths: string[]): TPromise; + call(command: 'undo'): TPromise; + call(command: 'reset', args: [string, boolean]): TPromise; + call(command: 'revertFiles', args: [string, string[]]): TPromise; + call(command: 'fetch'): TPromise; + call(command: 'pull', rebase?: boolean): TPromise; + call(command: 'push', args: [string, string, IPushOptions]): TPromise; + call(command: 'sync'): TPromise; + call(command: 'commit', args: [string, boolean, boolean]): TPromise; call(command: 'detectMimetypes', args: [string, string]): TPromise; call(command: 'show', args: [string, string]): TPromise; call(command: 'onOutput'): TPromise; @@ -44,21 +99,21 @@ export class GitChannel implements IGitChannel { case 'getVersion': return this.service.then(s => s.getVersion()); case 'serviceState': return this.service.then(s => s.serviceState()); case 'statusCount': return this.service.then(s => s.statusCount()); - case 'status': return this.service.then(s => s.status()); - case 'init': return this.service.then(s => s.init()); - case 'add': return this.service.then(s => s.add(args)); - case 'stage': return this.service.then(s => s.stage(args[0], args[1])); - case 'branch': return this.service.then(s => s.branch(args[0], args[1])); - case 'checkout': return this.service.then(s => s.checkout(args[0], args[1])); - case 'clean': return this.service.then(s => s.clean(args)); - case 'undo': return this.service.then(s => s.undo()); - case 'reset': return this.service.then(s => s.reset(args[0], args[1])); - case 'revertFiles': return this.service.then(s => s.revertFiles(args[0], args[1])); - case 'fetch': return this.service.then(s => s.fetch()); - case 'pull': return this.service.then(s => s.pull(args)); - case 'push': return this.service.then(s => s.push(args[0], args[1], args[2])); - case 'sync': return this.service.then(s => s.sync()); - case 'commit': return this.service.then(s => s.commit(args[0], args[1], args[2])); + case 'status': return this.service.then(s => s.status()).then(RawStatusSerializer.to); + case 'init': return this.service.then(s => s.init()).then(RawStatusSerializer.to); + case 'add': return this.service.then(s => s.add(args)).then(RawStatusSerializer.to); + case 'stage': return this.service.then(s => s.stage(args[0], args[1])).then(RawStatusSerializer.to); + case 'branch': return this.service.then(s => s.branch(args[0], args[1])).then(RawStatusSerializer.to); + case 'checkout': return this.service.then(s => s.checkout(args[0], args[1])).then(RawStatusSerializer.to); + case 'clean': return this.service.then(s => s.clean(args)).then(RawStatusSerializer.to); + case 'undo': return this.service.then(s => s.undo()).then(RawStatusSerializer.to); + case 'reset': return this.service.then(s => s.reset(args[0], args[1])).then(RawStatusSerializer.to); + case 'revertFiles': return this.service.then(s => s.revertFiles(args[0], args[1])).then(RawStatusSerializer.to); + case 'fetch': return this.service.then(s => s.fetch()).then(RawStatusSerializer.to); + case 'pull': return this.service.then(s => s.pull(args)).then(RawStatusSerializer.to); + case 'push': return this.service.then(s => s.push(args[0], args[1], args[2])).then(RawStatusSerializer.to); + case 'sync': return this.service.then(s => s.sync()).then(RawStatusSerializer.to); + case 'commit': return this.service.then(s => s.commit(args[0], args[1], args[2])).then(RawStatusSerializer.to); case 'detectMimetypes': return this.service.then(s => s.detectMimetypes(args[0], args[1])); case 'show': return this.service.then(s => s.show(args[0], args[1])); case 'onOutput': return this.service.then(s => eventToCall(s.onOutput)); @@ -96,63 +151,63 @@ export class GitChannelClient implements IRawGitService { } status(): TPromise { - return this.channel.call('status'); + return this.channel.call('status').then(RawStatusSerializer.from); } init(): TPromise { - return this.channel.call('init'); + return this.channel.call('init').then(RawStatusSerializer.from); } add(filesPaths?: string[]): TPromise { - return this.channel.call('add', filesPaths); + return this.channel.call('add', filesPaths).then(RawStatusSerializer.from); } stage(filePath: string, content: string): TPromise { - return this.channel.call('stage', [filePath, content]); + return this.channel.call('stage', [filePath, content]).then(RawStatusSerializer.from); } branch(name: string, checkout?: boolean): TPromise { - return this.channel.call('branch', [name, checkout]); + return this.channel.call('branch', [name, checkout]).then(RawStatusSerializer.from); } checkout(treeish?: string, filePaths?: string[]): TPromise { - return this.channel.call('checkout', [treeish, filePaths]); + return this.channel.call('checkout', [treeish, filePaths]).then(RawStatusSerializer.from); } clean(filePaths: string[]): TPromise { - return this.channel.call('clean', filePaths); + return this.channel.call('clean', filePaths).then(RawStatusSerializer.from); } undo(): TPromise { - return this.channel.call('undo'); + return this.channel.call('undo').then(RawStatusSerializer.from); } reset(treeish:string, hard?: boolean): TPromise { - return this.channel.call('reset', [treeish, hard]); + return this.channel.call('reset', [treeish, hard]).then(RawStatusSerializer.from); } revertFiles(treeish:string, filePaths?: string[]): TPromise { - return this.channel.call('revertFiles', [treeish, filePaths]); + return this.channel.call('revertFiles', [treeish, filePaths]).then(RawStatusSerializer.from); } fetch(): TPromise { - return this.channel.call('fetch'); + return this.channel.call('fetch').then(RawStatusSerializer.from); } pull(rebase?: boolean): TPromise { - return this.channel.call('pull', rebase); + return this.channel.call('pull', rebase).then(RawStatusSerializer.from); } push(remote?: string, name?: string, options?:IPushOptions): TPromise { - return this.channel.call('push', [remote, name, options]); + return this.channel.call('push', [remote, name, options]).then(RawStatusSerializer.from); } sync(): TPromise { - return this.channel.call('sync'); + return this.channel.call('sync').then(RawStatusSerializer.from); } commit(message:string, amend?: boolean, stage?: boolean): TPromise { - return this.channel.call('commit', [message, amend, stage]); + return this.channel.call('commit', [message, amend, stage]).then(RawStatusSerializer.from); } detectMimetypes(path: string, treeish?: string): TPromise { -- GitLab