diff --git a/media/commit-fill.svg b/media/commit-fill.svg new file mode 100644 index 0000000..9501536 --- /dev/null +++ b/media/commit-fill.svg @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/media/commit.png b/media/commit.png new file mode 100644 index 0000000..0bbdee6 Binary files /dev/null and b/media/commit.png differ diff --git a/package-lock.json b/package-lock.json index 1d28c23..f55e4a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gitcommitfilter", - "version": "0.0.1", + "version": "0.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gitcommitfilter", - "version": "0.0.1", + "version": "0.0.2", "devDependencies": { "@types/mocha": "^10.0.10", "@types/node": "20.x", diff --git a/package.json b/package.json index 10b17cb..a9a6a06 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "gitcommitfilter", "displayName": "gitcommitfilter", "description": "过滤显示当前git分支的commit", - "version": "0.0.1", + "version": "0.0.2", "engines": { "vscode": "^1.97.0" }, @@ -10,13 +10,14 @@ "Other" ], "extensionKind": [ - "ui", - "workspace" - ], - "publisher": "elf.cheng", + "ui", + "workspace" + ], + "icon": "media/commit.png", + "publisher": "elfcheng", "extensionDependencies": [ "vscode.git" -], + ], "activationEvents": [], "main": "./dist/extension.js", "contributes": { @@ -25,7 +26,7 @@ { "id": "gitCommitFilterView", "title": "Git Commits", - "icon": "media/icon.svg" + "icon": "media/commit-fill.svg" } ] }, @@ -71,4 +72,4 @@ "type": "git", "url": "https://git.pyer.club/kingecg/gitcommitfilter.git" } -} \ No newline at end of file +} diff --git a/src/GitService.ts b/src/GitService.ts index 4dc12b0..e333238 100644 --- a/src/GitService.ts +++ b/src/GitService.ts @@ -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,21 +112,26 @@ 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 = []; } else if (nline.trim() !== "") { 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}`)); diff --git a/src/extension.ts b/src/extension.ts index 8a991d9..d255c0c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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); diff --git a/src/view.provider.ts b/src/view.provider.ts index 0ea3c47..0467dd4 100644 --- a/src/view.provider.ts +++ b/src/view.provider.ts @@ -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( @@ -262,6 +263,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