-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced several git commands with git extension API
- Loading branch information
ole1986
committed
Nov 27, 2019
1 parent
8129209
commit b72180f
Showing
24 changed files
with
106 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,49 @@ | ||
import { inject, injectable } from 'inversify'; | ||
import * as md5 from 'md5'; | ||
import { Uri } from 'vscode'; | ||
import { IServiceContainer } from '../../ioc/types'; | ||
import { IGitService, IGitServiceFactory } from '../../types'; | ||
import { IGitCommandExecutor } from '../exec'; | ||
import { ILogParser } from '../parsers/types'; | ||
import { Git } from './git'; | ||
import { API } from './git.d'; | ||
import { IGitArgsService } from './types'; | ||
|
||
@injectable() | ||
export class GitServiceFactory implements IGitServiceFactory { | ||
private readonly gitServices = new Map<string, IGitService>(); | ||
private readonly gitServices = new Map<number, IGitService>(); | ||
private gitApi: API; | ||
constructor(@inject(IGitCommandExecutor) private gitCmdExecutor: IGitCommandExecutor, | ||
@inject(ILogParser) private logParser: ILogParser, | ||
@inject(IGitArgsService) private gitArgsService: IGitArgsService, | ||
@inject(IServiceContainer) private serviceContainer: IServiceContainer) { | ||
|
||
this.gitApi = this.gitCmdExecutor.gitExtension.getAPI(1); | ||
} | ||
public async createGitService(workspaceRoot: string, resource: Uri | string): Promise<IGitService> { | ||
|
||
public async createGitService(resource?: Uri | string): Promise<IGitService> { | ||
const resourceUri = typeof resource === 'string' ? Uri.file(resource) : resource; | ||
let repoIndex: number = -1; | ||
|
||
if (!resourceUri) { | ||
// no git service initialized, so take the selected as primary | ||
repoIndex = this.gitApi.repositories.findIndex(x => x.ui.selected); | ||
} | ||
|
||
const id = md5(workspaceRoot + resourceUri.fsPath); | ||
if (!this.gitServices.has(id)) { | ||
this.gitServices.set(id, new Git(this.serviceContainer, workspaceRoot, resourceUri, this.gitCmdExecutor, this.logParser, this.gitArgsService)); | ||
if (repoIndex === -1) { | ||
// find the correct repository from the given resource uri | ||
this.gitApi.repositories.forEach((x, i) => { | ||
if (resourceUri!.fsPath.startsWith(x.rootUri.fsPath)) { | ||
if (repoIndex === -1 || x.rootUri.fsPath.length > this.gitApi.repositories[repoIndex].rootUri.fsPath.length) { | ||
repoIndex = i; | ||
} | ||
} | ||
}); | ||
} | ||
return this.gitServices.get(id)!; | ||
|
||
if (!this.gitServices.has(repoIndex)) { | ||
this.gitServices.set(repoIndex, new Git(this.gitApi.repositories[repoIndex], this.serviceContainer, this.gitCmdExecutor, this.logParser, this.gitArgsService)); | ||
} | ||
|
||
return this.gitServices.get(repoIndex)!; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.