getLog
added to srv & clt-srv plumbing.
* Added `getLog` method to `Repository`. * Added `ILogOptions` to make the method friendlier to extension. * Options include `prevCount` and `format`, to effect our use case which is `git log -1 format=%B`. * Added this to the client-server communication pipeline.
This commit is contained in:
parent
acf71f87db
commit
8a92ee5aa3
|
@ -38,6 +38,7 @@ import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage'
|
|||
import Event from 'vs/base/common/event';
|
||||
import { domEvent } from 'vs/base/browser/event';
|
||||
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
|
||||
import { ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
|
||||
|
||||
function toReadablePath(path: string): string {
|
||||
if (!platform.isWindows) {
|
||||
|
@ -695,6 +696,10 @@ export class GitService extends ee.EventEmitter
|
|||
return this.raw.getCommitTemplate();
|
||||
}
|
||||
|
||||
public getLog(options?: ILogOptions): winjs.Promise {
|
||||
return this.raw.getLog(options);
|
||||
}
|
||||
|
||||
public detectMimetypes(path: string, treeish: string = '~'): winjs.Promise {
|
||||
return this.raw.detectMimetypes(path, treeish);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import { IEventEmitter } from 'vs/base/common/eventEmitter';
|
|||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import Event from 'vs/base/common/event';
|
||||
import { ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
|
||||
|
||||
// Model raw interfaces
|
||||
|
||||
|
@ -287,6 +288,7 @@ export interface IRawGitService {
|
|||
detectMimetypes(path: string, treeish?: string): TPromise<string[]>;
|
||||
show(path: string, treeish?: string): TPromise<string>;
|
||||
getCommitTemplate(): TPromise<string>;
|
||||
getLog(options?: ILogOptions): TPromise<string>;
|
||||
}
|
||||
|
||||
export const GIT_SERVICE_ID = 'gitService';
|
||||
|
@ -324,6 +326,7 @@ export interface IGitService extends IEventEmitter {
|
|||
getRunningOperations(): IGitOperation[];
|
||||
getAutoFetcher(): IAutoFetcher;
|
||||
getCommitTemplate(): TPromise<string>;
|
||||
getLog(options?: ILogOptions): TPromise<string>;
|
||||
}
|
||||
|
||||
export interface IAskpassService {
|
||||
|
|
|
@ -10,6 +10,7 @@ import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/i
|
|||
import Event from 'vs/base/common/event';
|
||||
import { IRawGitService, RawServiceState, IRawStatus, IPushOptions, IAskpassService, ICredentials,
|
||||
ServiceState, IRawFileStatus, IBranch, RefType, IRef, IRemote } from './git';
|
||||
import { ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
|
||||
|
||||
type ISerializer<A,B> = { to(a: A): B; from(b: B): A; };
|
||||
|
||||
|
@ -88,6 +89,7 @@ export interface IGitChannel extends IChannel {
|
|||
call(command: 'show', args: [string, string]): TPromise<string>;
|
||||
call(command: 'onOutput'): TPromise<void>;
|
||||
call(command: 'getCommitTemplate'): TPromise<string>;
|
||||
call(command: 'getLog', options?: ILogOptions): TPromise<string>;
|
||||
call(command: string, args: any): TPromise<any>;
|
||||
}
|
||||
|
||||
|
@ -119,6 +121,7 @@ export class GitChannel implements IGitChannel {
|
|||
case 'show': return this.service.then(s => s.show(args[0], args[1]));
|
||||
case 'onOutput': return this.service.then(s => eventToCall(s.onOutput));
|
||||
case 'getCommitTemplate': return this.service.then(s => s.getCommitTemplate());
|
||||
case 'getLog': return this.service.then(s => s.getLog(args));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,6 +226,10 @@ export class GitChannelClient implements IRawGitService {
|
|||
getCommitTemplate(): TPromise<string> {
|
||||
return this.channel.call('getCommitTemplate');
|
||||
}
|
||||
|
||||
getLog(options?: ILogOptions): TPromise<string> {
|
||||
return this.channel.call('getLog', options);
|
||||
}
|
||||
}
|
||||
|
||||
export interface IAskpassChannel extends IChannel {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import { IRawGitService, IRawStatus, ServiceState, RawServiceState } from 'vs/workbench/parts/git/common/git';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
|
||||
|
||||
export class NoOpGitService implements IRawGitService {
|
||||
|
||||
|
@ -105,4 +106,8 @@ export class NoOpGitService implements IRawGitService {
|
|||
getCommitTemplate(): TPromise<string> {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
getLog(options?: ILogOptions): TPromise<string> {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
}
|
|
@ -118,6 +118,18 @@ export class GitError {
|
|||
}
|
||||
}
|
||||
|
||||
export interface ILogOptions {
|
||||
/**
|
||||
* @example `git log -1 --format=%B` to get the last commit log, message only
|
||||
*/
|
||||
prevCount?: number;
|
||||
|
||||
/**
|
||||
* @example format: "%B" translates to `git log --format=%B` to extract only the message
|
||||
*/
|
||||
format?: string;
|
||||
}
|
||||
|
||||
export interface IGitOptions {
|
||||
gitPath:string;
|
||||
version: string;
|
||||
|
@ -719,6 +731,20 @@ export class Repository {
|
|||
}, () => '');
|
||||
}
|
||||
|
||||
/** Implemented for use case `git log` and `git log -N`. */
|
||||
getLog(options?: ILogOptions): TPromise<string> {
|
||||
const args = ['log'];
|
||||
|
||||
if (options) {
|
||||
if (options.prevCount) { args.push(`-${options.prevCount}`); }
|
||||
if (options.format) { args.push(`--format=${options.format}`); }
|
||||
}
|
||||
|
||||
return this.run(args, { log: false }).then(result => {
|
||||
return result.stdout.trim();
|
||||
});
|
||||
}
|
||||
|
||||
onOutput(listener: (output: string) => void): () => void {
|
||||
return this.git.onOutput(listener);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import { join } from 'path';
|
|||
import { TPromise, Promise } from 'vs/base/common/winjs.base';
|
||||
import { detectMimesFromFile, detectMimesFromStream } from 'vs/base/node/mime';
|
||||
import { realpath, exists} from 'vs/base/node/pfs';
|
||||
import { Repository, GitError } from 'vs/workbench/parts/git/node/git.lib';
|
||||
import { Repository, GitError, ILogOptions } from 'vs/workbench/parts/git/node/git.lib';
|
||||
import { IRawGitService, RawServiceState, IRawStatus, IRef, GitErrorCodes, IPushOptions } from 'vs/workbench/parts/git/common/git';
|
||||
import Event, { Emitter, fromPromise } from 'vs/base/common/event';
|
||||
|
||||
|
@ -199,6 +199,10 @@ export class RawGitService implements IRawGitService {
|
|||
getCommitTemplate(): TPromise<string> {
|
||||
return this.repo.getCommitTemplate();
|
||||
}
|
||||
|
||||
getLog(options?: ILogOptions): TPromise<string> {
|
||||
return this.repo.getLog(options);
|
||||
}
|
||||
}
|
||||
|
||||
export class DelayedRawGitService implements IRawGitService {
|
||||
|
@ -225,4 +229,5 @@ export class DelayedRawGitService implements IRawGitService {
|
|||
detectMimetypes(path: string, treeish?: string): TPromise<string[]> { return this.raw.then(r => r.detectMimetypes(path, treeish)); }
|
||||
show(path: string, treeish?: string): TPromise<string> { return this.raw.then(r => r.show(path, treeish)); }
|
||||
getCommitTemplate(): TPromise<string> { return this.raw.then(r => r.getCommitTemplate()); }
|
||||
getLog(options?: ILogOptions): TPromise<string> { return this.raw.then(r => r.getLog(options)); }
|
||||
}
|
Loading…
Reference in a new issue