fix git parse
This commit is contained in:
parent
7195a21d05
commit
f94358b381
|
@ -18,7 +18,7 @@ export interface GitCommit {
|
|||
export class GitService {
|
||||
private _repoPath: string;
|
||||
|
||||
constructor(private gitPath: string) {
|
||||
constructor(private gitPath: string, private logger: vscode.LogOutputChannel) {
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
if (!workspaceFolders || workspaceFolders.length === 0) {
|
||||
throw new Error("No workspace folder opened");
|
||||
|
@ -52,17 +52,19 @@ export class GitService {
|
|||
"--name-only",
|
||||
];
|
||||
|
||||
|
||||
const that = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
let lines: string[] = [];
|
||||
let commits: GitCommit[] = [];
|
||||
|
||||
function makeCommit(lines: any[]): GitCommit | undefined {
|
||||
try {
|
||||
if(lines.length === 1) {
|
||||
return undefined;
|
||||
}
|
||||
const commitLine = lines[0];
|
||||
console.log(commitLine);
|
||||
that.logger.info('add commit',commitLine);
|
||||
|
||||
const commit: GitCommit = JSON.parse(lines[0]);
|
||||
commit.files = [];
|
||||
for (let i = 1; i < lines.length; i++) {
|
||||
|
@ -93,11 +95,14 @@ export class GitService {
|
|||
gitProcess.stdout.on("data", (data) => {
|
||||
const nlines = data.split("\n").filter((l:string) => l.trim() !== "");
|
||||
for (let nline of nlines) {
|
||||
that.logger.info('process line 1',nline);
|
||||
if (nline.startsWith("{")) {
|
||||
if(lines.length > 0){
|
||||
const commit = makeCommit(lines);
|
||||
if(commit){
|
||||
that.logger.info('push commit', commit.hash)
|
||||
commits.push(commit);
|
||||
|
||||
}
|
||||
}
|
||||
lines = [];
|
||||
|
@ -107,6 +112,7 @@ export class GitService {
|
|||
}else if( nline.trim() === ""){
|
||||
const commit = makeCommit(lines);
|
||||
if(commit){
|
||||
that.logger.info('push commit 2', commit.hash)
|
||||
commits.push(commit);
|
||||
}
|
||||
lines = [];
|
||||
|
@ -114,15 +120,18 @@ export class GitService {
|
|||
lines.push(nline);
|
||||
}
|
||||
}
|
||||
if(lines.length > 0){
|
||||
const commit = makeCommit(lines);
|
||||
if(commit){
|
||||
commits.push(commit);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
gitProcess.on("exit",(code,signal)=>{
|
||||
if(code === 0){
|
||||
if(lines.length > 0){
|
||||
const commit = makeCommit(lines);
|
||||
if(commit){
|
||||
|
||||
that.logger.info('push commit 3', commit.hash)
|
||||
commits.push(commit);
|
||||
}
|
||||
}
|
||||
resolve(commits);
|
||||
}else{
|
||||
reject(new Error(`git log exited with code ${code}`));
|
||||
|
|
|
@ -4,6 +4,7 @@ import { GitService } from './GitService';
|
|||
import { GViewProvider } from './view.provider';
|
||||
|
||||
function getGitApi(){
|
||||
|
||||
const gitExtension = vscode.extensions.getExtension<'vscode.git'>('vscode.git');
|
||||
if(gitExtension && gitExtension.isActive){
|
||||
const api = (gitExtension.exports as any).getAPI(1);
|
||||
|
@ -20,10 +21,10 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
vscode.window.showErrorMessage('No Git avaliable');
|
||||
return;
|
||||
}
|
||||
|
||||
const gitService = new GitService(gitPath);
|
||||
const logger = vscode.window.createOutputChannel('GitCommitFilter',{log: true});
|
||||
const gitService = new GitService(gitPath,logger);
|
||||
|
||||
const viewProvider = new GViewProvider(context, gitService);
|
||||
const viewProvider = new GViewProvider(context, gitService,logger);
|
||||
|
||||
const activityBarIcon = vscode.window.registerWebviewViewProvider(GViewProvider.viewType, viewProvider);
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ export class GViewProvider implements vscode.WebviewViewProvider {
|
|||
|
||||
constructor(
|
||||
private context: vscode.ExtensionContext,
|
||||
private readonly _gitService: GitService
|
||||
private readonly _gitService: GitService,
|
||||
private readonly _logger: vscode.LogOutputChannel
|
||||
) {}
|
||||
|
||||
public resolveWebviewView(
|
||||
|
@ -283,6 +284,7 @@ private async openDiff(commitId: string, filePath: string) {
|
|||
private async filterCommits(filterText: string) {
|
||||
if (this._view) {
|
||||
const commits = await this._gitService.getCommits(filterText);
|
||||
this._logger.info(`filteredCommits:, ${JSON.stringify(commits)}"`);
|
||||
this._view.webview.postMessage({
|
||||
command: "updateCommits",
|
||||
commits
|
||||
|
|
Loading…
Reference in New Issue